mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
feat(geo): add redirect support for direct .mmdb downloads
This commit is contained in:
parent
371ff47325
commit
e13362bfec
1 changed files with 8 additions and 2 deletions
|
|
@ -45,10 +45,16 @@ const downloadCompressed = url =>
|
||||||
});
|
});
|
||||||
|
|
||||||
// Download handler for direct .mmdb files
|
// Download handler for direct .mmdb files
|
||||||
const downloadDirect = url =>
|
const downloadDirect = (url, originalUrl) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
https.get(url, res => {
|
https.get(url, res => {
|
||||||
const filename = path.join(dest, path.basename(url));
|
// Follow redirects
|
||||||
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
|
downloadDirect(res.headers.location, originalUrl || url).then(resolve).catch(reject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = path.join(dest, path.basename(originalUrl || url));
|
||||||
const fileStream = fs.createWriteStream(filename);
|
const fileStream = fs.createWriteStream(filename);
|
||||||
|
|
||||||
res.pipe(fileStream);
|
res.pipe(fileStream);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue