#534 - move to database folder

This commit is contained in:
Elio Struyf
2023-03-15 13:13:18 +01:00
parent 143f8d799a
commit bc3407fd7b
3 changed files with 31 additions and 1 deletions

View File

@@ -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

View File

@@ -1,6 +1,7 @@
export const LocalStore = {
rootFolder: '.frontmatter',
contentFolder: 'content',
databaseFolder: 'database',
templatesFolder: 'templates',
mediaDatabaseFile: 'mediaDb.json'
};

View File

@@ -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,