mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Compare commits
6 commits
97ebdc1bab
...
9fbcec46af
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fbcec46af | ||
|
|
d98cc35208 | ||
|
|
e13362bfec | ||
|
|
371ff47325 | ||
|
|
a56746ce6d | ||
|
|
678a2ccdf3 |
2 changed files with 75 additions and 26 deletions
|
|
@ -13,12 +13,18 @@ if (process.env.VERCEL && !process.env.BUILD_GEO) {
|
||||||
|
|
||||||
const db = 'GeoLite2-City';
|
const db = 'GeoLite2-City';
|
||||||
|
|
||||||
let url = `https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/${db}.tar.gz`;
|
// Support custom URL via environment variable
|
||||||
|
let url = process.env.GEO_DATABASE_URL;
|
||||||
|
|
||||||
if (process.env.MAXMIND_LICENSE_KEY) {
|
// Fallback to default URLs if not provided
|
||||||
url =
|
if (!url) {
|
||||||
`https://download.maxmind.com/app/geoip_download` +
|
if (process.env.MAXMIND_LICENSE_KEY) {
|
||||||
`?edition_id=${db}&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`;
|
url =
|
||||||
|
`https://download.maxmind.com/app/geoip_download` +
|
||||||
|
`?edition_id=${db}&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`;
|
||||||
|
} else {
|
||||||
|
url = `https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/${db}.tar.gz`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dest = path.resolve(process.cwd(), 'geo');
|
const dest = path.resolve(process.cwd(), 'geo');
|
||||||
|
|
@ -27,30 +33,72 @@ if (!fs.existsSync(dest)) {
|
||||||
fs.mkdirSync(dest);
|
fs.mkdirSync(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
const download = url =>
|
// Check if URL points to a direct .mmdb file (already extracted)
|
||||||
|
const isDirectMmdb = url.endsWith('.mmdb');
|
||||||
|
|
||||||
|
// Download handler for compressed tar.gz files
|
||||||
|
const downloadCompressed = url =>
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
https.get(url, res => {
|
https.get(url, res => {
|
||||||
resolve(res.pipe(zlib.createGunzip({})).pipe(tar.t()));
|
resolve(res.pipe(zlib.createGunzip({})).pipe(tar.t()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
download(url).then(
|
// Download handler for direct .mmdb files
|
||||||
res =>
|
const downloadDirect = (url, originalUrl) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
res.on('entry', entry => {
|
https.get(url, res => {
|
||||||
if (entry.path.endsWith('.mmdb')) {
|
// Follow redirects
|
||||||
const filename = path.join(dest, path.basename(entry.path));
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
entry.pipe(fs.createWriteStream(filename));
|
downloadDirect(res.headers.location, originalUrl || url).then(resolve).catch(reject);
|
||||||
|
return;
|
||||||
console.log('Saved geo database:', filename);
|
}
|
||||||
}
|
|
||||||
});
|
const filename = path.join(dest, path.basename(originalUrl || url));
|
||||||
|
const fileStream = fs.createWriteStream(filename);
|
||||||
res.on('error', e => {
|
|
||||||
reject(e);
|
res.pipe(fileStream);
|
||||||
});
|
|
||||||
res.on('finish', () => {
|
fileStream.on('finish', () => {
|
||||||
|
fileStream.close();
|
||||||
|
console.log('Saved geo database:', filename);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}),
|
|
||||||
);
|
fileStream.on('error', e => {
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Execute download based on file type
|
||||||
|
if (isDirectMmdb) {
|
||||||
|
downloadDirect(url).catch(e => {
|
||||||
|
console.error('Failed to download geo database:', e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
downloadCompressed(url).then(
|
||||||
|
res =>
|
||||||
|
new Promise((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(e => {
|
||||||
|
console.error('Failed to download geo database:', e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,16 @@ export function LoginForm() {
|
||||||
name="username"
|
name="username"
|
||||||
rules={{ required: formatMessage(labels.required) }}
|
rules={{ required: formatMessage(labels.required) }}
|
||||||
>
|
>
|
||||||
<TextField autoComplete="off" />
|
<TextField autoComplete="username" />
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
label={formatMessage(labels.password)}
|
label={formatMessage(labels.password)}
|
||||||
data-test="input-password"
|
data-test="input-password"
|
||||||
name="password"
|
name="password"
|
||||||
rules={{ required: formatMessage(labels.required) }}
|
rules={{ required: formatMessage(labels.required) }}
|
||||||
>
|
>
|
||||||
<PasswordField />
|
<PasswordField autoComplete="current-password" />
|
||||||
</FormField>
|
</FormField>
|
||||||
<FormButtons>
|
<FormButtons>
|
||||||
<FormSubmitButton
|
<FormSubmitButton
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue