fix: hotfix db initialize failed

This commit is contained in:
linyuchen
2024-03-06 22:55:33 +08:00
parent cc8e8f108b
commit e1d47f55bf
4 changed files with 16 additions and 11 deletions

View File

@@ -1,10 +1,10 @@
{ {
"manifest_version": 4, "manifest_version": 4,
"type": "extension", "type": "extension",
"name": "LLOneBot v3.13.0", "name": "LLOneBot v3.13.1",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi", "description": "LiteLoaderQQNT的OneBotApi",
"version": "3.13.0", "version": "3.13.1",
"thumbnail": "./icon.png", "thumbnail": "./icon.png",
"authors": [ "authors": [
{ {

View File

@@ -1,7 +1,7 @@
// import {DATA_DIR} from "./utils"; // import {DATA_DIR} from "./utils";
import {Level} from "level"; import {Level} from "level";
import {RawMessage} from "../ntqqapi/types"; import {RawMessage} from "../ntqqapi/types";
import {DATA_DIR} from "./utils"; import {DATA_DIR, log} from "./utils";
import {selfInfo} from "./data"; import {selfInfo} from "./data";
@@ -93,14 +93,14 @@ class DBUtil {
// 有则更新,无则添加 // 有则更新,无则添加
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
let existMsg = this.cache[longIdKey] let existMsg = this.cache[longIdKey]
if (!existMsg){ if (!existMsg) {
try { try {
existMsg = await this.getMsgByLongId(msg.msgId) existMsg = await this.getMsgByLongId(msg.msgId)
}catch (e) { } catch (e) {
} }
} }
if (existMsg){ if (existMsg) {
this.updateMsg(msg).then() this.updateMsg(msg).then()
return existMsg.msgShortId return existMsg.msgShortId
} }
@@ -108,10 +108,15 @@ class DBUtil {
const shortMsgId = await this.genMsgShortId(); const shortMsgId = await this.genMsgShortId();
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId; const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq; const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
await this.db.put(shortIdKey, msg.msgId);
msg.msgShortId = shortMsgId; msg.msgShortId = shortMsgId;
try {
await this.db.put(shortIdKey, msg.msgId);
await this.db.put(longIdKey, JSON.stringify(msg)); await this.db.put(longIdKey, JSON.stringify(msg));
await this.db.put(seqIdKey, msg.msgId); await this.db.put(seqIdKey, msg.msgId);
} catch (e) {
log("addMsg db error", e.stack.toString());
}
this.cache[seqIdKey] = this.cache[shortIdKey] = this.cache[longIdKey] = msg; this.cache[seqIdKey] = this.cache[shortIdKey] = this.cache[longIdKey] = msg;
return shortMsgId return shortMsgId
} }

View File

@@ -177,7 +177,7 @@ function onLoad() {
try { try {
await postReceiveMsg(payload.msgList); await postReceiveMsg(payload.msgList);
} catch (e) { } catch (e) {
log("report message error: ", e.toString()); log("report message error: ", e.stack.toString());
} }
}) })
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => { registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {

View File

@@ -1 +1 @@
export const version = "3.13.0" export const version = "3.13.1"