[management] Auto update geolite (#2297)

introduces helper functions to fetch and verify database versions, downloads new files if outdated, and deletes old ones. It also refactors filename handling to improve clarity and consistency, adding options to disable auto-updating via a flag. The changes aim to simplify GeoLite database management for admins.
This commit is contained in:
benniekiss
2024-09-09 12:27:42 -04:00
committed by GitHub
parent c720d54de6
commit 12c36312b5
14 changed files with 199 additions and 334 deletions

View File

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"mime"
"net/http"
"os"
"path"
@ -174,3 +175,21 @@ func downloadFile(url, filepath string) error {
_, err = io.Copy(out, bytes.NewBuffer(bodyBytes))
return err
}
func getFilenameFromURL(url string) (string, error) {
resp, err := http.Head(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
_, params, err := mime.ParseMediaType(resp.Header["Content-Disposition"][0])
if err != nil {
return "", err
}
filename := params["filename"]
return filename, nil
}