Skip to content

Commit

Permalink
clean up hud download a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Aug 5, 2024
1 parent 3ffe86a commit 2a9147d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/endpoints/hudDownloadStat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
let value = ((await this.ctx.storage.get("value")) as number) || 0;
return value;
}

Expand All @@ -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;
Expand Down

0 comments on commit 2a9147d

Please sign in to comment.