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.
- package/LICENSE +674 -21
- package/lib/index.js +197 -245
- package/lib/utils/HashStorage.d.ts +48 -56
- package/package.json +1 -1
|
@@ -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
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
41
|
-
|
|
42
|
-
getStatus(): Promise<HashStatus>;
|
|
43
|
-
/**
|
|
44
|
-
* 更新指定回声洞的图片哈希值
|
|
45
|
-
* @param caveId 回声洞ID
|
|
46
|
-
* @param imgBuffers 图片buffer数组
|
|
24
|
+
* 加载哈希数据
|
|
25
|
+
* @param data - 要加载的哈希数据
|
|
26
|
+
* @private
|
|
47
27
|
*/
|
|
48
|
-
|
|
28
|
+
private loadHashData;
|
|
49
29
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @param
|
|
30
|
+
* 更新指定回声洞的哈希值
|
|
31
|
+
* @param caveId - 回声洞ID
|
|
32
|
+
* @param type - 哈希类型(图像或文本)
|
|
33
|
+
* @param content - 要计算哈希的内容
|
|
52
34
|
*/
|
|
53
|
-
|
|
35
|
+
updateHash(caveId: number, type: 'image' | 'text', content: Buffer | string): Promise<void>;
|
|
54
36
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
37
|
+
* 查找重复项
|
|
38
|
+
* @param type - 查找类型(图像或文本)
|
|
39
|
+
* @param hashes - 要查找的哈希值数组
|
|
40
|
+
* @param threshold - 相似度阈值,默认为1
|
|
41
|
+
* @returns 匹配结果数组
|
|
59
42
|
*/
|
|
60
|
-
findDuplicates(
|
|
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
|
-
* @
|
|
49
|
+
* 清除指定回声洞的所有哈希值
|
|
50
|
+
* @param caveId - 回声洞ID
|
|
51
|
+
*/
|
|
52
|
+
clearHashes(caveId: number): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* 构建初始哈希值
|
|
68
55
|
* @private
|
|
69
56
|
*/
|
|
70
|
-
private
|
|
57
|
+
private buildInitialHashes;
|
|
71
58
|
/**
|
|
72
|
-
*
|
|
59
|
+
* 更新缺失的哈希值
|
|
73
60
|
* @private
|
|
74
61
|
*/
|
|
75
|
-
private
|
|
62
|
+
private updateMissingHashes;
|
|
76
63
|
/**
|
|
77
|
-
*
|
|
64
|
+
* 处理单个回声洞的哈希值
|
|
65
|
+
* @param cave - 回声洞数据
|
|
78
66
|
* @private
|
|
79
67
|
*/
|
|
80
|
-
private
|
|
68
|
+
private processCaveHashes;
|
|
69
|
+
private processCaveTextHashes;
|
|
81
70
|
/**
|
|
82
|
-
*
|
|
71
|
+
* 保存哈希数据到文件
|
|
83
72
|
* @private
|
|
84
73
|
*/
|
|
85
|
-
private
|
|
74
|
+
private saveHashes;
|
|
86
75
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
89
|
-
* @param processor 处理函数
|
|
90
|
-
* @param batchSize 批处理大小
|
|
76
|
+
* 加载回声洞数据
|
|
77
|
+
* @returns 回声洞数据数组
|
|
91
78
|
* @private
|
|
92
79
|
*/
|
|
93
|
-
private
|
|
80
|
+
private loadCaveData;
|
|
81
|
+
/**
|
|
82
|
+
* 计算文本的哈希值
|
|
83
|
+
* @param text - 要计算哈希的文本
|
|
84
|
+
* @returns MD5哈希值
|
|
85
|
+
*/
|
|
86
|
+
static hashText(text: string): string;
|
|
94
87
|
}
|
|
95
|
-
export {};
|