Add support to save chapter to databases

This commit is contained in:
2026-02-14 17:42:42 +08:00
parent d1a5b4aa3c
commit e510467197
9 changed files with 199 additions and 11 deletions

21
src/db/interfaces.ts Normal file
View File

@@ -0,0 +1,21 @@
import { DbConfig, DbType } from "../config";
import { IndexedDb } from "./indexedDb";
import type { QdChapterInfo } from "../types";
export interface Db {
init(): Promise<void>;
saveQdChapter(info: QdChapterInfo): Promise<void>;
close(): void;
}
export async function createDb(): Promise<Db> {
const config = new DbConfig();
await config.init();
switch (config.DbType) {
case DbType.IndexedDb:
const db = new IndexedDb(config.IndexedDb);
return db;
default:
throw new Error('Unsupported database type');
}
}