From 71004e5e79de947639e57f8188d25362fcd83cbe Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Tue, 20 Dec 2022 19:15:36 -0500 Subject: [PATCH] add FISU_USE_PS4EU to fuse off ps4eu fisu jank --- src/handlers.ts | 4 +++- src/index.ts | 1 + src/sources/fisu.ts | 37 ++++++++++++++++++++++++++++--------- src/types.ts | 2 ++ wrangler.toml | 1 + 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/handlers.ts b/src/handlers.ts index b2ebb4f..086ee9d 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -43,7 +43,9 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { }) : defaultServiceResponse, !flags.disableFisu - ? fisuFetchWorld(id, cache).catch(() => defaultServiceResponse) + ? fisuFetchWorld(id, cache, flags.fisuUsePS4EU).catch( + () => defaultServiceResponse + ) : defaultServiceResponse, !flags.disableHonu ? honuFetchWorld(id, cache).catch(() => defaultServiceResponse) diff --git a/src/index.ts b/src/index.ts index 72982c8..3a1237d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ export default { disableSaerro: env.DISABLE_SAERRO === "1", disableVoidwell: env.DISABLE_VOIDWELL === "1", voidwellUsePS4: env.VOIDWELL_USE_PS4 === "1", + fisuUsePS4EU: env.FISU_USE_PS4EU === "1", }; const start = Date.now(); diff --git a/src/sources/fisu.ts b/src/sources/fisu.ts index ab3289d..23a588d 100644 --- a/src/sources/fisu.ts +++ b/src/sources/fisu.ts @@ -14,7 +14,10 @@ interface FisuResponse { >; } -const fisuFetchAllWorlds = async (cache: Cache): Promise => { +const fisuFetchAllWorlds = async ( + cache: Cache, + usePS4EU: boolean +): Promise => { const cached = await cache.get("fisu"); if (cached) { // console.log("FISU data cached", cached); @@ -34,12 +37,14 @@ const fisuFetchAllWorlds = async (cache: Cache): Promise => { console.error("FISU PS4US ERROR", e); return { result: {} } as FisuResponse; }), - fetch(`https://ps4eu.ps2.fisu.pw/api/population/?world=2000`) - .then((res) => res.json()) - .catch((e) => { - console.error("FISU PS4EU ERROR", e); - return { result: {} } as FisuResponse; - }), + usePS4EU + ? fetch(`https://ps4eu.ps2.fisu.pw/api/population/?world=2000`) + .then((res) => res.json()) + .catch((e) => { + console.error("FISU PS4EU ERROR", e); + return { result: {} } as FisuResponse; + }) + : ({ result: {} } as FisuResponse), ]).catch((e) => { console.error("FISU ERROR", e); return [{ result: {} }, { result: {} }, { result: {} }] as FisuResponse[]; @@ -59,10 +64,24 @@ const fisuFetchAllWorlds = async (cache: Cache): Promise => { export const fisuFetchWorld = async ( worldID: string, - cache: Cache + cache: Cache, + usePS4EU: boolean ): Promise> => { + if (!usePS4EU && worldID === "2000") { + return { + population: { + total: -1, + nc: -1, + tr: -1, + vs: -1, + }, + raw: null, + cachedAt: new Date(0), + }; + } + const start = Date.now(); - const data: FisuResponse = await fisuFetchAllWorlds(cache); + const data: FisuResponse = await fisuFetchAllWorlds(cache, usePS4EU); const end = Date.now(); const world = data.result[worldID]; diff --git a/src/types.ts b/src/types.ts index f370749..c7faedc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -24,6 +24,7 @@ export interface Env { DISABLE_VOIDWELL: "1" | undefined; DISABLE_CACHE: "1" | undefined; VOIDWELL_USE_PS4: "1" | undefined; + FISU_USE_PS4EU: "1" | undefined; } export type OnePayload = { @@ -69,4 +70,5 @@ export type Flags = { disableSaerro: boolean; disableVoidwell: boolean; voidwellUsePS4: boolean; + fisuUsePS4EU: boolean; }; diff --git a/wrangler.toml b/wrangler.toml index 238c792..3334206 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -13,6 +13,7 @@ DISABLE_SAERRO = "0" DISABLE_VOIDWELL = "0" DISABLE_CACHE = "0" VOIDWELL_USE_PS4 = "0" +FISU_USE_PS4EU = "0" [[kv_namespaces]] binding = "CACHE"