* esm * wip * wip * wip * wip * wip * wip * subscription notice * wip * wip * wip * fix envs * fix: update docker build * fix * esm/types * delete dashboard :D * add patches to dockerfiles * update packages + catalogs + ts * wip * remove native libs * ts * improvements * fix redirects and fetching session * try fix favicon * fixes * fix * order and resize reportds within a dashboard * improvements * wip * added userjot to dashboard * fix * add op * wip * different cache key * improve date picker * fix table * event details loading * redo onboarding completely * fix login * fix * fix * extend session, billing and improve bars * fix * reduce price on 10M
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import fs from 'node:fs';
|
|
import https from 'node:https';
|
|
import path from 'node:path';
|
|
import { dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
import zlib from 'node:zlib';
|
|
import * as tar from 'tar';
|
|
import type { Parser } from 'tar';
|
|
|
|
const db = 'GeoLite2-City';
|
|
|
|
const download = async (url: string): Promise<Parser> => {
|
|
return new Promise((resolve) => {
|
|
https.get(url, (res) => {
|
|
const gunzip = zlib.createGunzip();
|
|
const parser = tar.t();
|
|
|
|
res.pipe(gunzip).pipe(parser as any);
|
|
resolve(parser);
|
|
});
|
|
});
|
|
};
|
|
|
|
async function main(): Promise<void> {
|
|
let url = `https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/${db}.tar.gz`;
|
|
|
|
if (process.env.MAXMIND_LICENSE_KEY) {
|
|
url = [
|
|
'https://download.maxmind.com/app/geoip_download',
|
|
`?edition_id=${db}&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`,
|
|
].join('');
|
|
}
|
|
|
|
const dest = path.resolve(__dirname, '../');
|
|
|
|
if (!fs.existsSync(dest)) {
|
|
console.log('Geo database not found');
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
const res = await download(url);
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
res.on('entry', (entry) => {
|
|
if (entry.path.endsWith('.mmdb')) {
|
|
const filename = path.join(dest, path.basename(entry.path));
|
|
entry.pipe(fs.createWriteStream(filename));
|
|
|
|
console.log('Saved geo database:', filename);
|
|
}
|
|
});
|
|
|
|
res.on('error', (e) => {
|
|
reject(e);
|
|
});
|
|
|
|
res.on('finish', () => {
|
|
resolve();
|
|
});
|
|
});
|
|
} catch (error) {
|
|
console.error('Error downloading geo database:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|