// Resolución server-side de una entidad de wowhead (nombre, calidad, icono) en la // rama WotLK y en un idioma concreto, usando el endpoint de tooltip de wowhead (el // mismo que consume tooltips.js). Cacheado un día: nombres/calidades no cambian. export const WOWHEAD_ENTITY_TYPES = ['item', 'spell', 'quest', 'npc', 'achievement', 'object'] as const export type WowheadEntityType = (typeof WOWHEAD_ENTITY_TYPES)[number] // Código de locale de wowhead: 0 = inglés, 6 = español. const WH_LOCALE: Record = { es: 6, en: 0 } export interface WowheadInfo { name: string | null quality: number | null icon: string | null } export async function fetchWowheadInfo( type: string, id: string | number, locale: string, ): Promise { const cleanId = String(id).replace(/\D/g, '') if (!WOWHEAD_ENTITY_TYPES.includes(type as WowheadEntityType) || !cleanId) return null const wl = WH_LOCALE[locale] ?? 0 try { const r = await fetch(`https://nether.wowhead.com/tooltip/${type}/${cleanId}?dataEnv=8&locale=${wl}`, { next: { revalidate: 86400 }, }) if (!r.ok) return null const d = (await r.json()) as { name?: string; quality?: number; icon?: string } return { name: d.name ?? null, quality: typeof d.quality === 'number' ? d.quality : null, icon: d.icon ?? null, } } catch { return null } }