aboutsummaryrefslogtreecommitdiff
path: root/src/routes/feeds/activity-notifications/+server.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-01 16:20:51 -0800
committerFuwn <[email protected]>2026-03-01 16:21:02 -0800
commiteae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch)
tree1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/routes/feeds/activity-notifications/+server.ts
parentchore(tooling): remove legacy eslint and prettier (diff)
downloaddue.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz
due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/routes/feeds/activity-notifications/+server.ts')
-rw-r--r--src/routes/feeds/activity-notifications/+server.ts102
1 files changed, 56 insertions, 46 deletions
diff --git a/src/routes/feeds/activity-notifications/+server.ts b/src/routes/feeds/activity-notifications/+server.ts
index 37190255..e4725a5b 100644
--- a/src/routes/feeds/activity-notifications/+server.ts
+++ b/src/routes/feeds/activity-notifications/+server.ts
@@ -1,11 +1,19 @@
-import { notifications, type Notification } from '$lib/Data/AniList/notifications';
-import root from '$lib/Utility/root';
+import {
+ notifications,
+ type Notification,
+} from "$lib/Data/AniList/notifications";
+import root from "$lib/Utility/root";
const htmlEncode = (input: string) => {
- return input.replace(/[\u00A0-\u9999<>&]/g, (i) => '&#' + i.charCodeAt(0) + ';');
+ return input.replace(
+ /[\u00A0-\u9999<>&]/g,
+ (i) => "&#" + i.charCodeAt(0) + ";",
+ );
};
-const render = (posts: Notification[] = []) => `<?xml version="1.0" encoding="UTF-8" ?>
+const render = (
+ posts: Notification[] = [],
+) => `<?xml version="1.0" encoding="UTF-8" ?>
<rss
version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
@@ -22,33 +30,35 @@ const render = (posts: Notification[] = []) => `<?xml version="1.0" encoding="UT
<language>en-US</language>
<snf:logo><url>https://due.moe/favicon-196x196.png</url></snf:logo>
${posts
- .filter((notification: Notification) => notification.type !== undefined)
- .map((notification: Notification) => {
- let title = `${notification.user.name}${notification.context}`;
- let link = `https://anilist.co/user/${notification.user.name}`;
- const prettyType = notification.type
- .toString()
- .replace(/_/g, ' ')
- .toLowerCase()
- .replace(/\w\S*/g, (text) => {
- return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();
- });
+ .filter((notification: Notification) => notification.type !== undefined)
+ .map((notification: Notification) => {
+ let title = `${notification.user.name}${notification.context}`;
+ let link = `https://anilist.co/user/${notification.user.name}`;
+ const prettyType = notification.type
+ .toString()
+ .replace(/_/g, " ")
+ .toLowerCase()
+ .replace(/\w\S*/g, (text) => {
+ return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();
+ });
- try {
- if (
- !['FOLLOWING', 'ACTIVITY_MESSAGE'].includes(notification.type.toString()) &&
- !notification.type.toString().includes('THREAD')
- ) {
- link = `https://anilist.co/activity/${notification.activity.id}`;
- } else if (notification.type.toString().includes('THREAD')) {
- title += `${notification.thread.title}`;
- link = `https://anilist.co/forum/thread/${notification.thread.id}`;
- }
- } catch {
- return '';
- }
+ try {
+ if (
+ !["FOLLOWING", "ACTIVITY_MESSAGE"].includes(
+ notification.type.toString(),
+ ) &&
+ !notification.type.toString().includes("THREAD")
+ ) {
+ link = `https://anilist.co/activity/${notification.activity.id}`;
+ } else if (notification.type.toString().includes("THREAD")) {
+ title += `${notification.thread.title}`;
+ link = `https://anilist.co/forum/thread/${notification.thread.id}`;
+ }
+ } catch {
+ return "";
+ }
- return `<item>
+ return `<item>
<guid isPermaLink="false">${notification.id}</guid>
<title>${htmlEncode(title)}</title>
<link>${link}</link>
@@ -57,29 +67,29 @@ const render = (posts: Notification[] = []) => `<?xml version="1.0" encoding="UT
<category>${prettyType}</category>
<pubDate>${new Date(notification.createdAt * 1000).toUTCString()}</pubDate>
</item>`;
- })
- .join('')}
+ })
+ .join("")}
</channel>
</rss>
`;
export const GET = async ({ url }) => {
- let token = url.searchParams.get('token');
- const refresh = url.searchParams.get('refresh');
- let notification = await notifications(token || '');
+ let token = url.searchParams.get("token");
+ const refresh = url.searchParams.get("refresh");
+ let notification = await notifications(token || "");
- if (notification === null) {
- token = (await (await fetch(root(`/api/oauth/refresh?token=${refresh}`))).json())[
- 'access_token'
- ];
+ if (notification === null) {
+ token = (
+ await (await fetch(root(`/api/oauth/refresh?token=${refresh}`))).json()
+ )["access_token"];
- notification = await notifications(token as string);
- }
+ notification = await notifications(token as string);
+ }
- return new Response(token ? render(notification || []) : render(), {
- headers: {
- 'Cache-Control': `max-age=0`,
- 'Content-Type': 'application/xml'
- }
- });
+ return new Response(token ? render(notification || []) : render(), {
+ headers: {
+ "Cache-Control": `max-age=0`,
+ "Content-Type": "application/xml",
+ },
+ });
};