chore: fmt [no ci]

This commit is contained in:
2026-07-07 22:16:21 +07:00 Unverified
parent 2db9bb10a2
commit 7bfabaa5a1
8 changed files with 147 additions and 127 deletions
+76 -70
View File
@@ -484,82 +484,88 @@ export function card(app: App) {
afterResponse: ({ log }) => log`Rendering completed`,
},
)
.get("/enka/:username", async ({ params: { username }, query: { lang } }) => {
const errorLoc = cardErrorLocs[lang === "th" ? "th" : "en"];
try {
const cacheKey = `enka-redir::${username}`;
if (feature("API")) {
const cached = cache.get<Response>(cacheKey);
if (cached) return cached.clone();
}
.get(
"/enka/:username",
async ({ params: { username }, query: { lang } }) => {
const errorLoc = cardErrorLocs[lang === "th" ? "th" : "en"];
try {
const cacheKey = `enka-redir::${username}`;
if (feature("API")) {
const cached = cache.get<Response>(cacheKey);
if (cached) return cached.clone();
}
const [hoyo] = await fetch(
`https://enka.network/api/profile/${username}/hoyos/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { hoyo_type: number; order: NumberLike }>
>,
const [hoyo] = await fetch(
`https://enka.network/api/profile/${username}/hoyos/`,
)
.then((e) =>
Object.entries(e)
.map(([k, v]) => ({ hash: k, ...v }))
.sort((a, b) => Number(a.order) - Number(b.order))
.filter((e) => e.hoyo_type === 0),
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { hoyo_type: number; order: NumberLike }>
>,
)
.then((e) =>
Object.entries(e)
.map(([k, v]) => ({ hash: k, ...v }))
.sort((a, b) => Number(a.order) - Number(b.order))
.filter((e) => e.hoyo_type === 0),
);
if (!hoyo) return status(404, errorLoc.profileNotFound);
const buildsArr = fetch(
`https://enka.network/api/profile/${username}/hoyos/${hoyo.hash}/builds/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { id: number; order: NumberLike }[]>
>,
);
const builds = await buildsArr.then((e) =>
((
pair:
| [string, { id: number; order: `${number}` }[]]
| undefined,
) =>
pair
? {
char: pair[0],
...pair[1]
.sort((a, b) => Number(a.order) - Number(b.order))
.shift(),
}
: undefined)(Object.entries(e).shift()),
);
if (!hoyo) return status(404, errorLoc.profileNotFound);
const buildsArr = fetch(
`https://enka.network/api/profile/${username}/hoyos/${hoyo.hash}/builds/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { id: number; order: NumberLike }[]>
>,
);
const builds = await buildsArr.then((e) =>
((
pair: [string, { id: number; order: `${number}` }[]] | undefined,
) =>
pair
? {
char: pair[0],
...pair[1]
.sort((a, b) => Number(a.order) - Number(b.order))
.shift(),
}
: undefined)(Object.entries(e).shift()),
);
if (!builds?.id) return status(404, errorLoc.buildNotFound);
if (!builds?.id) return status(404, errorLoc.buildNotFound);
const res = redirect(
`/v1/card/enka/${username}/${hoyo.hash}/${builds.char}/${builds.id}`,
);
queueMicrotask(async () => {
cache.set(cacheKey, res, 1000 * 60); // cache for 1 minute
cache.set(
`enka-redir::${username}::${hoyo.hash}`,
await buildsArr,
1000 * 120,
const res = redirect(
`/v1/card/enka/${username}/${hoyo.hash}/${builds.char}/${builds.id}`,
);
});
queueMicrotask(async () => {
cache.set(cacheKey, res, 1000 * 60); // cache for 1 minute
cache.set(
`enka-redir::${username}::${hoyo.hash}`,
await buildsArr,
1000 * 120,
);
});
return res.clone();
} catch (err) {
if (err instanceof ResponseNotOkError && err.status === 404)
return status(404, errorLoc.profileNotFound);
throw err;
}
}, {
query: t.Partial(
t.Object({
lang: Locale,
}),
),
})
return res.clone();
} catch (err) {
if (err instanceof ResponseNotOkError && err.status === 404)
return status(404, errorLoc.profileNotFound);
throw err;
}
},
{
query: t.Partial(
t.Object({
lang: Locale,
}),
),
},
)
.get(
"/enka/:username/:hash/:char/:build",
async ({
+1 -2
View File
@@ -243,8 +243,7 @@ export async function ListPage(
cons:
avatarInfoList?.find(
(e) => e.avatar.avatarId === a.avatar.avatarId,
)!.talentIdList?.length ??
a.talentLevel,
)!.talentIdList?.length ?? a.talentLevel,
}))
.map(({ a, c, cons }) => (
<div tw="relative flex flex-col rounded-[.3em] overflow-hidden shadow-[0_.08em_.35em_rgba(0,0,0,.18)]">