aboutsummaryrefslogtreecommitdiff
path: root/src/routes/feeds
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-10-09 00:41:20 -0700
committerFuwn <[email protected]>2024-10-09 00:41:43 -0700
commit998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch)
tree50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/routes/feeds
parentfeat(graphql): add badgeCount field (diff)
downloaddue.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz
due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/routes/feeds')
-rw-r--r--src/routes/feeds/activity-notifications/+server.ts86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/routes/feeds/activity-notifications/+server.ts b/src/routes/feeds/activity-notifications/+server.ts
index 354f80a0..b8675de9 100644
--- a/src/routes/feeds/activity-notifications/+server.ts
+++ b/src/routes/feeds/activity-notifications/+server.ts
@@ -2,7 +2,7 @@ import { notifications, type Notification } from '$lib/Data/AniList/notification
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" ?>
@@ -22,33 +22,33 @@ 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 +57,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'
+ }
+ });
};