automatically generate directories with new DbFile system

This commit is contained in:
May 2024-05-24 18:46:18 +00:00 committed by GitHub
parent 37f88d6984
commit 93b277e5b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 9 deletions

View file

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

View file

@ -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<Structure extends ({}|[])> {
}
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))