mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
#534 - move to database folder
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
### ⚡️ Optimizations
|
||||
|
||||
- [#534](https://github.com/estruyf/vscode-front-matter/issues/534): Moved the `mediaDb.json` file to a `.frontmatter/database` folder instead of the `.frontmatter/content` folder
|
||||
- [#536](https://github.com/estruyf/vscode-front-matter/issues/536): Set the start location from the script to the root of the workspace
|
||||
|
||||
### 🐞 Fixes
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export const LocalStore = {
|
||||
rootFolder: '.frontmatter',
|
||||
contentFolder: 'content',
|
||||
databaseFolder: 'database',
|
||||
templatesFolder: 'templates',
|
||||
mediaDatabaseFile: 'mediaDb.json'
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Notifications } from './Notifications';
|
||||
import { parseWinPath } from './parseWinPath';
|
||||
import { LocalStore } from '../constants';
|
||||
import { existsAsync, renameAsync } from '../utils';
|
||||
import { existsSync, mkdirSync, renameSync } from 'fs';
|
||||
|
||||
interface MediaRecord {
|
||||
description: string;
|
||||
@@ -23,11 +24,38 @@ export class MediaLibrary {
|
||||
return;
|
||||
}
|
||||
|
||||
// In version 8.4.0 we moved to a new database location
|
||||
// This is to ensure that the database is moved to the new location
|
||||
const oldDbPath = join(
|
||||
parseWinPath(wsFolder?.fsPath || ''),
|
||||
LocalStore.rootFolder,
|
||||
LocalStore.contentFolder,
|
||||
LocalStore.mediaDatabaseFile
|
||||
);
|
||||
|
||||
const dbFolder = join(
|
||||
parseWinPath(wsFolder?.fsPath || ''),
|
||||
LocalStore.rootFolder,
|
||||
LocalStore.databaseFolder
|
||||
);
|
||||
const dbPath = join(dbFolder, LocalStore.mediaDatabaseFile);
|
||||
|
||||
if (existsSync(oldDbPath)) {
|
||||
// Check if the database folder exists
|
||||
if (!existsSync(dbFolder)) {
|
||||
mkdirSync(dbFolder, { recursive: true });
|
||||
}
|
||||
// Move the database file
|
||||
if (existsSync(oldDbPath)) {
|
||||
renameSync(oldDbPath, dbPath);
|
||||
}
|
||||
}
|
||||
|
||||
this.db = new JsonDB(
|
||||
join(
|
||||
parseWinPath(wsFolder?.fsPath || ''),
|
||||
LocalStore.rootFolder,
|
||||
LocalStore.contentFolder,
|
||||
LocalStore.databaseFolder,
|
||||
LocalStore.mediaDatabaseFile
|
||||
),
|
||||
true,
|
||||
|
||||
Reference in New Issue
Block a user