diff options
| author | Fuwn <[email protected]> | 2024-07-22 16:00:33 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-22 16:00:33 -0700 |
| commit | a7fe390be2b812e77395738eba395835dc45f007 (patch) | |
| tree | d821839a4bc0eb8f90e676a24595f49bc716c295 /src/routes/api/birthdays/primary/+server.ts | |
| parent | fix(SequelSpy): use LinkedTooltip (diff) | |
| download | due.moe-a7fe390be2b812e77395738eba395835dc45f007.tar.xz due.moe-a7fe390be2b812e77395738eba395835dc45f007.zip | |
refactor(Birthday): rename modules
Diffstat (limited to 'src/routes/api/birthdays/primary/+server.ts')
| -rw-r--r-- | src/routes/api/birthdays/primary/+server.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/routes/api/birthdays/primary/+server.ts b/src/routes/api/birthdays/primary/+server.ts new file mode 100644 index 00000000..0b92a11e --- /dev/null +++ b/src/routes/api/birthdays/primary/+server.ts @@ -0,0 +1,40 @@ +import { JSDOM } from 'jsdom'; + +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: '' }; + + return { + image: anchor.getAttribute('data-bg') + ? `https://cdn.anisearch.com/images/${anchor.getAttribute('data-bg')}` + : null, + name: title.textContent?.trim() + }; + }), + { + headers: { + 'Cache-Control': 'max-age=10800, s-maxage=10800', + 'Access-Control-Allow-Origin': 'https://due.moe' + } + } + ); +}; |