koishi-plugin-best-cave 2.7.8 → 2.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +14 -27
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -722,42 +722,29 @@ var HashManager = class {
|
|
|
722
722
|
if (requireAdmin(session, this.config)) return requireAdmin(session, this.config);
|
|
723
723
|
try {
|
|
724
724
|
const allCaves = await this.ctx.database.get("cave", { status: "active" });
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
725
|
+
const existingHashes = await this.ctx.database.get("cave_hash", {}, { fields: ["cave"] });
|
|
726
|
+
const hashedCaveIds = new Set(existingHashes.map((h4) => h4.cave));
|
|
727
|
+
const cavesToProcess = allCaves.filter((cave2) => !hashedCaveIds.has(cave2.id));
|
|
728
|
+
if (cavesToProcess.length === 0) return "无需补全回声洞哈希";
|
|
729
|
+
await session.send(`开始补全 ${cavesToProcess.length} 个回声洞的哈希...`);
|
|
730
|
+
const hashesToInsert = [];
|
|
730
731
|
let processedCaveCount = 0;
|
|
731
|
-
let totalHashesGenerated = 0;
|
|
732
732
|
let errorCount = 0;
|
|
733
|
-
const
|
|
734
|
-
if (hashesToInsert.length === 0) return;
|
|
735
|
-
await this.ctx.database.upsert("cave_hash", hashesToInsert);
|
|
736
|
-
totalHashesGenerated += hashesToInsert.length;
|
|
737
|
-
this.logger.info(`[${processedCaveCount}/${allCaves.length}] 正在导入 ${hashesToInsert.length} 条回声洞哈希...`);
|
|
738
|
-
hashesToInsert = [];
|
|
739
|
-
}, "flushBatch");
|
|
740
|
-
for (const cave2 of allCaves) {
|
|
733
|
+
for (const cave2 of cavesToProcess) {
|
|
741
734
|
processedCaveCount++;
|
|
742
735
|
try {
|
|
743
736
|
const newHashesForCave = await this.generateAllHashesForCave(cave2);
|
|
744
|
-
|
|
745
|
-
const uniqueKey = `${hashObj.cave}-${hashObj.hash}-${hashObj.type}`;
|
|
746
|
-
if (!existingHashSet.has(uniqueKey)) {
|
|
747
|
-
hashesToInsert.push(hashObj);
|
|
748
|
-
existingHashSet.add(uniqueKey);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (hashesToInsert.length >= 100) await flushBatch();
|
|
737
|
+
if (newHashesForCave.length > 0) hashesToInsert.push(...newHashesForCave);
|
|
752
738
|
} catch (error) {
|
|
753
739
|
errorCount++;
|
|
754
740
|
this.logger.warn(`补全回声洞(${cave2.id})哈希时出错: ${error.message}`);
|
|
755
741
|
}
|
|
756
742
|
}
|
|
757
|
-
await
|
|
758
|
-
|
|
743
|
+
if (hashesToInsert.length > 0) await this.ctx.database.upsert("cave_hash", hashesToInsert);
|
|
744
|
+
const successCount = processedCaveCount - errorCount;
|
|
745
|
+
return `已补全 ${successCount} 个回声洞的 ${hashesToInsert.length} 条哈希(失败 ${errorCount} 条)`;
|
|
759
746
|
} catch (error) {
|
|
760
|
-
this.logger.error("
|
|
747
|
+
this.logger.error("补全哈希失败:", error);
|
|
761
748
|
return `操作失败: ${error.message}`;
|
|
762
749
|
}
|
|
763
750
|
});
|
|
@@ -821,13 +808,13 @@ var HashManager = class {
|
|
|
821
808
|
if (requireAdmin(session, this.config)) return requireAdmin(session, this.config);
|
|
822
809
|
let cavesToProcess;
|
|
823
810
|
try {
|
|
811
|
+
await session.send("正在修复,请稍候...");
|
|
824
812
|
if (ids.length === 0) {
|
|
825
|
-
await session.send("正在修复,请稍候...");
|
|
826
813
|
cavesToProcess = await this.ctx.database.get("cave", { status: "active" });
|
|
827
814
|
} else {
|
|
828
815
|
cavesToProcess = await this.ctx.database.get("cave", { id: { $in: ids }, status: "active" });
|
|
829
816
|
}
|
|
830
|
-
if (!cavesToProcess.length) return "
|
|
817
|
+
if (!cavesToProcess.length) return "无可修复的回声洞";
|
|
831
818
|
let fixedFiles = 0;
|
|
832
819
|
let errorCount = 0;
|
|
833
820
|
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|