This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -10,39 +10,49 @@ const CACHE_TTL = 30 * 60 * 1000;
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
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 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 ?? [];
|
||||
}
|
||||
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