- env.ts: added 10 missing Zod-validated env vars (imager, paypal currency, argon2/bcrypt params) - Migrated 6 modules from process.env to validated env.* (auth, proxy-auth, paypal, password, redis, imager, moderation, alert, logger) - Replaced console.warn/error with pino logger in 9 server-side modules - Removed 50+ dead exports (SWF wrappers, coalesceHotelName, signIn, isStaff re-export, formatTimestamp, Skeleton/SkeletonCard, 4 unused housekeeping sections) - Consolidated date formatting: 28 files migrated to shared formatDate() from @/lib/format-date - Wired 4 radio/settings API routes through cached siteSettings service instead of raw Prisma queries - Added getMany()/getAll() helpers to SiteSettings service - Removed 88 dead Prisma model definitions (schema 2763→1846 lines) - Created admin action-helper.ts with wrapAction() for standardized error handling - Fixed useEffect dependency arrays in 4 data-heavy components - Replaced raw btn CSS classes with shadcn Button component across admin pages - Stripped dead i18n namespaces (common, pages.client) from all 22 translation files - Removed 2 dead scripts (create-release.sh, check-local-imports.ts) - Fixed knip.json configuration - Added 7 new test suites: format-date, paypal, moderation, alert, webhook, action-helper, and fixed password.test.ts for env mocking - All 358 tests passing across 72 test files - TypeScript: 0 errors
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { logger } from "@/lib/logger";
|
|
import { resolveGordonBuildUrl } from "@/lib/services/import/core/gordon";
|
|
import { siteSettings } from "@/lib/services/site-settings";
|
|
import type { EffectMapEntry } from "@/types/effects";
|
|
|
|
// Defaults to VALIDATE against a live fetch (spec Open Item #2). Override the
|
|
// SWF source with the `effect_swf_base_url` site setting if these drift.
|
|
const OFFICIAL_EFFECTMAP_URL = "https://www.habbo.com/gamedata/effectmap/1";
|
|
const CACHE_TTL = 30 * 60 * 1000;
|
|
|
|
let effectCache: { list: EffectMapEntry[]; ts: number } | null = null;
|
|
|
|
export function __clearEffectSourceCache(): void {
|
|
effectCache = null;
|
|
}
|
|
|
|
function parseEffectMapXml(xml: string): EffectMapEntry[] {
|
|
const out: EffectMapEntry[] = [];
|
|
const re = /<effect\b([^>]*)\/?>/g;
|
|
for (const m of xml.matchAll(re)) {
|
|
const attrs = m[1];
|
|
const id = /\bid="([^"]*)"/.exec(attrs)?.[1];
|
|
const lib = /\blib="([^"]*)"/.exec(attrs)?.[1];
|
|
const type = /\btype="([^"]*)"/.exec(attrs)?.[1] ?? "fx";
|
|
const revision = Number(/\brevision="([^"]*)"/.exec(attrs)?.[1] ?? "0");
|
|
if (id && lib)
|
|
out.push({
|
|
id,
|
|
lib,
|
|
type,
|
|
revision: Number.isFinite(revision) ? revision : 0,
|
|
});
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export async function listOfficialEffects(): Promise<EffectMapEntry[]> {
|
|
const now = Date.now();
|
|
if (effectCache && now - effectCache.ts < CACHE_TTL) return effectCache.list;
|
|
const res = await fetch(OFFICIAL_EFFECTMAP_URL, {
|
|
signal: AbortSignal.timeout(20000),
|
|
});
|
|
if (!res.ok) {
|
|
logger.warn(`[effect-source] effectmap fetch failed: ${res.status}`);
|
|
return effectCache?.list ?? [];
|
|
}
|
|
const list = parseEffectMapXml(await res.text());
|
|
effectCache = { list, ts: now };
|
|
return list;
|
|
}
|
|
|
|
export async function resolveEffectSwfUrl(lib: string): Promise<string> {
|
|
const override = (
|
|
(await siteSettings.get("effect_swf_base_url", "")) ?? ""
|
|
).trim();
|
|
if (override) return `${override.replace(/\/+$/, "")}/${lib}.swf`;
|
|
const gordon = await resolveGordonBuildUrl();
|
|
return `${gordon}${lib}.swf`;
|
|
}
|