From cd49dd513c27cb8d856d822dcc778a77cf7d670e Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 17 Sep 2023 19:58:24 -0700 Subject: feat(routes): rss feed git status --- src/routes/feeds/notifications/+server.ts | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/routes/feeds/notifications/+server.ts (limited to 'src/routes') diff --git a/src/routes/feeds/notifications/+server.ts b/src/routes/feeds/notifications/+server.ts new file mode 100644 index 00000000..b06aa1f3 --- /dev/null +++ b/src/routes/feeds/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' + } + }); +}; -- cgit v1.2.3