aboutsummaryrefslogtreecommitdiff
path: root/src/routes/feeds/activity-notifications/+server.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-15 23:54:53 -0800
committerFuwn <[email protected]>2023-12-15 23:54:53 -0800
commitf056a1e19470967198b1dab61cf6133047f07afd (patch)
treeea3ac4647037c257d1866aff7ff23cf64d9f9f3b /src/routes/feeds/activity-notifications/+server.ts
parentfeat(media): multiple dueincludes (diff)
downloaddue.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.ts14
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'