@michengai/dsh-im-connect 0.1.19 → 0.1.21
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/README.en.md +2 -2
- package/README.md +2 -2
- package/SECURITY.md +1 -1
- package/lib/channels/dingtalk-card.d.ts.map +1 -1
- package/lib/channels/dingtalk-card.js +3 -0
- package/lib/channels/dingtalk-card.js.map +1 -1
- package/lib/channels/dingtalk.d.ts.map +1 -1
- package/lib/channels/dingtalk.js +6 -1
- package/lib/channels/dingtalk.js.map +1 -1
- package/lib/channels/feishu.d.ts +9 -0
- package/lib/channels/feishu.d.ts.map +1 -1
- package/lib/channels/feishu.js +23 -6
- package/lib/channels/feishu.js.map +1 -1
- package/lib/channels/qq.d.ts.map +1 -1
- package/lib/channels/qq.js +17 -1
- package/lib/channels/qq.js.map +1 -1
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +17 -4
- package/lib/channels/telegram.js.map +1 -1
- package/lib/channels/wecom.d.ts +7 -1
- package/lib/channels/wecom.d.ts.map +1 -1
- package/lib/channels/wecom.js +44 -11
- package/lib/channels/wecom.js.map +1 -1
- package/lib/channels/weixin.d.ts +3 -0
- package/lib/channels/weixin.d.ts.map +1 -1
- package/lib/channels/weixin.js +68 -15
- package/lib/channels/weixin.js.map +1 -1
- package/lib/engine/abort.d.ts +4 -0
- package/lib/engine/abort.d.ts.map +1 -0
- package/lib/engine/abort.js +26 -0
- package/lib/engine/abort.js.map +1 -0
- package/lib/engine/atomic-file.d.ts +5 -0
- package/lib/engine/atomic-file.d.ts.map +1 -0
- package/lib/engine/atomic-file.js +46 -0
- package/lib/engine/atomic-file.js.map +1 -0
- package/lib/engine/json-state.d.ts.map +1 -1
- package/lib/engine/json-state.js +7 -5
- package/lib/engine/json-state.js.map +1 -1
- package/lib/engine/secure-file.d.ts.map +1 -1
- package/lib/engine/secure-file.js +2 -12
- package/lib/engine/secure-file.js.map +1 -1
- package/lib/engine/seen-store.d.ts.map +1 -1
- package/lib/engine/seen-store.js +4 -4
- package/lib/engine/seen-store.js.map +1 -1
- package/lib/engine/session-store.d.ts.map +1 -1
- package/lib/engine/session-store.js +7 -5
- package/lib/engine/session-store.js.map +1 -1
- package/lib/manager.d.ts +7 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +50 -42
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/channels/dingtalk-card.ts +195 -192
- package/src/channels/dingtalk.ts +144 -140
- package/src/channels/feishu.ts +92 -66
- package/src/channels/qq.ts +303 -288
- package/src/channels/telegram.ts +170 -158
- package/src/channels/wecom.ts +209 -177
- package/src/channels/weixin.ts +158 -112
- package/src/engine/abort.ts +25 -0
- package/src/engine/access.ts +34 -34
- package/src/engine/atomic-file.ts +36 -0
- package/src/engine/json-state.ts +16 -15
- package/src/engine/secure-file.ts +7 -13
- package/src/engine/seen-store.ts +39 -39
- package/src/engine/session-store.ts +40 -39
- package/src/manager.ts +346 -321
package/src/engine/seen-store.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/** 去重最近见过的消息 id,避免重启或重复投递打两次。 */
|
|
5
|
-
export class SeenStore {
|
|
6
|
-
private ids: string[] = []
|
|
7
|
-
private known = new Set<string>()
|
|
8
|
-
|
|
9
|
-
constructor(private readonly file: string, private readonly limit = 2000) {
|
|
10
|
-
this.load()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
has(id: string): boolean {
|
|
14
|
-
return this.known.has(id)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
add(id: string): void {
|
|
18
|
-
if (!id || this.has(id)) return
|
|
19
|
-
this.ids.push(id)
|
|
20
|
-
this.known.add(id)
|
|
21
|
-
if (this.ids.length > this.limit) {
|
|
22
|
-
this.ids = this.ids.slice(-this.limit)
|
|
23
|
-
this.known = new Set(this.ids)
|
|
24
|
-
}
|
|
25
|
-
this.flush()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private load(): void {
|
|
29
|
-
try {
|
|
30
|
-
const parsed = JSON.parse(readFileSync(this.file, 'utf8')) as { ids?: string[] }
|
|
31
|
-
this.ids = Array.isArray(parsed.ids) ? parsed.ids.filter((item) => typeof item === 'string') : []
|
|
32
|
-
this.known = new Set(this.ids)
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { backupCorruptFileSync, writeFileAtomicSync } from './atomic-file.js'
|
|
3
|
+
|
|
4
|
+
/** 去重最近见过的消息 id,避免重启或重复投递打两次。 */
|
|
5
|
+
export class SeenStore {
|
|
6
|
+
private ids: string[] = []
|
|
7
|
+
private known = new Set<string>()
|
|
8
|
+
|
|
9
|
+
constructor(private readonly file: string, private readonly limit = 2000) {
|
|
10
|
+
this.load()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
has(id: string): boolean {
|
|
14
|
+
return this.known.has(id)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
add(id: string): void {
|
|
18
|
+
if (!id || this.has(id)) return
|
|
19
|
+
this.ids.push(id)
|
|
20
|
+
this.known.add(id)
|
|
21
|
+
if (this.ids.length > this.limit) {
|
|
22
|
+
this.ids = this.ids.slice(-this.limit)
|
|
23
|
+
this.known = new Set(this.ids)
|
|
24
|
+
}
|
|
25
|
+
this.flush()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private load(): void {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(readFileSync(this.file, 'utf8')) as { ids?: string[] }
|
|
31
|
+
this.ids = Array.isArray(parsed.ids) ? parsed.ids.filter((item) => typeof item === 'string') : []
|
|
32
|
+
this.known = new Set(this.ids)
|
|
33
33
|
} catch {
|
|
34
|
+
backupCorruptFileSync(this.file)
|
|
34
35
|
this.ids = []
|
|
35
|
-
this.known.clear()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
36
|
+
this.known.clear()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
39
40
|
private flush(): void {
|
|
40
|
-
|
|
41
|
-
writeFileSync(this.file, `${JSON.stringify({ ids: this.ids }, null, 2)}\n`, 'utf8')
|
|
41
|
+
writeFileAtomicSync(this.file, `${JSON.stringify({ ids: this.ids }, null, 2)}\n`)
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname } from 'node:path'
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
3
2
|
import type { SessionRecord } from './session-id.js'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
3
|
+
import { backupCorruptFileSync, writeFileAtomicSync } from './atomic-file.js'
|
|
4
|
+
|
|
5
|
+
export class SessionMapStore {
|
|
6
|
+
private readonly file: string
|
|
7
|
+
private records: Record<string, SessionRecord> = {}
|
|
8
|
+
|
|
9
|
+
constructor(file: string) {
|
|
10
|
+
this.file = file
|
|
11
|
+
this.load()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
list(): SessionRecord[] {
|
|
15
|
+
return Object.values(this.records).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get(key: string): SessionRecord | undefined {
|
|
19
|
+
return this.records[key]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
upsert(key: string, record: SessionRecord): void {
|
|
23
|
+
this.records[key] = record
|
|
24
|
+
this.flush()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
remove(key: string): void {
|
|
28
|
+
delete this.records[key]
|
|
29
|
+
this.flush()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private load(): void {
|
|
33
|
+
try {
|
|
34
34
|
const parsed = JSON.parse(readFileSync(this.file, 'utf8')) as Record<string, SessionRecord>
|
|
35
|
-
|
|
35
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new TypeError('会话映射顶层必须是对象')
|
|
36
|
+
this.records = parsed
|
|
36
37
|
} catch {
|
|
38
|
+
backupCorruptFileSync(this.file)
|
|
37
39
|
this.records = {}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
41
43
|
private flush(): void {
|
|
42
|
-
|
|
43
|
-
writeFileSync(this.file, `${JSON.stringify(this.records, null, 2)}\n`, 'utf8')
|
|
44
|
+
writeFileAtomicSync(this.file, `${JSON.stringify(this.records, null, 2)}\n`)
|
|
44
45
|
}
|
|
45
|
-
}
|
|
46
|
+
}
|