Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 13, 2024
1 parent 31d2a18 commit 7fe1f07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion scripts/update-mmdb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const buf = fs.readFileSync('server/geoip/GeoLite2-Country.mmdb');
fs.writeFileSync(
'server/geoip/data.mjs',
`
import * as zlib from 'node:zlib';
// data is brotli compressed GeoLite2-Country.mmdb in base64 format
export const data = "${zlib.brotliCompressSync(buf).toString('base64')}";
export const data = zlib.brotliDecompressSync(Buffer.from('${zlib
.brotliCompressSync(buf)
.toString('base64')}', 'base64'));
`,
);
10 changes: 8 additions & 2 deletions server/geoip/data.mjs

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions server/services/geoip.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as zlib from 'node:zlib';

import {Reader} from '@maxmind/geoip2-node';

import * as data from '../geoip/data.mjs';

const r = Reader.openBuffer(zlib.brotliDecompressSync(Buffer.from(data.data, 'base64')));
const r = Reader.openBuffer(data.data);

export function lookup(s: string): string {
try {
Expand Down

0 comments on commit 7fe1f07

Please sign in to comment.