feat: shorten character ID

This commit is contained in:
2026-03-22 12:39:52 +07:00 Unverified
parent da2a273a12
commit 6a86034fc6
2 changed files with 22 additions and 11 deletions
+11 -3
View File
@@ -1,7 +1,7 @@
import { feature } from "bun:bundle"; import { feature } from "bun:bundle";
import { ImageResponse } from "@takumi-rs/image-response"; import { ImageResponse } from "@takumi-rs/image-response";
import { file, hash, inspect } from "bun"; import { file, hash, inspect } from "bun";
import { NotFoundError, redirect, status, t } from "elysia"; import { NotFoundError, status, t } from "elysia";
import { import {
EquipType, EquipType,
fetchEnka, fetchEnka,
@@ -238,7 +238,10 @@ export function card(app: App) {
if (typeof data.avatarInfoList === "undefined") if (typeof data.avatarInfoList === "undefined")
return error(400, errorLoc.private); return error(400, errorLoc.private);
const char = data.avatarInfoList.find( const char = data.avatarInfoList.find(
(c) => c.avatar.avatarId === Number(charId), (c) =>
c.avatar.avatarId === Number(charId) ||
`${c.avatar.avatarId}`.match(/^10*(\d+)/)?.[1] ===
`${charId}`,
); );
if (!char) return error(400, errorLoc.notInShowcase); if (!char) return error(400, errorLoc.notInShowcase);
@@ -262,7 +265,12 @@ export function card(app: App) {
typeof w === "number" ? w / (1218 / 508) : heightRaw; typeof w === "number" ? w / (1218 / 508) : heightRaw;
const cacheKey = hash( const cacheKey = hash(
JSON.stringify({ data, charId, lang, height }), JSON.stringify({
data,
charId: char.avatar.avatarId,
lang,
height,
}),
).toString(36); ).toString(36);
if (feature("API")) { if (feature("API")) {
if (!debug) { if (!debug) {
+11 -8
View File
@@ -142,14 +142,17 @@ export async function ListPage(
</div> </div>
</div> </div>
</div> </div>
<div tw="absolute bottom-[.2em] right-[.2em] leading-none p-[.2em] rounded-md bg-black/50"> <div tw="absolute bottom-0 right-0 leading-none p-[.2em] pb-[.3em] pr-[.45em] rounded-tl-md bg-black/50">
{uid <div tw="opacity-0 whitespace-pre">00000000/00 </div>
.slice(-7) <div tw="absolute">
.split("") {uid
.map((c, i) => ( .slice(-7)
<div style={{ opacity: i / 5 }}>{c}</div> .split("")
))} .map((c, i) => (
/{a.avatar.avatarId} <div style={{ opacity: i / 5 }}>{c}</div>
))}
/{`${a.avatar.avatarId}`.match(/^10*(\d+)/)?.[1]}
</div>
</div> </div>
</div> </div>
))} ))}