diff options
| author | Fuwn <[email protected]> | 2023-12-15 23:54:53 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-15 23:54:53 -0800 |
| commit | f056a1e19470967198b1dab61cf6133047f07afd (patch) | |
| tree | ea3ac4647037c257d1866aff7ff23cf64d9f9f3b /src/routes/feeds/activity-notifications/+server.ts | |
| parent | feat(media): multiple dueincludes (diff) | |
| download | due.moe-f056a1e19470967198b1dab61cf6133047f07afd.tar.xz due.moe-f056a1e19470967198b1dab61cf6133047f07afd.zip | |
feat(notifications): refresh token
Diffstat (limited to 'src/routes/feeds/activity-notifications/+server.ts')
| -rw-r--r-- | src/routes/feeds/activity-notifications/+server.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/routes/feeds/activity-notifications/+server.ts b/src/routes/feeds/activity-notifications/+server.ts index fde2027d..f0482194 100644 --- a/src/routes/feeds/activity-notifications/+server.ts +++ b/src/routes/feeds/activity-notifications/+server.ts @@ -59,9 +59,19 @@ const render = (posts: Notification[] = []) => `<?xml version="1.0" encoding="UT `; export const GET = async ({ url }) => { - const token = url.searchParams.get('token'); + let token = url.searchParams.get('token'); + const refresh = url.searchParams.get('refresh'); + let notification = await notifications(token || ''); - return new Response(token ? render(await notifications(token)) : render(), { + if (notification === null) { + token = ( + await (await fetch(`https://192.168.1.60:5173/api/oauth/refresh?token=${refresh}`)).json() + )['access_token']; + + notification = await notifications(token as string); + } + + return new Response(token ? render(notification || []) : render(), { headers: { 'Cache-Control': `max-age=0, s-max-age=0`, 'Content-Type': 'application/xml' |