koishi-plugin-best-cave 1.3.4 → 1.4.0

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.
@@ -1,95 +1,87 @@
1
1
  /**
2
- * 哈希存储状态信息
3
- */
4
- interface HashStatus {
5
- /** 最后更新时间戳 */
6
- lastUpdated: string;
7
- /** 所有回声洞的哈希值条目 */
8
- entries: Array<{
9
- caveId: number;
10
- hashes: string[];
11
- }>;
12
- }
13
- /**
14
- * 图片哈希值存储管理类
15
- * 负责管理和维护回声洞图片的哈希值
2
+ * 哈希存储管理类
3
+ * @class HashStorage
16
4
  */
17
5
  export declare class HashStorage {
18
6
  private readonly caveDir;
19
- private static readonly HASH_FILE;
20
- private static readonly CAVE_FILE;
21
- private static readonly BATCH_SIZE;
22
- private hashes;
7
+ private readonly filePath;
8
+ private readonly resourceDir;
9
+ private readonly caveFilePath;
10
+ private imageHashes;
11
+ private textHashes;
23
12
  private initialized;
24
13
  /**
25
- * 初始化HashStorage实例
26
- * @param caveDir 回声洞数据目录路径
14
+ * 创建哈希存储实例
15
+ * @param caveDir - 回声洞数据目录路径
27
16
  */
28
17
  constructor(caveDir: string);
29
- private get filePath();
30
- private get resourceDir();
31
- private get caveFilePath();
32
18
  /**
33
19
  * 初始化哈希存储
34
- * 读取现有哈希数据或重新构建哈希值
35
20
  * @throws 初始化失败时抛出错误
36
21
  */
37
22
  initialize(): Promise<void>;
38
23
  /**
39
- * 获取当前哈希存储状态
40
- * @returns 包含最后更新时间和所有条目的状态对象
41
- */
42
- getStatus(): Promise<HashStatus>;
43
- /**
44
- * 更新指定回声洞的图片哈希值
45
- * @param caveId 回声洞ID
46
- * @param imgBuffers 图片buffer数组
24
+ * 加载哈希数据
25
+ * @param data - 要加载的哈希数据
26
+ * @private
47
27
  */
48
- updateCaveHash(caveId: number, imgBuffers?: Buffer[]): Promise<void>;
28
+ private loadHashData;
49
29
  /**
50
- * 更新所有回声洞的哈希值
51
- * @param isInitialBuild 是否为初始构建
30
+ * 更新指定回声洞的哈希值
31
+ * @param caveId - 回声洞ID
32
+ * @param type - 哈希类型(图像或文本)
33
+ * @param content - 要计算哈希的内容
52
34
  */
53
- updateAllCaves(isInitialBuild?: boolean): Promise<void>;
35
+ updateHash(caveId: number, type: 'image' | 'text', content: Buffer | string): Promise<void>;
54
36
  /**
55
- * 查找重复的图片
56
- * @param imgBuffers 待查找的图片buffer数组
57
- * @param threshold 相似度阈值
58
- * @returns 匹配结果数组,包含索引、回声洞ID和相似度
37
+ * 查找重复项
38
+ * @param type - 查找类型(图像或文本)
39
+ * @param hashes - 要查找的哈希值数组
40
+ * @param threshold - 相似度阈值,默认为1
41
+ * @returns 匹配结果数组
59
42
  */
60
- findDuplicates(imgBuffers: Buffer[], threshold: number): Promise<Array<{
43
+ findDuplicates(type: 'image' | 'text', hashes: string[], threshold?: number): Promise<Array<{
61
44
  index: number;
62
45
  caveId: number;
63
46
  similarity: number;
64
47
  } | null>>;
65
48
  /**
66
- * 加载回声洞数据
67
- * @returns 回声洞数据数组
49
+ * 清除指定回声洞的所有哈希值
50
+ * @param caveId - 回声洞ID
51
+ */
52
+ clearHashes(caveId: number): Promise<void>;
53
+ /**
54
+ * 构建初始哈希值
68
55
  * @private
69
56
  */
70
- private loadCaveData;
57
+ private buildInitialHashes;
71
58
  /**
72
- * 保存哈希数据到文件
59
+ * 更新缺失的哈希值
73
60
  * @private
74
61
  */
75
- private saveHashes;
62
+ private updateMissingHashes;
76
63
  /**
77
- * 构建初始哈希数据
64
+ * 处理单个回声洞的哈希值
65
+ * @param cave - 回声洞数据
78
66
  * @private
79
67
  */
80
- private buildInitialHashes;
68
+ private processCaveHashes;
69
+ private processCaveTextHashes;
81
70
  /**
82
- * 更新缺失的哈希值
71
+ * 保存哈希数据到文件
83
72
  * @private
84
73
  */
85
- private updateMissingHashes;
74
+ private saveHashes;
86
75
  /**
87
- * 批量处理数组项
88
- * @param items 待处理项数组
89
- * @param processor 处理函数
90
- * @param batchSize 批处理大小
76
+ * 加载回声洞数据
77
+ * @returns 回声洞数据数组
91
78
  * @private
92
79
  */
93
- private processBatch;
80
+ private loadCaveData;
81
+ /**
82
+ * 计算文本的哈希值
83
+ * @param text - 要计算哈希的文本
84
+ * @returns MD5哈希值
85
+ */
86
+ static hashText(text: string): string;
94
87
  }
95
- export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "最好的 cave 插件,可开关的审核系统,可引用添加,支持图文混合内容,可查阅投稿列表,完美复刻你的 .cave 体验!",
4
- "version": "1.3.4",
4
+ "version": "1.4.0",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],