From 93b277e5b8a9e0314d2b0f3cc5508ac9065df782 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Fri, 24 May 2024 18:46:18 +0000 Subject: [PATCH] automatically generate directories with new DbFile system --- src/server/index.ts | 8 -------- src/server/lib/dbfile.ts | 8 +++++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index 158b338..334113b 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -57,14 +57,6 @@ if (config.forceSSL) { }) } -// funcs - -// init data - -const __dirname = dirname(fileURLToPath(import.meta.url)) -if (!fs.existsSync(__dirname + "/../.data/")) - fs.mkdirSync(__dirname + "/../.data/") - // discord let files = new Files(config) diff --git a/src/server/lib/dbfile.ts b/src/server/lib/dbfile.ts index e9cedf3..c1a8a69 100644 --- a/src/server/lib/dbfile.ts +++ b/src/server/lib/dbfile.ts @@ -1,4 +1,5 @@ -import { readFile, writeFile, rename, readdir } from "fs/promises" +import { readFile, writeFile, readdir, mkdir } from "fs/promises" +import { existsSync } from "fs" import path from "node:path" const DATADIR = `./.data` @@ -92,6 +93,11 @@ export default class DbFile { } private async findAvailable() { + // would it be worth it to remove existsSync here? + // mkdir seems to already do it itself when recursive is true + if (!existsSync(DATADIR)) + await mkdir(DATADIR, { recursive: true }) + return (await readdir(DATADIR)) .filter(e => e.match(new RegExp(`^${this.name}(?:-b)?.json$`))) .map(e => path.join(DATADIR, e))