mirror of
https://github.com/idootop/mi-gpt.git
synced 2025-04-07 00:31:47 +00:00
misc: polish reset MiGPT logic
This commit is contained in:
parent
303663440d
commit
e427f3337a
10
src/index.ts
10
src/index.ts
|
@ -1,8 +1,9 @@
|
|||
import { AISpeaker, AISpeakerConfig } from "./services/speaker/ai";
|
||||
import { MyBot, MyBotConfig } from "./services/bot";
|
||||
import { initDB, runWithDB } from "./services/db";
|
||||
import { getDBInfo, initDB, runWithDB } from "./services/db";
|
||||
import { kBannerASCII } from "./utils/string";
|
||||
import { Logger } from "./utils/log";
|
||||
import { deleteFile } from "./utils/io";
|
||||
|
||||
export type MiGPTConfig = Omit<MyBotConfig, "speaker"> & {
|
||||
speaker: AISpeakerConfig;
|
||||
|
@ -10,8 +11,13 @@ export type MiGPTConfig = Omit<MyBotConfig, "speaker"> & {
|
|||
|
||||
export class MiGPT {
|
||||
static instance: MiGPT | null;
|
||||
static reset() {
|
||||
static async reset() {
|
||||
MiGPT.instance = null;
|
||||
const { dbPath } = getDBInfo();
|
||||
await deleteFile(dbPath);
|
||||
await deleteFile(".mi.json");
|
||||
await deleteFile(".bot.json");
|
||||
MiGPT.logger.log("MiGPT 已重置,请使用 MiGPT.create() 重新创建实例。");
|
||||
}
|
||||
static logger = Logger.create({ tag: "MiGPT" });
|
||||
static create(config: MiGPTConfig) {
|
||||
|
|
|
@ -27,15 +27,19 @@ export function getSkipWithCursor(skip: number, cursorId: any) {
|
|||
};
|
||||
}
|
||||
|
||||
export async function initDB() {
|
||||
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 };
|
||||
}
|
||||
|
||||
export async function initDB() {
|
||||
const { dbPath, withSchema } = getDBInfo();
|
||||
if (!exists(dbPath)) {
|
||||
const withSchema = isExternal
|
||||
? "--schema node_modules/mi-gpt/prisma/schema.prisma"
|
||||
: "";
|
||||
await deleteFile(".bot.json");
|
||||
await Shell.run(`npx prisma migrate dev --name init ${withSchema}`, {
|
||||
silent: true,
|
||||
|
|
Loading…
Reference in New Issue
Block a user