From 43410244e878f96fff0fef21c01f93b4a1e081f5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 17 Jun 2024 18:39:24 +0200 Subject: [PATCH] Cleanup keys --- src/main.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index a62d504..9945eb7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -145,6 +145,16 @@ export class Main { private readonly ipv4: IP2Location private readonly ipv6: IP2Location private readonly boottime = new Date() + private readonly allowedKeys = [ + "latitude", + "longitude", + "region", + "countryLong", + "countryShort", + "ip", + "ipNo" + ] as const + private readonly keysSet = new Set(this.allowedKeys) constructor() { console.log("Loading databases from ./data/") @@ -180,7 +190,13 @@ export class Main { //see : https://github.com/kirsch33/realip/issues/14 const ipAddress = request.headers['x-forwarded-for'] const db = ipAddress.match(Main.ipv4Regex) ? this.ipv4 : this.ipv6 - return db.getAll(ipAddress) + const result = db.getAll(ipAddress) + for (const k in result) { + if (!this.keysSet.has(k)) { + delete result[k] + } + } + return result } }