Založení složky server/data, pokud neexistuje, do které je vytvořen soubor db.json

This commit is contained in:
Michal Hájek
2025-02-02 19:46:20 +01:00
parent f3af64923c
commit 89dec1c194
2 changed files with 12 additions and 2 deletions

View File

@@ -1,7 +1,17 @@
import JSONdb from 'simple-json-db';
import { StorageInterface } from "./StorageInterface";
import * as fs from 'fs';
import * as path from 'path';
const db = new JSONdb('../data/db.json');
const dbPath = path.resolve(__dirname, '../../data/db.json');
const dbDir = path.dirname(dbPath);
// Zajistěte, že adresář existuje
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
}
const db = new JSONdb(dbPath);
/**
* Implementace úložiště používající JSON soubor.
*/