koishi-plugin-best-cave 2.2.4 → 2.2.5

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.
@@ -63,7 +63,13 @@ export declare class HashManager {
63
63
  * @returns {Promise<string>} 一个包含操作结果的报告字符串。
64
64
  */
65
65
  checkForSimilarCaves(): Promise<string>;
66
- private _generateSingleChannelPHash;
66
+ /**
67
+ * @description 从单通道原始像素数据计算pHash。
68
+ * @param channelData - 单通道的像素值数组。
69
+ * @param size - 图像的边长(例如16)。
70
+ * @returns {string} 该通道的二进制哈希字符串。
71
+ */
72
+ private _calculateHashFromRawChannel;
67
73
  /**
68
74
  * @description 生成768位颜色感知哈希(Color pHash)。
69
75
  * @param imageBuffer - 图片的 Buffer 数据。
package/lib/index.js CHANGED
@@ -806,11 +806,16 @@ var HashManager = class {
806
806
  if (subHashDuplicates.length > 0) report += "\n图片局部重复:\n" + [...new Set(subHashDuplicates)].join("\n");
807
807
  return report.trim();
808
808
  }
809
- async _generateSingleChannelPHash(channelBuffer, size) {
810
- const pixelData = await (0, import_sharp.default)(channelBuffer).resize(size, size, { fit: "fill" }).raw().toBuffer();
811
- const totalLuminance = pixelData.reduce((acc, val) => acc + val, 0);
809
+ /**
810
+ * @description 从单通道原始像素数据计算pHash。
811
+ * @param channelData - 单通道的像素值数组。
812
+ * @param size - 图像的边长(例如16)。
813
+ * @returns {string} 该通道的二进制哈希字符串。
814
+ */
815
+ _calculateHashFromRawChannel(channelData, size) {
816
+ const totalLuminance = channelData.reduce((acc, val) => acc + val, 0);
812
817
  const avgLuminance = totalLuminance / (size * size);
813
- return Array.from(pixelData).map((lum) => lum > avgLuminance ? "1" : "0").join("");
818
+ return channelData.map((lum) => lum > avgLuminance ? "1" : "0").join("");
814
819
  }
815
820
  /**
816
821
  * @description 生成768位颜色感知哈希(Color pHash)。
@@ -826,11 +831,9 @@ var HashManager = class {
826
831
  g.push(data[i + 1]);
827
832
  b.push(data[i + 2]);
828
833
  }
829
- const [rHash, gHash, bHash] = await Promise.all([
830
- this._generateSingleChannelPHash(Buffer.from(r), 16),
831
- this._generateSingleChannelPHash(Buffer.from(g), 16),
832
- this._generateSingleChannelPHash(Buffer.from(b), 16)
833
- ]);
834
+ const rHash = this._calculateHashFromRawChannel(r, 16);
835
+ const gHash = this._calculateHashFromRawChannel(g, 16);
836
+ const bHash = this._calculateHashFromRawChannel(b, 16);
834
837
  const combinedHash = rHash + gHash + bHash;
835
838
  let hex = "";
836
839
  for (let i = 0; i < combinedHash.length; i += 4) {
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.4",
4
+ "version": "2.2.5",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],