mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
Several project files user folder (#617)
* feat: save loaded file across sessions
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { fileURLToPath } from 'url';
|
||||
import path, { dirname, join } from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
import { config } from './config/config.js';
|
||||
|
||||
// =================================================
|
||||
@@ -69,12 +71,23 @@ export const currentDirectory = dirname(__dirname);
|
||||
const testDbStartDirectory = isTest ? '../' : getAppDataPath();
|
||||
export const externalsStartDirectory = isProduction ? getAppDataPath() : join(currentDirectory, 'external');
|
||||
|
||||
const lastLoadedProjectConfigPath = join(getAppDataPath(), 'config.json');
|
||||
|
||||
let lastLoadedProject;
|
||||
|
||||
try {
|
||||
lastLoadedProject = JSON.parse(fs.readFileSync(lastLoadedProjectConfigPath, 'utf8')).lastLoadedProject;
|
||||
} catch {
|
||||
if (!isTest) {
|
||||
fs.writeFileSync(lastLoadedProjectConfigPath, JSON.stringify({ lastLoadedProject: null }));
|
||||
}
|
||||
}
|
||||
|
||||
const configDbDirectory = lastLoadedProject ? 'uploads' : config.database.directory;
|
||||
|
||||
// path to public db
|
||||
export const resolveDbDirectory = join(
|
||||
testDbStartDirectory,
|
||||
isTest ? config.database.testdb : config.database.directory,
|
||||
);
|
||||
export const resolveDbPath = join(resolveDbDirectory, config.database.filename);
|
||||
export const resolveDbDirectory = join(testDbStartDirectory, isTest ? config.database.testdb : configDbDirectory);
|
||||
export const resolveDbPath = join(resolveDbDirectory, lastLoadedProject ? lastLoadedProject : config.database.filename);
|
||||
|
||||
export const pathToStartDb = isTest
|
||||
? join(currentDirectory, '../', config.database.testdb, config.database.filename)
|
||||
|
||||
Reference in New Issue
Block a user