-
Notifications
You must be signed in to change notification settings - Fork 35
/
update.js
31 lines (28 loc) · 910 Bytes
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const fs = require('fs');
const maxmind = require('maxmind');
let path;
import('geolite2-redist').then(geolite2 => {
return geolite2.open('GeoLite2-Country', dbPath => {
path = dbPath;
return maxmind.open(dbPath);
});
}).then(reader => {
fs.stat(path, async (err, s) => {
if (err) {
console.error(err);
reader.close();
}
if (s.size > 2 * 1024 * 1024) {
const stream = fs.createReadStream(path);
console.log('Updating GeoLite2-Country.db');
await stream.pipe(fs.createWriteStream('v2/country-flags/firefox/data/assets/GeoLite2-Country.db'));
await stream.pipe(fs.createWriteStream('v3/country-flags/data/assets/GeoLite2-Country.db'));
await stream.pipe(fs.createWriteStream('v3/server-ip/data/assets/GeoLite2-Country.db'));
reader.close();
}
else {
console.error('FILE_TOO_SMALL');
reader.close();
}
});
});