blob: 3c29ecfc1b032bd0ed0ff166ac956248245fbf7c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { intervalTrigger } from '@trigger.dev/sdk';
import { client } from '../trigger';
import * as webpush from 'web-push';
import { env as privateEnv } from '$env/dynamic/private';
import { env } from '$env/dynamic/public';
import { getUserSubscriptions } from '$lib/Database/userNotifications';
webpush.setVapidDetails(
privateEnv.VAPID_SUBJECT,
env.PUBLIC_VAPID_PUBLIC_KEY,
privateEnv.VAPID_PRIVATE_KEY
);
client.defineJob({
id: 'notifications',
name: 'Notifications',
version: '0.0.1',
trigger: intervalTrigger({
seconds: 20
}),
run: async () => {
for (const subscription of await getUserSubscriptions())
await webpush.sendNotification(subscription['subscription'], '.');
return {};
}
});
|