feat: 添加类型注释

This commit is contained in:
2025-01-20 16:05:50 +08:00
parent e5a4381b04
commit 60724a923e
27 changed files with 1364 additions and 249 deletions
+81
View File
@@ -0,0 +1,81 @@
import {
join,
dirname
} from 'path'
import {
Low,
JSONFile
} from 'lowdb'
import {
fileURLToPath
} from 'url'
import ConfigHelper from "./ConfigHelper.mjs";
const __dirname = dirname(fileURLToPath(
import.meta.url));
const getDbPath = (dbName:string, defPath:string) => {
let file = "";
if (ConfigHelper.config && ConfigHelper.config.db && ConfigHelper.config.db[dbName]) {
file = ConfigHelper.config.path + ConfigHelper.config.db[dbName];
} else {
file = defPath;
}
return file;
}
/**
* 基础数据库
* @returns
*/
export const getDb = async () => {
let file = getDbPath('db', join(__dirname, 'db.json'));
const adapter = new JSONFile(file)
const db = new Low(adapter)
await db.read();
return db;
}
/**
* 文件资源库
* @returns
*/
export const getResourceDb = async () => {
let file = getDbPath('resourceDB', join(__dirname, 'resourceDB.json'));
const adapter = new JSONFile(file)
const db = new Low(adapter)
await db.read();
return db;
}
/**
* 备份记录存储库
* @returns
*/
export const getBackupDb = async () => {
let file = getDbPath('backupDB', join(__dirname, 'backupDB.json'));
const adapter = new JSONFile(file)
const db = new Low(adapter)
await db.read();
return db;
}
/**
* 日志存储库
* @returns
*/
export const getLogDb = async () => {
let file = getDbPath('logDB', join(__dirname, 'logDB.json'));
const adapter = new JSONFile(file)
const db = new Low(adapter)
await db.read();
return db;
}
export default getDb;