diff --git a/lib/geoip.ts b/lib/geoip.ts index 19f79e4..a9d41a0 100644 --- a/lib/geoip.ts +++ b/lib/geoip.ts @@ -1,17 +1,11 @@ import dotenv from "dotenv"; -import maxmind from "maxmind"; -import { - createReadStream, - existsSync, - statSync, - writeFile, - writeFileSync, -} from "fs"; +import { existsSync, statSync, writeFileSync } from "fs"; +import { get } from "https"; import { DateTime } from "luxon"; +import maxmind from "maxmind"; +import { basename } from "path"; import tar from "tar-stream"; import { createGunzip } from "zlib"; -import { get } from "https"; -import { basename } from "path"; dotenv.config(); @@ -59,7 +53,10 @@ export const getCountryForIP = async (ip: string) => { if (existsSync(path)) { const maxAge = DateTime.now().minus({ weeks: 1 }); const lastModified = DateTime.fromJSDate(statSync(path).mtime); - if (lastModified < maxAge) await download(); + if (lastModified < maxAge) { + console.log("Maxmind DB is older than 1 week - redownloading"); + await download(); + } } else { if (!url) { if (!hasLoggedError) { @@ -68,6 +65,7 @@ export const getCountryForIP = async (ip: string) => { } return; } + console.log("Maxmind DB not found - downloading"); await download(); } diff --git a/package.json b/package.json index 219b0fc..f7bd237 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,6 @@ "typescript": "^5.4.5" }, "lint-staged": { - "*.{js,css,md}": "prettier --write" + "*.{js,css,md,ts,tsx}": "prettier --write" } }