Skip to content

Commit

Permalink
add character icons asset api
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue committed Jun 18, 2024
1 parent d1f99cf commit 0c0752c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions api/v2/images/character_icons/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check
import { characters } from "@gi-tcg/static-data";

/**
* @typedef {import("@vercel/node").VercelRequest} VercelRequest
* @typedef {import("@vercel/node").VercelResponse} VercelResponse
*/

const ICONS_MAP = Object.fromEntries(characters.map((ch) => [ch.id, ch.icon]));

/**
*
* @param {VercelRequest} req
* @param {VercelResponse} res
* @returns
*/
export default function handler(req, res) {
const { id } = req.query;
if (Array.isArray(id)) {
res.status(400)
.send("Bad request (multiple id)");
return;
}
const icon = ICONS_MAP[id];
const url = `/assets/${icon}.webp`;
if (icon) {
res.status(307).setHeader("Location", url).send(void 0);
return;
} else {
res.status(404).send("Not found");
return;
}
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@genshin-db/tcg": "^5.1.6",
"@gi-tcg/static-data": "^0.8.4",
"@gi-tcg/static-data": "^0.9.0",
"@mdi/font": "^7.4.47",
"@types/bun": "^1.0.5",
"@types/node": "^20.11.16",
Expand Down

0 comments on commit 0c0752c

Please sign in to comment.