chore: 优化 db 路径查找方式

This commit is contained in:
WJG 2024-06-16 19:03:25 +08:00
parent 86feece787
commit 1992317f10
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
3 changed files with 13 additions and 8 deletions

View File

@ -13,6 +13,7 @@
- ✅ 登录凭证过期后自动刷新 token https://github.com/idootop/mi-gpt/issues/76
- ✅ 优化网络请求错误重试策略(消息/播放状态轮询)
- ✅ 移除 TTS 不发音字符emoji
- ✅ 优化 db 路径查找方式
## 📚 文档

View File

@ -111,7 +111,7 @@ class _BotConfig {
}
const bot = await UserCRUD.get(this.botIndex!.botId);
if (!bot) {
this._logger.error("find bot failed");
this._logger.error("find bot failed. 请删除 .bot.json 文件后重试!");
return undefined;
}
const master = await UserCRUD.get(this.botIndex!.masterId);

View File

@ -28,13 +28,17 @@ export function getSkipWithCursor(skip: number, cursorId: any) {
}
export function getDBInfo() {
const isExternal = exists("node_modules/mi-gpt/prisma");
const dbPath = isExternal
? "node_modules/mi-gpt/prisma/app.db"
: "prisma/app.db";
const schemaPath = isExternal ? "node_modules/mi-gpt" : ".";
const withSchema = `--schema ${schemaPath}/prisma/schema.prisma`;
return { dbPath, isExternal, withSchema };
let rootDir = import.meta.url
.replace("/dist/index.js", "")
.replace("/dist/index.cjs", "")
.replace("/src/services/db/index.ts", "")
.replace("file:///", "");
if (rootDir[1] !== ":") {
rootDir = "/" + rootDir; // linux root path
}
const dbPath = rootDir + "/prisma/app.db";
const withSchema = `--schema ${rootDir}/prisma/schema.prisma`;
return { dbPath, withSchema };
}
export async function initDB() {