mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
adding backup/restore ability
This commit is contained in:
@@ -155,3 +155,21 @@ class SqliteConnection {
|
||||
}
|
||||
|
||||
export default SqliteConnection;
|
||||
|
||||
// Centralized DB path computation to avoid duplication across modules
|
||||
// Returns: { dir, dbPath }
|
||||
/**
|
||||
* Compute the absolute SQLite database directory and file path based on configuration.
|
||||
* Ensures the directory exists on disk.
|
||||
* @returns {Promise<{dir:string, dbPath:string}>} Absolute directory and database file path.
|
||||
*/
|
||||
export async function computeDbPath() {
|
||||
const cfg = await readConfigFromStorage();
|
||||
const rawDir = cfg?.sqlitepath && cfg.sqlitepath.length > 0 ? cfg.sqlitepath : '/db';
|
||||
const relDir = rawDir.startsWith('/') ? rawDir.slice(1) : rawDir;
|
||||
const absDir = path.isAbsolute(relDir) ? relDir : path.join(process.cwd(), relDir);
|
||||
const dbPath = path.join(absDir, 'listings.db');
|
||||
const dir = path.dirname(dbPath);
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||
return { dir: absDir, dbPath };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user