diff options
| author | Fuwn <[email protected]> | 2024-07-24 21:24:09 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-24 21:24:09 -0700 |
| commit | 8a94bbfba322f8011017980e4362d46c4d51bb55 (patch) | |
| tree | 4d861cd7f1d9304e6297e1b52fe759674fd5df1a /src/jobs | |
| parent | feat(layout): browser notifications (diff) | |
| download | due.moe-8a94bbfba322f8011017980e4362d46c4d51bb55.tar.xz due.moe-8a94bbfba322f8011017980e4362d46c4d51bb55.zip | |
feat: background notifications
Diffstat (limited to 'src/jobs')
| -rw-r--r-- | src/jobs/index.ts | 1 | ||||
| -rw-r--r-- | src/jobs/notifications.ts | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/jobs/index.ts b/src/jobs/index.ts new file mode 100644 index 00000000..9ea5ce77 --- /dev/null +++ b/src/jobs/index.ts @@ -0,0 +1 @@ +export * from './notifications'; diff --git a/src/jobs/notifications.ts b/src/jobs/notifications.ts new file mode 100644 index 00000000..3c29ecfc --- /dev/null +++ b/src/jobs/notifications.ts @@ -0,0 +1,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 {}; + } +}); |