revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s
Local Build and Deploy / deploy (push) Successful in 1m11s
revert style: clean up code with prettier and eslint
This commit is contained in:
1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
@@ -1,48 +1,48 @@
|
||||
import { resolveGordonBuildUrl } from "@/lib/services/import/core/gordon";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
import type { EffectMapEntry } from "@/types/effects";
|
||||
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;
|
||||
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;
|
||||
let effectCache: { list: EffectMapEntry[]; ts: number } | null = null
|
||||
|
||||
export function __clearEffectSourceCache(): void {
|
||||
effectCache = null;
|
||||
effectCache = null
|
||||
}
|
||||
|
||||
function parseEffectMapXml(xml: string): EffectMapEntry[] {
|
||||
const out: EffectMapEntry[] = [];
|
||||
const re = /<effect\b([^>]*)\/?>/g;
|
||||
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 });
|
||||
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;
|
||||
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) });
|
||||
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) {
|
||||
console.warn(`[effect-source] effectmap fetch failed: ${res.status}`);
|
||||
return effectCache?.list ?? [];
|
||||
console.warn(`[effect-source] effectmap fetch failed: ${res.status}`)
|
||||
return effectCache?.list ?? []
|
||||
}
|
||||
const list = parseEffectMapXml(await res.text());
|
||||
effectCache = { list, ts: now };
|
||||
return 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`;
|
||||
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`
|
||||
}
|
||||
Reference in new issue
Block a user