From 3dcbb7d40691de74dcdca6ebf9c599234b7388c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=BC=E3=83=BC=E3=83=AC?= Date: Mon, 12 May 2025 14:23:48 +0500 Subject: [PATCH] Create shikimori-proxy.ts --- api/v1/src/shikimori-proxy.ts | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api/v1/src/shikimori-proxy.ts diff --git a/api/v1/src/shikimori-proxy.ts b/api/v1/src/shikimori-proxy.ts new file mode 100644 index 0000000..7773194 --- /dev/null +++ b/api/v1/src/shikimori-proxy.ts @@ -0,0 +1,39 @@ +import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; + +serve(async (req) => { + const url = new URL(req.url); + const search = url.searchParams.get("search"); + const year = url.searchParams.get("year"); + + if (!search) { + return new Response("Missing search param", { status: 400 }); + } + + const targetUrl = `https://shikimori.one/api/animes?search=${encodeURIComponent(search)}&limit=1${year ? `&year=${year}` : ""}`; + + try { + const shikiRes = await fetch(targetUrl, { + headers: { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Accept": "application/json" + } + }); + + const data = await shikiRes.text(); + + return new Response(data, { + status: 200, + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*" + } + }); + } catch (err) { + return new Response(JSON.stringify({ error: "Shikimori fetch failed" }), { + status: 500, + headers: { + "Content-Type": "application/json" + } + }); + } +});