diff --git a/src/handlers.ts b/src/handlers.ts index 29c1fa3..b2ebb4f 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -49,7 +49,9 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { ? honuFetchWorld(id, cache).catch(() => defaultServiceResponse) : defaultServiceResponse, !flags.disableVoidwell - ? voidwellFetchWorld(id, cache).catch(() => defaultServiceResponse) + ? voidwellFetchWorld(id, cache, flags.voidwellUsePS4).catch( + () => defaultServiceResponse + ) : defaultServiceResponse, ]); diff --git a/src/index.ts b/src/index.ts index 182d297..72982c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,6 +34,7 @@ export default { disableHonu: env.DISABLE_HONU === "1", disableSaerro: env.DISABLE_SAERRO === "1", disableVoidwell: env.DISABLE_VOIDWELL === "1", + voidwellUsePS4: env.VOIDWELL_USE_PS4 === "1", }; const start = Date.now(); diff --git a/src/sources/voidwell.ts b/src/sources/voidwell.ts index 375d412..978033b 100644 --- a/src/sources/voidwell.ts +++ b/src/sources/voidwell.ts @@ -26,7 +26,8 @@ type VoidwellResponse = Array<{ }>; const voidwellFetchAllWorlds = async ( - cache: Cache + cache: Cache, + usePS4: boolean ): Promise => { const cached = await cache.get("voidwell"); if (cached) { @@ -40,18 +41,22 @@ const voidwellFetchAllWorlds = async ( console.error("voidwell PC ERROR", e); return [] as VoidwellResponse; }), - fetch(`https://api.voidwell.com/ps2/worldstate/?platform=ps4us`) - .then((res) => res.json()) - .catch((e) => { - console.error("voidwell PS4US ERROR", e); - return [] as VoidwellResponse; - }), - fetch(`https://api.voidwell.com/ps2/worldstate/?platform=ps4eu`) - .then((res) => res.json()) - .catch((e) => { - console.error("voidwell PS4EU ERROR", e); - return [] as VoidwellResponse; - }), + usePS4 + ? fetch(`https://api.voidwell.com/ps2/worldstate/?platform=ps4us`) + .then((res) => res.json()) + .catch((e) => { + console.error("voidwell PS4US ERROR", e); + return [] as VoidwellResponse; + }) + : [], + usePS4 + ? fetch(`https://api.voidwell.com/ps2/worldstate/?platform=ps4eu`) + .then((res) => res.json()) + .catch((e) => { + console.error("voidwell PS4EU ERROR", e); + return [] as VoidwellResponse; + }) + : [], ]); // console.log("voidwell data fetched", JSON.stringify({ pc, ps4us, ps4eu })); @@ -68,10 +73,25 @@ const voidwellFetchAllWorlds = async ( // we're stuck with not counting faction populations. export const voidwellFetchWorld = async ( worldID: string, - cache: Cache -): Promise> => { + cache: Cache, + usePS4: boolean +): Promise> => { + if (!usePS4 && (worldID === "1000" || worldID === "2000")) { + // Voidwell doesn't support PS4 well enough. + return { + raw: null, + population: { + total: -1, + nc: undefined, + tr: undefined, + vs: undefined, + }, + cachedAt: new Date(0), + }; + } + const start = Date.now(); - const data = await voidwellFetchAllWorlds(cache); + const data = await voidwellFetchAllWorlds(cache, usePS4); const end = Date.now(); const world = data.find((w) => w.id === Number(worldID)); diff --git a/src/types.ts b/src/types.ts index 6d2452d..f370749 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,7 @@ export interface Env { DISABLE_SAERRO: "1" | undefined; DISABLE_VOIDWELL: "1" | undefined; DISABLE_CACHE: "1" | undefined; + VOIDWELL_USE_PS4: "1" | undefined; } export type OnePayload = { @@ -67,4 +68,5 @@ export type Flags = { disableFisu: boolean; disableSaerro: boolean; disableVoidwell: boolean; + voidwellUsePS4: boolean; }; diff --git a/wrangler.toml b/wrangler.toml index 3c394b4..238c792 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,6 +12,7 @@ DISABLE_FISU = "0" DISABLE_SAERRO = "0" DISABLE_VOIDWELL = "0" DISABLE_CACHE = "0" +VOIDWELL_USE_PS4 = "0" [[kv_namespaces]] binding = "CACHE"