fix: improve fuzzy handling

This commit is contained in:
2026-05-30 19:32:01 +07:00 Unverified
parent 4bf2466b3d
commit 39f1eb6988
13 changed files with 280 additions and 264 deletions
+6 -3
View File
@@ -55,7 +55,8 @@ export function endfieldCard(app: App) {
params: t.Object({ uid: t.String() }),
detail: {
tags: ["Endfield"],
description: "Preload data required to render an Endfield template card.",
description:
"Preload data required to render an Endfield template card.",
},
afterResponse: ({ log }) => log`Data preload complete`,
},
@@ -121,7 +122,8 @@ export function endfieldCard(app: App) {
{ http: "http", card: "card" },
{
default: "http",
description: "Type of error to return when card fails to render.",
description:
"Type of error to return when card fails to render.",
},
),
debug: t.Boolean({
@@ -134,7 +136,8 @@ export function endfieldCard(app: App) {
),
detail: {
tags: ["Endfield"],
description: "Generate a placeholder Endfield profile card image from a UID.",
description:
"Generate a placeholder Endfield profile card image from a UID.",
},
afterResponse: ({ log }) => log`Rendering completed`,
},
+8 -3
View File
@@ -61,7 +61,9 @@ export function EndfieldTemplate({
<div tw="text-[1.55em] leading-[1.15] font-semibold">
Route + Card Shell
</div>
<div tw="text-white/60 mt-[.35em]">Ready for game-specific layout work</div>
<div tw="text-white/60 mt-[.35em]">
Ready for game-specific layout work
</div>
</div>
<div tw="rounded-[1em] border border-white/10 bg-black/20 p-[1.2em]">
@@ -71,7 +73,9 @@ export function EndfieldTemplate({
<div tw="text-[1.55em] leading-[1.15] font-semibold">
Character Grid
</div>
<div tw="text-white/60 mt-[.35em]">Replace placeholder sections with Endfield data</div>
<div tw="text-white/60 mt-[.35em]">
Replace placeholder sections with Endfield data
</div>
</div>
</div>
@@ -80,7 +84,8 @@ export function EndfieldTemplate({
Signature
</div>
<div tw="text-[1.05em] leading-[1.45] text-white/82 whitespace-pre-wrap">
{signature?.trim() || "No signature available in the fetched payload yet."}
{signature?.trim() ||
"No signature available in the fetched payload yet."}
</div>
</div>
</div>
+5 -6
View File
@@ -3,7 +3,7 @@ import { mkdir, readdir, rm } from "node:fs/promises";
import { join } from "node:path";
import { file, hash, write } from "bun";
import type { ResolvedPlayerInfo} from "enka.ts";
import type { ResolvedPlayerInfo } from "enka.ts";
import { TTLCache } from "enka.ts";
import type {
@@ -13,11 +13,9 @@ import type {
EnkaNamecards,
EnkaPfps,
RelicStore,
WeaponStore} from "@/games/genshin/types/enka";
import {
ElementList
WeaponStore,
} from "@/games/genshin/types/enka";
import { ElementList } from "@/games/genshin/types/enka";
import { Deduplicator } from "@/lib/dedupe";
import { createLogger } from "@/lib/logger";
@@ -210,10 +208,11 @@ export async function getEnkaStore<K extends keyof StoreTypeMap>(
return data;
}
// DEPRECATED: No longer needed
export function getAvatar(
store: AvatarStore,
playerInfo: ResolvedPlayerInfo,
id: number,
id: string | number,
) {
return (
Object.entries(store).find(
+6 -3
View File
@@ -1,9 +1,9 @@
import type { BaseAvatar } from "enka.ts";
import { distance } from "fastest-levenshtein";
function shortAvatarId(id: number) {
function shortAvatarId(id: string | number) {
// 10000120 -> 120
return String(id).replace(/^10*/, "");
return String(id).replace(/^10*/, "").replace(/^-\d+/, "");
}
function norm(s: string) {
@@ -60,5 +60,8 @@ function fuzzyNameMatch<T extends { avatar: BaseAvatar }>(
}
function avatarAliases(name: string) {
return [name, ...name.split(" ")];
const aliases: Record<string, string[]> = {
Traveler: ["Aether", "Lumine"],
};
return [name, ...name.split(" "), ...(aliases[name] ?? [])];
}
+4 -1
View File
@@ -2,7 +2,10 @@ import type { ResolvedAvatarInfo } from "enka.ts";
import { AvatarElement } from "enka.ts";
import type { EnkaLocsLanguage } from "@/games/genshin/types/enka";
import { FightPropMapEnum, PercentageFightProp } from "@/games/genshin/types/fightPropMap";
import {
FightPropMapEnum,
PercentageFightProp,
} from "@/games/genshin/types/fightPropMap";
// Types
interface DisplayRow {
+4 -1
View File
@@ -1,5 +1,8 @@
import type { Affix } from "@/games/genshin/types/enka";
import { FightPropMapEnum, PercentageFightProp } from "@/games/genshin/types/fightPropMap";
import {
FightPropMapEnum,
PercentageFightProp,
} from "@/games/genshin/types/fightPropMap";
export type RollSummary = {
id: string;
-1
View File
@@ -19,7 +19,6 @@ import {
} from "@/games/genshin/types/enka";
import type { Logger } from "@/lib/logger";
import { arrRandom } from "@/lib/util";
import { CardResponse } from "@/v1/response";
export async function ListPage(
+1 -1
View File
@@ -1,6 +1,6 @@
import { t } from "elysia";
export type AvatarStore = Record<number, Avatar>;
export type AvatarStore = Record<string | number, Avatar>;
export interface Avatar {
Element: ElementType;
+1 -1
View File
@@ -1,3 +1,4 @@
import { cors } from "@elysia/cors";
import openapi from "@elysiajs/openapi";
import { Elysia, t } from "elysia";
@@ -5,7 +6,6 @@ import { version } from "../package.json";
import { pm } from "./lib/auth";
import { createLogger } from "./lib/logger";
import { v1routes } from "./v1";
import { cors } from '@elysia/cors'
const log = createLogger("APP");
+1 -1
View File
@@ -1,5 +1,5 @@
import { feature } from "bun:bundle";
import type { InspectColor} from "node:util";
import type { InspectColor } from "node:util";
import { styleText } from "node:util";
import { inspect } from "bun";
+14 -14
View File
@@ -10,19 +10,19 @@ export function v1routes(app: App) {
.use(card)
// .use(endfieldCard)
.get(
"/status/:status",
async ({ params: { status }, set }) => {
const res = await fetch(
`http://mts.dgnr.us:3999/__error/${status}/testerror.astrxl.dev`,
);
set.headers["content-type"] = "text/html";
return res;
},
{
params: t.Object({
status: t.RegExp(/^[1-5][0-9][0-9]$/),
}),
},
),
"/status/:status",
async ({ params: { status }, set }) => {
const res = await fetch(
`http://mts.dgnr.us:3999/__error/${status}/testerror.astrxl.dev`,
);
set.headers["content-type"] = "text/html";
return res;
},
{
params: t.Object({
status: t.RegExp(/^[1-5][0-9][0-9]$/),
}),
},
),
);
}