ework-qq-bridge 0.1.4 → 0.1.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.
- package/package.json +1 -1
- package/src/ingest.ts +21 -0
package/package.json
CHANGED
package/src/ingest.ts
CHANGED
|
@@ -19,6 +19,23 @@ interface IngestDeps {
|
|
|
19
19
|
send(groupId: number, text: string): Promise<void>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// Looping agent sessions can emit a reply every few seconds; cap forwards
|
|
23
|
+
// per issue so a runaway session cannot flood the group.
|
|
24
|
+
const FORWARD_WINDOW_MS = 60_000;
|
|
25
|
+
const FORWARD_MAX_PER_WINDOW = 5;
|
|
26
|
+
const forwardTimestamps = new Map<string, number[]>();
|
|
27
|
+
|
|
28
|
+
function forwardAllowed(key: string, now = Date.now()): boolean {
|
|
29
|
+
const list = (forwardTimestamps.get(key) ?? []).filter((t) => now - t < FORWARD_WINDOW_MS);
|
|
30
|
+
if (list.length >= FORWARD_MAX_PER_WINDOW) {
|
|
31
|
+
forwardTimestamps.set(key, list);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
list.push(now);
|
|
35
|
+
forwardTimestamps.set(key, list);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
export function verifySignature(secret: string, body: string, header: string | null): boolean {
|
|
23
40
|
if (!secret) return true;
|
|
24
41
|
if (!header) return false;
|
|
@@ -74,6 +91,10 @@ export function createIngest(deps: IngestDeps) {
|
|
|
74
91
|
return new Response("skipped:dup", { status: 200 });
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
if (!forwardAllowed(`${owner}/${String(repo.name)}#${number}`)) {
|
|
95
|
+
console.warn(`[qq-bridge] forward rate-limited for ${owner}/${String(repo.name)}#${number}`);
|
|
96
|
+
return new Response("rate-limited", { status: 200 });
|
|
97
|
+
}
|
|
77
98
|
const text = deps.scrub(`[#${number}] ${body}`);
|
|
78
99
|
try {
|
|
79
100
|
await deps.send(groupId, text);
|