mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
refactor(core): message tracker abstraction and formatter plugin registry
This commit is contained in:
9 files changed
+361
-90
No files matched your search
@@ -0,0 +1,24 @@
|
||||
export interface MessageTracker {
|
||||
get(eventId: string, targetId: string): Promise<string | null>;
|
||||
set(eventId: string, targetId: string, messageId: string): Promise<void>;
|
||||
delete(eventId: string, targetId: string): Promise<void>;
|
||||
}
|
||||
|
||||
const MESSAGE_KEY_TTL_SECONDS = 604800;
|
||||
|
||||
export function kvMessageTracker(kv: KVNamespace): MessageTracker {
|
||||
const key = (eventId: string, targetId: string): string => `msg:${eventId}:${targetId}`;
|
||||
return {
|
||||
async get(eventId: string, targetId: string): Promise<string | null> {
|
||||
return kv.get(key(eventId, targetId));
|
||||
},
|
||||
async set(eventId: string, targetId: string, messageId: string): Promise<void> {
|
||||
await kv.put(key(eventId, targetId), messageId, {
|
||||
expirationTtl: MESSAGE_KEY_TTL_SECONDS,
|
||||
});
|
||||
},
|
||||
async delete(eventId: string, targetId: string): Promise<void> {
|
||||
await kv.delete(key(eventId, targetId));
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user