From 2a9147d6451351059c0b964373d7eb1a8e134db4 Mon Sep 17 00:00:00 2001 From: mastercoms Date: Mon, 5 Aug 2024 10:49:48 -0400 Subject: [PATCH] clean up hud download a little bit --- src/endpoints/hudDownloadStat.ts | 2 +- src/index.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/endpoints/hudDownloadStat.ts b/src/endpoints/hudDownloadStat.ts index 3e13782..e0eaa91 100644 --- a/src/endpoints/hudDownloadStat.ts +++ b/src/endpoints/hudDownloadStat.ts @@ -40,7 +40,7 @@ export class HudDownloadStat extends OpenAPIRoute { request.headers.get("CF-Connecting-IP") || request.headers.get("X-Real-Ip") || (env.DEV && "127.0.0.1"); - if (rawIp === null) { + if (!rawIp) { return { success: false, }; diff --git a/src/index.ts b/src/index.ts index 7161b51..cad6638 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,8 +58,8 @@ router.all("*", () => export class HudDownloadCounter extends DurableObject { static milliseconds_per_request = 86400000; - async getCounterValue() { - let value = (await this.ctx.storage.get("value")) || 0; + async getCounterValue(): Promise { + let value = ((await this.ctx.storage.get("value")) as number) || 0; return value; } @@ -78,7 +78,8 @@ export class HudDownloadCounter extends DurableObject { } knownIpBlocks[ip] = now; await this.ctx.storage.put("known", knownIpBlocks); - let value: number = await this.getCounterValue(); + // avoids call to getCounterValue() + let value = ((await this.ctx.storage.get("value")) as number) || 0; value += 1; await this.ctx.storage.put("value", value); return true;