perf: static file download and catch

This commit is contained in:
ibuler 2025-05-19 14:57:34 +08:00 committed by 老广
parent 1364889083
commit 16e7a12974
3 changed files with 18 additions and 1 deletions

View File

@ -16,6 +16,8 @@ def get_ip_city_by_geoip(ip):
global reader
if reader is None:
path = os.path.join(os.path.dirname(__file__), 'GeoLite2-City.mmdb')
if not os.path.exists(path):
raise FileNotFoundError(f"IP Database not found, please run `./requirements/static_files.sh`")
reader = geoip2.database.Reader(path)
try:

View File

@ -12,6 +12,9 @@ def get_ip_city_by_ipip(ip):
global ipip_db
if ipip_db is None:
ipip_db_path = os.path.join(os.path.dirname(__file__), 'ipipfree.ipdb')
if not os.path.exists(ipip_db_path):
raise FileNotFoundError(
f"IP database not found, please run `bash ./requirements/static_files.sh`")
ipip_db = ipdb.City(ipip_db_path)
try:
info = ipip_db.find_info(ip, 'CN')

View File

@ -18,13 +18,19 @@ fi
for file in $to_files; do
# Check if the file already exists
file_path="${BASE_DIR}/$file"
rm -f $file_path
if [ -f "$file_path" ]; then
echo "File $file already exists, skipping download."
continue
fi
filename=$(basename "$file")
static_path="$BASE_DIR/data/static/$filename"
if [[ "$1" == "static" && -f "$static_path" ]]; then
echo "File $file already exists in static path, copy it."
cp -f "$static_path" "$file_path"
continue
fi
to_dir=$(dirname "$file_path")
if [ ! -d "$to_dir" ]; then
mkdir -p "$to_dir"
@ -32,5 +38,11 @@ for file in $to_files; do
url=""https://github.com/jumpserver/static/releases/download/${VERSION}/$filename""
echo "Download $filename to $file_path"
wget "$url" -O "${file_path}"
if [[ "$1" == "static" ]];then
# Copy the file to the static directory
echo "Copy to static"
cp -f "$file_path" "$static_path"
fi
done