improve voidwell PS4 supported-ness, add VOIDWELL_USE_PS4 flag
This commit is contained in:
parent
715e367137
commit
0b317704cc
5 changed files with 43 additions and 17 deletions
|
@ -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,
|
||||
]);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -26,7 +26,8 @@ type VoidwellResponse = Array<{
|
|||
}>;
|
||||
|
||||
const voidwellFetchAllWorlds = async (
|
||||
cache: Cache
|
||||
cache: Cache,
|
||||
usePS4: boolean
|
||||
): Promise<VoidwellResponse> => {
|
||||
const cached = await cache.get<VoidwellResponse>("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<VoidwellResponse>())
|
||||
.catch((e) => {
|
||||
console.error("voidwell PS4US ERROR", e);
|
||||
return [] as VoidwellResponse;
|
||||
}),
|
||||
fetch(`https://api.voidwell.com/ps2/worldstate/?platform=ps4eu`)
|
||||
.then((res) => res.json<VoidwellResponse>())
|
||||
.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<VoidwellResponse>())
|
||||
.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<VoidwellResponse>())
|
||||
.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<ServiceResponse<undefined, VoidwellResponse[0]>> => {
|
||||
cache: Cache,
|
||||
usePS4: boolean
|
||||
): Promise<ServiceResponse<undefined, VoidwellResponse[0] | null>> => {
|
||||
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));
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ DISABLE_FISU = "0"
|
|||
DISABLE_SAERRO = "0"
|
||||
DISABLE_VOIDWELL = "0"
|
||||
DISABLE_CACHE = "0"
|
||||
VOIDWELL_USE_PS4 = "0"
|
||||
|
||||
[[kv_namespaces]]
|
||||
binding = "CACHE"
|
||||
|
|
Loading…
Add table
Reference in a new issue