Skip to content

Commit

Permalink
Add more logging as to why the Maxmind database keeps downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
statico committed May 12, 2024
1 parent 5bbb439 commit ea16aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions lib/geoip.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -68,6 +65,7 @@ export const getCountryForIP = async (ip: string) => {
}
return;
}
console.log("Maxmind DB not found - downloading");
await download();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
"typescript": "^5.4.5"
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
"*.{js,css,md,ts,tsx}": "prettier --write"
}
}

0 comments on commit ea16aa8

Please sign in to comment.