Add DatabaseHandle and DB utilities, integrate API

Introduce a DatabaseHandle wrapper and helper functions for opening and decrypting NTQQ SQLite DBs (openDatabase, decryptAndOpen) in napcat-database; expose them from the package index. Add typed query/execute helpers and SQLInputValue typing. Extend NTQQDatabaseApi in napcat-core to provide high-level methods (openDecryptedDb, openDatabase, query, queryOne, execute) and export DatabaseHandle. Replace disabled inline test blocks with runtime DatabaseApi usage in napcat-framework and napcat-shell to test/read nt_msg.db via the new API. Misc: small cleanup of imports and comments.
This commit is contained in:
手瓜一十雪 committed 2026-03-04 11:02:21 +08:00
1 parent b9dcedacf5
commit 0ddf21a2f5
5 files changed
+294 -37

No files matched your search

+17 -18
View File
@@ -716,24 +716,6 @@ export async function NCoreInitShell () {
logger.logDebug('本账号数据/缓存目录:', accountDataPath);
// // [测试代码 - 已禁用] 使用捕获的 passphrase 读取 nt_msg.db 的表信息
// if (dbPassphrase) {
// const sqliteOk = await checkSqliteAvailable();
// if (!sqliteOk) {
// logger.logWarn('[NapCat] [Database] node:sqlite 不可用,跳过数据库读取');
// } else {
// const ntDbDir = path.resolve(dataPath, selfInfo.uin, 'nt_qq', 'nt_db');
// const dbCacheDir = path.resolve(accountDataPath, 'decrypted_db');
// const ntMsgDbPath = path.resolve(ntDbDir, 'nt_msg.db');
// try {
// const result = readSingleDatabase(ntMsgDbPath, Buffer.from(dbPassphrase), { cacheDir: dbCacheDir });
// logger.log('[NapCat] [Database] 读取完成:\n' + formatScanResults([result]));
// } catch (e) {
// logger.logError('[NapCat] [Database] 读取失败:', e);
// }
// }
// }
const shell = new NapCatShell(
wrapper,
session,
@@ -780,6 +762,23 @@ export class NapCatShell {
async InitNapCat () {
await this.core.initCore();
// 测试 DatabaseApi
if (this.core.dbPassphrase) {
const dbApi = this.core.apis.DatabaseApi;
const sqliteOk = await dbApi.isSqliteAvailable();
if (sqliteOk) {
try {
const result = dbApi.readDatabase('nt_msg.db');
if (result) {
this.context.logger.log('[NapCat] [Database] nt_msg.db:\n' + dbApi.formatResults([result]));
}
} catch (e) {
this.context.logger.logError('[NapCat] [Database] 读取失败:', e);
}
}
}
// 监听下线通知并同步到 WebUI
this.core.event.on('KickedOffLine', (tips: string) => {
WebUiDataRuntime.setQQLoginError(tips);