koishi-plugin-best-cave 2.2.0 → 2.2.1

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.
Files changed (2) hide show
  1. package/lib/index.js +18 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -625,8 +625,12 @@ var HashManager = class {
625
625
  const flushHashes = /* @__PURE__ */ __name(async () => {
626
626
  if (hashesToInsert.length > 0) {
627
627
  this.logger.info(`补全第 ${batchStartCaveCount + 1} 到 ${historicalCount} 条回声洞哈希中...`);
628
- await this.ctx.database.upsert("cave_hash", hashesToInsert);
629
- totalHashesGenerated += hashesToInsert.length;
628
+ try {
629
+ await this.ctx.database.upsert("cave_hash", hashesToInsert);
630
+ totalHashesGenerated += hashesToInsert.length;
631
+ } catch (error) {
632
+ this.logger.error(`导入哈希失败: ${error.message}`);
633
+ }
630
634
  hashesToInsert = [];
631
635
  batchStartCaveCount = historicalCount;
632
636
  }
@@ -634,21 +638,29 @@ var HashManager = class {
634
638
  for (const cave of allCaves) {
635
639
  if (existingHashedCaveIds.has(cave.id)) continue;
636
640
  historicalCount++;
641
+ const newHashesForCave = [];
637
642
  const combinedText = cave.elements.filter((el) => el.type === "text" && el.content).map((el) => el.content).join(" ");
638
- if (combinedText) {
639
- hashesToInsert.push({ cave: cave.id, hash: this.generateTextSimhash(combinedText), type: "sim" });
643
+ const textHash = this.generateTextSimhash(combinedText);
644
+ if (textHash) {
645
+ newHashesForCave.push({ cave: cave.id, hash: textHash, type: "sim" });
640
646
  }
641
647
  for (const el of cave.elements.filter((el2) => el2.type === "image" && el2.file)) {
642
648
  try {
643
649
  const imageBuffer = await this.fileManager.readFile(el.file);
644
650
  const pHash = await this.generateImagePHash(imageBuffer);
645
- hashesToInsert.push({ cave: cave.id, hash: pHash, type: "phash" });
651
+ newHashesForCave.push({ cave: cave.id, hash: pHash, type: "phash" });
646
652
  const subHashes = await this.generateImageSubHashes(imageBuffer);
647
- subHashes.forEach((subHash) => hashesToInsert.push({ cave: cave.id, hash: subHash, type: "sub" }));
653
+ subHashes.forEach((subHash) => newHashesForCave.push({ cave: cave.id, hash: subHash, type: "sub" }));
648
654
  } catch (e) {
649
655
  this.logger.warn(`无法为回声洞(${cave.id})的内容(${el.file})生成哈希:`, e);
650
656
  }
651
657
  }
658
+ const uniqueHashesMap = /* @__PURE__ */ new Map();
659
+ newHashesForCave.forEach((h4) => {
660
+ const uniqueKey = `${h4.type}-${h4.hash}`;
661
+ uniqueHashesMap.set(uniqueKey, h4);
662
+ });
663
+ hashesToInsert.push(...uniqueHashesMap.values());
652
664
  if (hashesToInsert.length >= 100) await flushHashes();
653
665
  }
654
666
  await flushHashes();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞。支持丰富的媒体类型、内容查重、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],