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

View File

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

View File

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