diff --git a/src/db.ts b/src/db.ts index bf3aa41..67a00d6 100644 --- a/src/db.ts +++ b/src/db.ts @@ -33,15 +33,12 @@ export async function checkIdentifier(key: string): Promise { } export async function markIdentifier( - identifier: string, + key: string, value: boolean = true, - expiry?: number, - now: Date = new Date() -): Promise<{ key: string }> { - const key = getKey(identifier, now); + expiry?: number +): Promise { + const internalValue = value ? '1' : '0'; - if (expiry == undefined) await redis.set(key, value ? '1' : '0'); - else await redis.set(key, value ? '1' : '0', 'EX', expiry); - - return { key }; + if (expiry == undefined) await redis.set(key, internalValue); + else await redis.set(key, internalValue, 'EX', expiry); } diff --git a/src/pages/api/cron.ts b/src/pages/api/cron.ts index 892455f..c1add8e 100644 --- a/src/pages/api/cron.ts +++ b/src/pages/api/cron.ts @@ -72,9 +72,9 @@ export default async function handler( } }; - // Send notification, mark + // Send notification, mark (expire in 1 month) await sendNotification(`${matching.message} (${matching.name})`); - await markIdentifier(matching.name, true, 60 * 60 * 24 * 31, now); + await markIdentifier(key, true, 60 * 60 * 24 * 31); return { status: 'notified', identifier: { name: matching.name, key } }; }