import { notifications, type Notification } from '$lib/AniList/notifications'; const htmlEncode = (input: string) => { return input.replace(/[\u00A0-\u9999<>&]/g, (i) => '&#' + i.charCodeAt(0) + ';'); }; 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 ${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(); }); 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}`; } return ` ${notification.id} ${htmlEncode(title)} ${link} ${notification.user.name} ${prettyType} ${new Date(notification.createdAt * 1000).toUTCString()} `; }) .join('')} `; export const GET = async ({ url }) => { const token = url.searchParams.get('token'); return new Response(token ? render(await notifications(token)) : render(), { headers: { 'Cache-Control': `max-age=0, s-max-age=0`, 'Content-Type': 'application/xml' } }); };