From 3889e5fe08ac24b6538c53ddb5d45490e229c7a0 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Thu, 22 Dec 2022 16:19:11 -0500 Subject: [PATCH] mulligan, no kiwi --- README.md | 1 - src/fetcher.ts | 10 +----- src/index.ts | 11 ++---- src/landing.ts | 12 ++----- src/sources/kiwi.ts | 82 --------------------------------------------- src/types.ts | 6 ---- 6 files changed, 7 insertions(+), 115 deletions(-) delete mode 100644 src/sources/kiwi.ts diff --git a/README.md b/README.md index 8da2a74..4b84460 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ A Planetside 2 population aggreggation API between - https://wt.honu.pw - https://saerro.ps2.live - https://voidwell.com -- https://ps2.nice.kiwi Has some jank filters and will average between all 4 sources with as much data as can be used. diff --git a/src/fetcher.ts b/src/fetcher.ts index 22c6809..592d8c6 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -34,7 +34,7 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { return cached; } - const [saerro, fisu, honu, voidwell, kiwi] = await Promise.all([ + const [saerro, fisu, honu, voidwell] = await Promise.all([ !flags.disableSaerro ? saerroFetchWorld(id, cache).catch((e) => { console.error("SAERRO ERROR:", e); @@ -54,9 +54,6 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { () => defaultServiceResponse ) : defaultServiceResponse, - !flags.disableKiwi - ? kiwiFetchWorld(id, cache).catch(() => defaultServiceResponse) - : defaultServiceResponse, ]); const debug: DebugPayload = { @@ -65,21 +62,18 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { fisu: fisu.raw, honu: honu.raw, voidwell: voidwell.raw, - kiwi: kiwi.raw, }, timings: { saerro: saerro?.timings || null, fisu: fisu?.timings || null, honu: honu?.timings || null, voidwell: voidwell?.timings || null, - kiwi: kiwi?.timings || null, }, lastFetchTimes: { saerro: saerro.cachedAt, fisu: fisu.cachedAt, honu: honu.cachedAt, voidwell: voidwell.cachedAt, - kiwi: kiwi.cachedAt, }, }; @@ -88,7 +82,6 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { fisu.population.total, honu.population.total, voidwell.population.total, - kiwi.population.total, ].filter((x) => x > 0); if (totalPopulations.length === 0) { @@ -135,7 +128,6 @@ export const getWorld = async (id: string, cache: Cache, flags: Flags) => { fisu: fisu.population.total, honu: honu.population.total, voidwell: voidwell.population.total, - kiwi: kiwi.population.total, }, }; diff --git a/src/index.ts b/src/index.ts index 1a69b57..8a5c2a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,14 +35,11 @@ router } ) .get("/population~/health", async () => { - const [saerro, voidwell, honu, fisu, kiwi] = await Promise.all([ + const [saerro, voidwell, honu, fisu] = await Promise.all([ fetch("https://saerro.ps2.live/health").then((r) => r.status === 200), fetch("https://voidwell.com/").then((r) => r.status === 200), fetch("https://wt.honu.pw/api/health").then((r) => r.status === 200), fetch("https://ps2.fisu.pw").then((r) => r.status === 200), - fetch("https://planetside-2-api.herokuapp.com").then( - (r) => r.status === 200 - ), ]); return new Response( @@ -51,11 +48,10 @@ router voidwell, honu, fisu, - kiwi, }), { headers: { "content-type": "application/json" }, - status: saerro || voidwell || honu || fisu || kiwi ? 200 : 502, + status: saerro || voidwell || honu || fisu ? 200 : 502, } ); }) @@ -74,9 +70,8 @@ export default { disableHonu: env.DISABLE_HONU === "1", disableSaerro: env.DISABLE_SAERRO === "1", disableVoidwell: env.DISABLE_VOIDWELL === "1", - disableKiwi: env.DISABLE_KIWI === "1", voidwellUsePS4: env.VOIDWELL_USE_PS4 === "1", - fisuUsePS4EU: env.FISU_USE_PS4EU === "1", + fisuUsePS4EU: true, // env.FISU_USE_PS4EU === "1", }; const start = Date.now(); diff --git a/src/landing.ts b/src/landing.ts index 7876a84..8e1f964 100644 --- a/src/landing.ts +++ b/src/landing.ts @@ -13,7 +13,6 @@ This service aggregates the population data from the following sources: - https://ps2.fisu.pw/ - https://wt.honu.pw/ - https://voidwell.com/ (caveat: no factions, non-standard counting method) -- https://ps2.nice.kiwi/ ## Routes @@ -31,8 +30,7 @@ GET /:id - Get one world by ID "saerro": 282, "fisu": 271, "honu": 292, - "voidwell": 298, - "kiwi": 281 + "voidwell": 298 } } @@ -46,14 +44,12 @@ GET /:id - Get one world by ID "fisu": { ... }, "honu": { ... }, "voidwell": { ... } - "kiwi": { ... } }, "lastFetchTimes": { "saerro": "2020-10-10T00:00:00.000Z", "fisu": "2020-10-10T00:00:00.000Z", "honu": "2020-10-10T00:00:00.000Z", "voidwell": "2020-10-10T00:00:00.000Z" - "kiwi": "2020-10-10T00:00:00.000Z" } } @@ -72,8 +68,7 @@ GET /all - Get all worlds "saerro": 282, "fisu": 271, "honu": 292, - "voidwell": 298, - "kiwi": 281 + "voidwell": 298 } }, { @@ -88,8 +83,7 @@ GET /all - Get all worlds "saerro": 95, "fisu": 48, "honu": 91, - "voidwell": 99, - "kiwi": 97 + "voidwell": 99 } } ] diff --git a/src/sources/kiwi.ts b/src/sources/kiwi.ts deleted file mode 100644 index 3174026..0000000 --- a/src/sources/kiwi.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { Cache } from "../cache"; -import { ServiceResponse } from "../types"; - -type KiwiResponse = { - worldId: number; - stats: { - population: { - nc: number; - tr: number; - vs: number; - total: number; - }; - }; -}[]; - -const kiwiFetchAllWorlds = async (cache: Cache): Promise => { - return new Promise(async (resolve, reject) => { - const cached = await cache.get("kiwi"); - if (cached) { - return cached; - } - let resp = await fetch( - "https://planetside-2-api.herokuapp.com/socket.io/?EIO=3&transport=websocket", - { - headers: { - Upgrade: "websocket", - Origin: "https://ps2.nice.kiwi", - }, - } - ); - const ws = resp.webSocket; - if (!ws) { - throw new Error("kiwi: No websocket"); - } - - ws.accept(); - - ws.addEventListener("message", async (e) => { - let payload = e.data as string; - if (payload.startsWith("42")) { - ws.close(); - - const [, data]: [string, KiwiResponse] = JSON.parse(payload.slice(2)); - await cache.put("kiwi", data); - resolve(data); - } - }); - - ws.send(`42["worlds-update-request"]`); - }); -}; - -export const kiwiFetchWorld = async ( - worldID: string, - cache: Cache -): Promise> => { - const start = Date.now(); - const resp = await kiwiFetchAllWorlds(cache); - const end = Date.now(); - - const data = resp.find((w) => w.worldId === Number(worldID)); - - if (!data) { - throw new Error(`kiwi: World ${worldID} not found`); - } - - return { - population: { - total: data.stats.population.total, - nc: data.stats.population.nc, - tr: data.stats.population.tr, - vs: data.stats.population.vs, - }, - raw: data, - cachedAt: new Date(), - timings: { - enter: start, - exit: end, - upstream: end - start, - }, - }; -}; diff --git a/src/types.ts b/src/types.ts index b8c0c99..c7faedc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,7 +22,6 @@ export interface Env { DISABLE_FISU: "1" | undefined; DISABLE_SAERRO: "1" | undefined; DISABLE_VOIDWELL: "1" | undefined; - DISABLE_KIWI: "1" | undefined; DISABLE_CACHE: "1" | undefined; VOIDWELL_USE_PS4: "1" | undefined; FISU_USE_PS4EU: "1" | undefined; @@ -41,7 +40,6 @@ export type OnePayload = { fisu: number | null; honu: number | null; voidwell: number | null; - kiwi: number | null; }; }; @@ -51,21 +49,18 @@ export type DebugPayload = { fisu: any; honu: any; voidwell: any; - kiwi: any; }; timings: { saerro: any; fisu: any; honu: any; voidwell: any; - kiwi: any; }; lastFetchTimes: { saerro?: Date; fisu?: Date; honu?: Date; voidwell?: Date; - kiwi?: Date; }; }; @@ -74,7 +69,6 @@ export type Flags = { disableFisu: boolean; disableSaerro: boolean; disableVoidwell: boolean; - disableKiwi: boolean; voidwellUsePS4: boolean; fisuUsePS4EU: boolean; };