feat(geo): add redirect support for direct .mmdb downloads

This commit is contained in:
Mintimate 2025-11-12 19:18:44 +08:00
parent 371ff47325
commit e13362bfec

View file

@ -45,10 +45,16 @@ const downloadCompressed = url =>
});
// Download handler for direct .mmdb files
const downloadDirect = url =>
const downloadDirect = (url, originalUrl) =>
new Promise((resolve, reject) => {
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);
res.pipe(fileStream);