commit
add extra endpoints
diff --git a/src/genshin.ts b/src/genshin.ts
index 11ca65d..a117bac 100644
--- a/src/genshin.ts
+++ b/src/genshin.ts
@@ -1,24 +1,47 @@
/* =====================================================================
* genshin.ts — Enka.Network passthrough + static-data merge for a
- * player's Genshin character roster (owned/not-owned + level).
+ * player's Genshin character roster (owned/not-owned + level), plus
+ * per-character detail (weapon, artifacts, constellation, friendship).
*
- * Two independent cache tiers in the same PROFILE_CACHE KV, since they
- * change at very different rates:
+ * Three cache tiers in the same PROFILE_CACHE KV, since they change at
+ * very different rates:
* - the character *catalog* (Enka's store/characters.json + store/loc.json,
* merged into id -> {name, element, rarity, icon}) barely ever changes —
- * cached ~24h.
- * - a given player's *roster* (their UID response) can change any time
- * they refresh their in-game showcase — cached using the `ttl` Enka
- * itself returns, so we never serve staler data than Enka intends.
+ * cached ~24h. `loc` (raw localization strings) is cached separately on
+ * the same TTL so weapon/artifact name lookups don't need their own fetch.
+ * - a given player's *raw* Enka UID response is cached using the `ttl`
+ * Enka itself returns, so we never serve staler data than Enka intends.
+ * Everything below (roster list, single-character detail, items,
+ * constellations) is derived from this one cached blob — one upstream
+ * fetch per UID per ttl window, no matter how many of these are called.
*
* Note: Enka only returns a player's full owned roster (`avatarInfoList`)
* if they've enabled "Display all your characters" on their in-game
* Character Showcase. Otherwise only the pinned showcase characters
- * (`showAvatarInfoList`, up to 8) come back — the response below flags
+ * (`showAvatarInfoList`, up to 8) come back — the roster response flags
* this via `partial: true` so callers/UIs can prompt the user to enable it.
+ *
+ * Separately: even with "Display all" on, Mihoyo's own API (which Enka
+ * passes through) only includes full builds (`equipList` — weapon +
+ * artifacts) for characters currently sitting in the showcase (~8 max).
+ * The rest of `avatarInfoList` only has level/ascension/constellation. So
+ * `weapon`/`artifacts` can legitimately be empty for an owned, leveled
+ * character that just isn't pinned right now — that's an Enka/game
+ * limitation, not a bug here.
* ===================================================================== */
-import type { Env, UnifiedGenshinCharacter, UnifiedGenshinRoster } from "./types";
+import type {
+ Env,
+ UnifiedGenshinArtifact,
+ UnifiedGenshinArtifactSlot,
+ UnifiedGenshinCharacter,
+ UnifiedGenshinCharacterConstellations,
+ UnifiedGenshinCharacterDetail,
+ UnifiedGenshinCharacterItems,
+ UnifiedGenshinRoster,
+ UnifiedGenshinStat,
+ UnifiedGenshinWeapon,
+} from "./types";
import { ABUSE_CONTACT } from "./abuse";
const ENKA_UID_BASE = "https://enka.network/api/uid";
@@ -35,7 +58,8 @@ const ENKA_USER_AGENT = `doughmination-genshin-roster/1.0 (+https://doughminatio
const CATALOG_TTL_SECONDS = 60 * 60 * 24; // static game data — refresh daily
const ROSTER_MIN_TTL_SECONDS = 30; // floor under Enka's own ttl, avoids 0/negative
const CATALOG_KEY = "genshin:catalog:v1";
-const rosterKey = (uid: string) => `genshin:roster:${uid}`;
+const LOC_KEY = "genshin:loc:v1";
+const rawKey = (uid: string) => `genshin:raw:${uid}`;
const ELEMENT_NAMES: Record<string, string> = {
Fire: "Pyro",
@@ -47,6 +71,66 @@ const ELEMENT_NAMES: Record<string, string> = {
Grass: "Dendro",
};
+/** The base Traveler entries (10000005/10000007) come back from Enka's
+ * catalog as a single generic "Traveler" with whatever element their most
+ * recently-used vision happens to be — not the two named, elementless
+ * identities players actually think of them as. Override both explicitly
+ * rather than trusting the catalog for these two ids. */
+const TRAVELER_OVERRIDES: Record<string, { name: string; element: string }> = {
+ "10000005": { name: "Aether", element: "All" },
+ "10000007": { name: "Lumine", element: "All" },
+};
+
+/** appendPropId -> display name, for weapon/artifact stat lines. */
+const STAT_NAMES: Record<string, string> = {
+ FIGHT_PROP_HP: "HP",
+ FIGHT_PROP_HP_PERCENT: "HP%",
+ FIGHT_PROP_ATTACK: "ATK",
+ FIGHT_PROP_ATTACK_PERCENT: "ATK%",
+ FIGHT_PROP_DEFENSE: "DEF",
+ FIGHT_PROP_DEFENSE_PERCENT: "DEF%",
+ FIGHT_PROP_CRITICAL: "CRIT Rate",
+ FIGHT_PROP_CRITICAL_HURT: "CRIT DMG",
+ FIGHT_PROP_CHARGE_EFFICIENCY: "Energy Recharge",
+ FIGHT_PROP_ELEMENT_MASTERY: "Elemental Mastery",
+ FIGHT_PROP_HEAL_ADD: "Healing Bonus",
+ FIGHT_PROP_FIRE_ADD_HURT: "Pyro DMG Bonus",
+ FIGHT_PROP_WATER_ADD_HURT: "Hydro DMG Bonus",
+ FIGHT_PROP_WIND_ADD_HURT: "Anemo DMG Bonus",
+ FIGHT_PROP_ELEC_ADD_HURT: "Electro DMG Bonus",
+ FIGHT_PROP_ICE_ADD_HURT: "Cryo DMG Bonus",
+ FIGHT_PROP_ROCK_ADD_HURT: "Geo DMG Bonus",
+ FIGHT_PROP_GRASS_ADD_HURT: "Dendro DMG Bonus",
+ FIGHT_PROP_PHYSICAL_ADD_HURT: "Physical DMG Bonus",
+};
+/** Which of the above are percentages (Enka already reports these as e.g.
+ * 46.6, not 0.466 — this just tells the caller whether to append "%"). */
+const PERCENT_STAT_IDS = new Set([
+ "FIGHT_PROP_HP_PERCENT",
+ "FIGHT_PROP_ATTACK_PERCENT",
+ "FIGHT_PROP_DEFENSE_PERCENT",
+ "FIGHT_PROP_CRITICAL",
+ "FIGHT_PROP_CRITICAL_HURT",
+ "FIGHT_PROP_CHARGE_EFFICIENCY",
+ "FIGHT_PROP_HEAL_ADD",
+ "FIGHT_PROP_FIRE_ADD_HURT",
+ "FIGHT_PROP_WATER_ADD_HURT",
+ "FIGHT_PROP_WIND_ADD_HURT",
+ "FIGHT_PROP_ELEC_ADD_HURT",
+ "FIGHT_PROP_ICE_ADD_HURT",
+ "FIGHT_PROP_ROCK_ADD_HURT",
+ "FIGHT_PROP_GRASS_ADD_HURT",
+ "FIGHT_PROP_PHYSICAL_ADD_HURT",
+]);
+/** equipType -> artifact slot. Fixed by the game, never changes. */
+const ARTIFACT_SLOTS: Record<string, UnifiedGenshinArtifactSlot> = {
+ EQUIP_BRACER: "flower",
+ EQUIP_NECKLACE: "plume",
+ EQUIP_SHOES: "sands",
+ EQUIP_RING: "goblet",
+ EQUIP_DRESS: "circlet",
+};
+
interface RawCharacterEntry {
Element?: string;
QualityType?: string;
@@ -56,6 +140,37 @@ interface RawCharacterEntry {
type RawCharacters = Record<string, RawCharacterEntry>;
type RawLoc = Record<string, Record<string, string>>; // lang -> hash -> name
+interface RawStat {
+ appendPropId?: string;
+ statValue?: number;
+}
+interface RawFlat {
+ nameTextMapHash?: number | string;
+ setNameTextMapHash?: number | string;
+ rankLevel?: number;
+ icon?: string;
+ weaponStats?: RawStat[];
+ reliquaryMainstat?: RawStat;
+ reliquarySubstats?: RawStat[];
+ equipType?: string;
+}
+interface RawWeaponData {
+ level?: number;
+ promoteLevel?: number;
+ /** key = skill id, value = refine rank 0-4 (R1-R5). Single entry in practice. */
+ affixMap?: Record<string, number>;
+}
+interface RawReliquaryData {
+ /** 1-indexed — display level (the in-game "+N") is this minus 1. */
+ level?: number;
+}
+interface RawEquip {
+ itemId: number;
+ weapon?: RawWeaponData;
+ reliquary?: RawReliquaryData;
+ flat: RawFlat;
+}
+
interface EnkaShowAvatar {
avatarId: number;
level: number;
@@ -63,6 +178,11 @@ interface EnkaShowAvatar {
interface EnkaAvatarInfo {
avatarId: number;
propMap?: Record<string, { ival?: string }>;
+ /** Unlocked constellations, in unlock order. Length == constellation count. */
+ talentIdList?: number[];
+ fetterInfo?: { expLevel?: number };
+ /** Only present for characters currently in the showcase — see file header. */
+ equipList?: RawEquip[];
}
interface EnkaUidResponse {
playerInfo: {
@@ -93,6 +213,25 @@ async function fetchJson<T>(url: string): Promise<T> {
return (await res.json()) as T;
}
+/** Build (or fetch from cache) the raw en-locale string table (hash -> name).
+ * Shared by the character catalog and by weapon/artifact name lookups. */
+async function getLoc(env: Env, ctx?: ExecutionContext, force = false): Promise<RawLoc> {
+ if (!force) {
+ const cached = (await env.PROFILE_CACHE.get(LOC_KEY, "json")) as RawLoc | null;
+ if (cached) return cached;
+ }
+ const loc = await fetchJson<RawLoc>(LOC_JSON_URL);
+ const write = env.PROFILE_CACHE.put(LOC_KEY, JSON.stringify(loc), { expirationTtl: CATALOG_TTL_SECONDS });
+ if (ctx) ctx.waitUntil(write);
+ else await write;
+ return loc;
+}
+
+function locName(loc: RawLoc, hash: number | string | undefined): string {
+ if (hash == null) return "Unknown";
+ return loc.en?.[String(hash)] ?? "Unknown";
+}
+
interface CatalogEntry {
name: string;
element: string;
@@ -111,7 +250,7 @@ async function getCatalog(env: Env, ctx?: ExecutionContext, force = false): Prom
const [characters, loc] = await Promise.all([
fetchJson<RawCharacters>(CHARACTERS_JSON_URL),
- fetchJson<RawLoc>(LOC_JSON_URL),
+ getLoc(env, ctx, force),
]);
const en = loc.en ?? {};
@@ -122,9 +261,10 @@ async function getCatalog(env: Env, ctx?: ExecutionContext, force = false): Prom
const sideIcon = entry.SideIconName ?? "";
// "UI_AvatarIcon_Side_Ayaka" -> "UI_AvatarIcon_Ayaka" (front-facing icon)
const fullIcon = sideIcon.replace("_Side_", "_");
+ const override = TRAVELER_OVERRIDES[id];
catalog[id] = {
- name: name ?? `Traveler ${id}`,
- element: ELEMENT_NAMES[entry.Element ?? ""] ?? entry.Element ?? "Unknown",
+ name: override?.name ?? name ?? `Traveler ${id}`,
+ element: override?.element ?? ELEMENT_NAMES[entry.Element ?? ""] ?? entry.Element ?? "Unknown",
rarity: entry.QualityType?.startsWith("QUALITY_ORANGE") ? 5 : 4,
iconUrl: fullIcon ? `${ICON_BASE}/${fullIcon}.png` : "",
sideIconUrl: sideIcon ? `${ICON_BASE}/${sideIcon}.png` : "",
@@ -148,30 +288,104 @@ export class EnkaNotFoundError extends Error {
}
}
-/** Full owned/not-owned roster for a UID, merged against the character catalog.
- * Cache-first, honoring the `ttl` Enka itself returns for that profile. */
-export async function getGenshinRoster(
+/** Fetch (or return the cached copy of) the raw Enka UID response.
+ * This is the one and only upstream call per UID per ttl window — the
+ * roster list, single-character detail, items, and constellations
+ * endpoints all derive from this same cached blob. */
+async function getCachedRaw(
env: Env,
uid: string,
ctx?: ExecutionContext,
force = false,
-): Promise<UnifiedGenshinRoster> {
+): Promise<EnkaUidResponse> {
if (!force) {
- const cached = (await env.PROFILE_CACHE.get(rosterKey(uid), "json")) as UnifiedGenshinRoster | null;
+ const cached = (await env.PROFILE_CACHE.get(rawKey(uid), "json")) as EnkaUidResponse | null;
if (cached) return cached;
}
- const [raw, catalog] = await Promise.all([
- (async () => {
- const res = await fetch(`${ENKA_UID_BASE}/${uid}`, {
- headers: { "User-Agent": ENKA_USER_AGENT, Accept: "application/json" },
- });
- if (res.status === 404 || res.status === 400) throw new EnkaNotFoundError(uid);
- if (!res.ok) throw new Error(`Enka upstream returned ${res.status}`);
- return (await res.json()) as EnkaUidResponse;
- })(),
+ const res = await fetch(`${ENKA_UID_BASE}/${uid}`, {
+ headers: { "User-Agent": ENKA_USER_AGENT, Accept: "application/json" },
+ });
+ if (res.status === 404 || res.status === 400) throw new EnkaNotFoundError(uid);
+ if (!res.ok) throw new Error(`Enka upstream returned ${res.status}`);
+ const raw = (await res.json()) as EnkaUidResponse;
+
+ const ttl = Math.max(ROSTER_MIN_TTL_SECONDS, raw.ttl ?? ROSTER_MIN_TTL_SECONDS);
+ const write = env.PROFILE_CACHE.put(rawKey(uid), JSON.stringify(raw), { expirationTtl: ttl });
+ if (ctx) ctx.waitUntil(write);
+ else await write;
+
+ return raw;
+}
+
+/** Raw Enka response + the static catalog + loc strings, all cache-first. */
+async function getUidData(
+ env: Env,
+ uid: string,
+ ctx?: ExecutionContext,
+ force = false,
+): Promise<{ raw: EnkaUidResponse; catalog: Catalog; loc: RawLoc }> {
+ const [raw, catalog, loc] = await Promise.all([
+ getCachedRaw(env, uid, ctx, force),
getCatalog(env, ctx, force),
+ getLoc(env, ctx, force),
]);
+ return { raw, catalog, loc };
+}
+
+function toStat(raw: RawStat | undefined): UnifiedGenshinStat | null {
+ if (!raw?.appendPropId) return null;
+ const id = raw.appendPropId;
+ return {
+ name: STAT_NAMES[id] ?? id,
+ value: raw.statValue ?? 0,
+ is_percent: PERCENT_STAT_IDS.has(id),
+ };
+}
+
+function buildWeapon(equip: RawEquip, loc: RawLoc): UnifiedGenshinWeapon | null {
+ if (!equip.weapon) return null;
+ const refine = Object.values(equip.weapon.affixMap ?? {})[0] ?? 0;
+ return {
+ id: String(equip.itemId),
+ name: locName(loc, equip.flat.nameTextMapHash),
+ rarity: equip.flat.rankLevel ?? 1,
+ level: equip.weapon.level ?? 1,
+ ascension: equip.weapon.promoteLevel ?? 0,
+ refinement: refine + 1,
+ base_stat: toStat(equip.flat.weaponStats?.[0]),
+ sub_stat: toStat(equip.flat.weaponStats?.[1]),
+ icon_url: equip.flat.icon ? `${ICON_BASE}/${equip.flat.icon}.png` : "",
+ };
+}
+
+function buildArtifact(equip: RawEquip, loc: RawLoc): UnifiedGenshinArtifact | null {
+ if (!equip.reliquary) return null;
+ return {
+ id: String(equip.itemId),
+ name: locName(loc, equip.flat.nameTextMapHash),
+ set_name: locName(loc, equip.flat.setNameTextMapHash),
+ slot: ARTIFACT_SLOTS[equip.flat.equipType ?? ""] ?? "flower",
+ rarity: equip.flat.rankLevel ?? 1,
+ // Enka's raw reliquary.level is 1 higher than the in-game "+N" display.
+ level: Math.max(0, (equip.reliquary.level ?? 1) - 1),
+ main_stat: toStat(equip.flat.reliquaryMainstat),
+ sub_stats: (equip.flat.reliquarySubstats ?? [])
+ .map((s) => toStat(s))
+ .filter((s): s is UnifiedGenshinStat => s !== null),
+ icon_url: equip.flat.icon ? `${ICON_BASE}/${equip.flat.icon}.png` : "",
+ };
+}
+
+/** Full owned/not-owned roster for a UID, merged against the character catalog.
+ * Cache-first, honoring the `ttl` Enka itself returns for that profile. */
+export async function getGenshinRoster(
+ env: Env,
+ uid: string,
+ ctx?: ExecutionContext,
+ force = false,
+): Promise<UnifiedGenshinRoster> {
+ const { raw, catalog } = await getUidData(env, uid, ctx, force);
// Prefer the full roster (only present if the player enabled "Display all
// your characters"); fall back to the pinned showcase otherwise.
@@ -201,7 +415,7 @@ export async function getGenshinRoster(
}));
characters.sort((a, b) => (b.owned === a.owned ? a.name.localeCompare(b.name) : b.owned ? 1 : -1));
- const result: UnifiedGenshinRoster = {
+ return {
uid,
nickname: raw.playerInfo.nickname ?? null,
player_level: raw.playerInfo.level ?? null,
@@ -211,11 +425,86 @@ export async function getGenshinRoster(
characters,
updated_at: Date.now(),
};
+}
- const ttl = Math.max(ROSTER_MIN_TTL_SECONDS, raw.ttl ?? ROSTER_MIN_TTL_SECONDS);
- const write = env.PROFILE_CACHE.put(rosterKey(uid), JSON.stringify(result), { expirationTtl: ttl });
- if (ctx) ctx.waitUntil(write);
- else await write;
+/** Full detail (level, constellation, weapon, artifacts) for one character.
+ * Returns null if `heroId` isn't a real playable character id at all —
+ * an unowned-but-real character still returns a detail object (with
+ * `owned: false` and empty weapon/artifacts), since that's the normal
+ * shape for a wishlist entry. */
+export async function getGenshinCharacterDetail(
+ env: Env,
+ uid: string,
+ heroId: string,
+ ctx?: ExecutionContext,
+ force = false,
+): Promise<UnifiedGenshinCharacterDetail | null> {
+ const { raw, catalog, loc } = await getUidData(env, uid, ctx, force);
+ const meta = catalog[heroId];
+ if (!meta) return null;
- return result;
-}
\ No newline at end of file
+ const entry = (raw.playerInfo.avatarInfoList ?? []).find((c) => String(c.avatarId) === heroId);
+ const base = {
+ id: heroId,
+ name: meta.name,
+ element: meta.element,
+ rarity: meta.rarity,
+ icon_url: meta.iconUrl,
+ updated_at: Date.now(),
+ };
+
+ if (!entry) {
+ return { ...base, owned: false, level: null, constellation: 0, friendship: null, weapon: null, artifacts: [] };
+ }
+
+ const level = Number(entry.propMap?.["4001"]?.ival ?? 0);
+ const weaponEquip = entry.equipList?.find((e) => e.weapon);
+ const artifactEquips = (entry.equipList ?? []).filter((e) => e.reliquary);
+
+ return {
+ ...base,
+ owned: true,
+ level,
+ constellation: entry.talentIdList?.length ?? 0,
+ friendship: entry.fetterInfo?.expLevel ?? null,
+ weapon: weaponEquip ? buildWeapon(weaponEquip, loc) : null,
+ artifacts: artifactEquips
+ .map((e) => buildArtifact(e, loc))
+ .filter((a): a is UnifiedGenshinArtifact => a !== null),
+ };
+}
+
+/** Just the weapon + artifacts for one character. Thin slice of
+ * `getGenshinCharacterDetail` — same cache, no extra upstream cost. */
+export async function getGenshinCharacterItems(
+ env: Env,
+ uid: string,
+ heroId: string,
+ ctx?: ExecutionContext,
+ force = false,
+): Promise<UnifiedGenshinCharacterItems | null> {
+ const detail = await getGenshinCharacterDetail(env, uid, heroId, ctx, force);
+ if (!detail) return null;
+ return { weapon: detail.weapon, artifacts: detail.artifacts };
+}
+
+/** Just the constellation count/unlock order + friendship level for one
+ * character. Thin slice, same cache as the roster/detail calls. */
+export async function getGenshinCharacterConstellations(
+ env: Env,
+ uid: string,
+ heroId: string,
+ ctx?: ExecutionContext,
+ force = false,
+): Promise<UnifiedGenshinCharacterConstellations | null> {
+ const { raw, catalog } = await getUidData(env, uid, ctx, force);
+ if (!catalog[heroId]) return null;
+
+ const entry = (raw.playerInfo.avatarInfoList ?? []).find((c) => String(c.avatarId) === heroId);
+ const unlocked = entry?.talentIdList ?? [];
+ return {
+ constellation: unlocked.length,
+ unlocked_talent_ids: unlocked,
+ friendship: entry?.fetterInfo?.expLevel ?? null,
+ };
+}
diff --git a/src/index.ts b/src/index.ts
index 43123d1..027525b 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -33,6 +33,9 @@ import type {
UnifiedMinecraftHypixel,
VanillaCapeList,
UnifiedGenshinRoster,
+ UnifiedGenshinCharacterDetail,
+ UnifiedGenshinCharacterItems,
+ UnifiedGenshinCharacterConstellations,
} from "./types";
import { getProfile } from "./profile";
import { GatewayManager } from "./gateway";
@@ -40,7 +43,13 @@ import { getGuildInvite } from "./guild";
import { getGirlsResource, isGirlsIdType } from "./girls";
import { getMinecraftGeneral, getMinecraftHypixel, getVanillaCapeList, normalizeMcUuid, isAllowedHypixelUuid, MojangUpstreamError } from "./minecraft";
import { getContributions } from "./contribapi";
-import { getGenshinRoster, EnkaNotFoundError } from "./genshin";
+import {
+ getGenshinRoster,
+ getGenshinCharacterDetail,
+ getGenshinCharacterItems,
+ getGenshinCharacterConstellations,
+ EnkaNotFoundError,
+} from "./genshin";
import { DOCS_HTML } from "./docs";
import { ABUSE_HTML, ABUSE_CONTACT, securityTxt } from "./abuse";
import { TERMS_HTML, PRIVACY_HTML, NOT_FOUND_HTML } from "./pages";
@@ -406,6 +415,55 @@ export default {
}
}
+ // ---- /v2/genshin/roster/:uid/:heroId (single-character detail) ------
+ // Full detail for one character: level, constellation, friendship,
+ // weapon, artifacts. Same cached Enka fetch as the roster route above —
+ // this never costs an extra upstream call within the ttl window.
+ const gsItems = path.match(/^\/v2\/genshin\/roster\/(\d{1,12})\/(\d{1,10})\/items$/);
+ const gsCons = path.match(/^\/v2\/genshin\/roster\/(\d{1,12})\/(\d{1,10})\/constellations$/);
+ const gsHero = path.match(/^\/v2\/genshin\/roster\/(\d{1,12})\/(\d{1,10})$/);
+ if (gsItems || gsCons || gsHero) {
+ const [, uid, heroId] = (gsItems ?? gsCons ?? gsHero)!;
+ try {
+ if (gsItems) {
+ const data = await getGenshinCharacterItems(env, uid, heroId, ctx, wantsForce(url));
+ if (!data) {
+ return json(
+ { success: false, error: { code: "not_found", message: `No playable character with id ${heroId}` } },
+ 404,
+ );
+ }
+ return json<UnifiedGenshinCharacterItems>({ success: true, data });
+ }
+ if (gsCons) {
+ const data = await getGenshinCharacterConstellations(env, uid, heroId, ctx, wantsForce(url));
+ if (!data) {
+ return json(
+ { success: false, error: { code: "not_found", message: `No playable character with id ${heroId}` } },
+ 404,
+ );
+ }
+ return json<UnifiedGenshinCharacterConstellations>({ success: true, data });
+ }
+ const data = await getGenshinCharacterDetail(env, uid, heroId, ctx, wantsForce(url));
+ if (!data) {
+ return json(
+ { success: false, error: { code: "not_found", message: `No playable character with id ${heroId}` } },
+ 404,
+ );
+ }
+ return json<UnifiedGenshinCharacterDetail>({ success: true, data });
+ } catch (err) {
+ if (err instanceof EnkaNotFoundError) {
+ return json({ success: false, error: { code: "not_found", message: err.message } }, 404);
+ }
+ return json(
+ { success: false, error: { code: "upstream_error", message: (err as Error).message } },
+ 502,
+ );
+ }
+ }
+
// ---- /v2/discord/users/:id (merged profile + presence) --------------
// Profile (REST) + presence (gateway) in parallel — the full user record
// the website's presence cards render from.
diff --git a/src/types.ts b/src/types.ts
index 6890db0..24a5887 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -572,4 +572,79 @@ export interface UnifiedGenshinRoster {
total_count: number;
characters: UnifiedGenshinCharacter[];
updated_at: number;
+}
+
+/** One stat line — a weapon's base stat/substat, or an artifact's main/substat. */
+export interface UnifiedGenshinStat {
+ /** e.g. "CRIT Rate", "ATK%", "Elemental Mastery". */
+ name: string;
+ /** Raw value as Enka reports it — already a percentage number (e.g. 46.6)
+ * for percent stats, not a 0-1 fraction. Pair with `is_percent` to render. */
+ value: number;
+ is_percent: boolean;
+}
+
+export interface UnifiedGenshinWeapon {
+ /** Enka/game itemId, as a string. */
+ id: string;
+ name: string;
+ /** 1-5. */
+ rarity: number;
+ level: number;
+ /** Ascension phase, 0-6. */
+ ascension: number;
+ /** Refinement rank, 1-5. */
+ refinement: number;
+ base_stat: UnifiedGenshinStat | null;
+ sub_stat: UnifiedGenshinStat | null;
+ icon_url: string;
+}
+
+/** Genshin artifact slot, in equip order. */
+export type UnifiedGenshinArtifactSlot =
+ | "flower"
+ | "plume"
+ | "sands"
+ | "goblet"
+ | "circlet";
+
+export interface UnifiedGenshinArtifact {
+ /** Enka/game itemId, as a string. */
+ id: string;
+ name: string;
+ set_name: string;
+ slot: UnifiedGenshinArtifactSlot;
+ /** 1-5. */
+ rarity: number;
+ /** Display level (the "+N" shown in-game), already adjusted for Enka's
+ * off-by-one raw `level` field. */
+ level: number;
+ main_stat: UnifiedGenshinStat | null;
+ sub_stats: UnifiedGenshinStat[];
+ icon_url: string;
+}
+
+/** GET /v2/genshin/roster/:uid/:heroId */
+export interface UnifiedGenshinCharacterDetail extends UnifiedGenshinCharacter {
+ /** 0-6. 0 if not owned or no constellations unlocked. */
+ constellation: number;
+ /** In-game friendship/fetter level, 1-10. Null if not owned. */
+ friendship: number | null;
+ weapon: UnifiedGenshinWeapon | null;
+ artifacts: UnifiedGenshinArtifact[];
+ updated_at: number;
+}
+
+/** GET /v2/genshin/roster/:uid/:heroId/items */
+export interface UnifiedGenshinCharacterItems {
+ weapon: UnifiedGenshinWeapon | null;
+ artifacts: UnifiedGenshinArtifact[];
+}
+
+/** GET /v2/genshin/roster/:uid/:heroId/constellations */
+export interface UnifiedGenshinCharacterConstellations {
+ constellation: number;
+ /** Raw unlocked talent ids from Enka, in unlock order. Length == constellation. */
+ unlocked_talent_ids: number[];
+ friendship: number | null;
}
\ No newline at end of file