diff options
Diffstat (limited to 'src/routes/api/birthdays/primary')
| -rw-r--r-- | src/routes/api/birthdays/primary/+server.ts | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/routes/api/birthdays/primary/+server.ts b/src/routes/api/birthdays/primary/+server.ts index 774d47e1..109961f8 100644 --- a/src/routes/api/birthdays/primary/+server.ts +++ b/src/routes/api/birthdays/primary/+server.ts @@ -1,40 +1,40 @@ -import { JSDOM } from 'jsdom'; +import { JSDOM } from "jsdom"; +import { appOriginHeaders } from "$lib/Utility/appOrigin"; export const GET = async ({ url }: { url: URL }) => { - const document = new JSDOM( - await ( - await fetch( - `https://www.anisearch.com/character/birthdays?month=${url.searchParams.get('month')}` - ) - ).text() - ).window.document; - const section = document.querySelector(`#day-${url.searchParams.get('day')}`); - - if (!section) return Response.json([]); - - const ul = section.querySelector('ul.covers.simple'); - - if (!ul) return Response.json([]); - - return Response.json( - Array.from(ul.querySelectorAll('li')).map((li) => { - const anchor = li.querySelector('a'); - const title = li.querySelector('.title'); - - if (!anchor || !title) return { image: '', title: '' }; - - const image = li.getElementsByClassName('item-cover')[0]; - - return { - image: image ? image.getAttribute('src') : '', - name: title.textContent?.trim() - }; - }), - { - headers: { - 'Cache-Control': 'max-age=10800, s-maxage=10800', - 'Access-Control-Allow-Origin': 'https://due.moe' - } - } - ); + const document = new JSDOM( + await ( + await fetch( + `https://www.anisearch.com/character/birthdays?month=${url.searchParams.get("month")}`, + ) + ).text(), + ).window.document; + const section = document.querySelector(`#day-${url.searchParams.get("day")}`); + + if (!section) return Response.json([]); + + const ul = section.querySelector("ul.covers.simple"); + + if (!ul) return Response.json([]); + + return Response.json( + Array.from(ul.querySelectorAll("li")).map((li) => { + const anchor = li.querySelector("a"); + const title = li.querySelector(".title"); + + if (!anchor || !title) return { image: "", title: "" }; + + const image = li.getElementsByClassName("item-cover")[0]; + + return { + image: image ? image.getAttribute("src") : "", + name: title.textContent?.trim(), + }; + }), + { + headers: appOriginHeaders({ + "Cache-Control": "max-age=10800, s-maxage=10800", + }), + }, + ); }; |