Run scheduled tasks through application database
Validate and deploy staging / validate (push) Successful in 18s
Validate and deploy staging / deploy (push) Successful in 44s

This commit is contained in:
JB
2026-07-26 10:38:07 -04:00
parent 548d19d9ea
commit f5eb2fd663
8 changed files with 221 additions and 14 deletions
@@ -0,0 +1,20 @@
import { createHash, timingSafeEqual } from 'node:crypto';
import { env } from '$env/dynamic/private';
import { runScheduledNotificationTasks } from '$lib/server/scheduled-notifications';
import { json } from '@sveltejs/kit';
function tokenMatches(header: string | null) {
const configured = env.SCHEDULER_TOKEN;
const provided = header?.startsWith('Bearer ') ? header.slice(7) : '';
if (!configured || !provided) return false;
const expectedHash = createHash('sha256').update(configured).digest();
const providedHash = createHash('sha256').update(provided).digest();
return timingSafeEqual(expectedHash, providedHash);
}
export async function POST({ request }) {
if (!tokenMatches(request.headers.get('authorization'))) {
return json({ error: 'Not found' }, { status: 404 });
}
return json({ status: 'ok', ...(await runScheduledNotificationTasks()) });
}