From 038e763326d8b4f0739f8bce860e577c3c1ff367 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 17 Sep 2023 20:13:59 -0700 Subject: feat(settings): add settings tab for feeds --- src/routes/feeds/activity-notifications/+server.ts | 58 ++++++++++++++++++++++ src/routes/settings/+page.svelte | 17 +++++++ 2 files changed, 75 insertions(+) create mode 100644 src/routes/feeds/activity-notifications/+server.ts (limited to 'src/routes') diff --git a/src/routes/feeds/activity-notifications/+server.ts b/src/routes/feeds/activity-notifications/+server.ts new file mode 100644 index 00000000..3ab0e2c7 --- /dev/null +++ b/src/routes/feeds/activity-notifications/+server.ts @@ -0,0 +1,58 @@ +import { notifications, type Notification } from '$lib/AniList/notifications'; + +export const GET = async ({ url }) => { + const data = await notifications(url.searchParams.get('token') || 'null'); + const render = (posts: Notification[]) => ` + + + + 期限 | AniList Notifications + https://due.moe + Instantly view your AniList notifications via RSS! + ${new Date().toUTCString()} + ${new Date().toUTCString()} + en-US + + https://due.moe/favicon-192x192.png + https://due.moe + 期限 Logo + + ${posts + .map((notification: Notification) => { + let title = `${notification.user.name} ${notification.context}`; + const prettyType = notification.type + .toString() + .replace(/_/g, ' ') + .toLowerCase() + .replace(/\w\S*/g, (text) => { + return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase(); + }); + + if (notification.type.toString().includes('THREAD')) { + title += `${notification.thread.title}`; + } + + return ` +${notification.id} +${title} +https://anilist.co/user/${notification.user.name} +${notification.user.name} + +${prettyType} +${new Date( + notification.createdAt * 1000 + new Date().getTimezoneOffset() + ).toUTCString()} +`; + }) + .join('')} + + +`; + + return new Response(render(data), { + headers: { + 'Cache-Control': `max-age=0, s-max-age=${600}`, + 'Content-Type': 'application/xml' + } + }); +}; diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index 0686b201..ea7d6d8b 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -30,6 +30,23 @@ {#if data.user === undefined} Please log in to modify settings. {:else} +
+ RSS Feeds + + + navigator.clipboard.writeText( + `https://due.moe/feeds/activity-notifications?token=${data.user.accessToken}` + )} + > + Click to copy AniList notifications RSS feed URL and token + + Do not share this with anyone! +
+ +

+

Display -- cgit v1.2.3