mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-07 12:06:56 +03:00
refactor: Add download helper functions to helpers.sh and remove from main script
This commit is contained in:
@@ -2026,38 +2026,6 @@ global_check() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: create helper functon
|
|
||||||
# Download URL content directly
|
|
||||||
download_to_stream() {
|
|
||||||
local url="$1"
|
|
||||||
|
|
||||||
config_get_bool detour "main" "detour" "0"
|
|
||||||
if [ "$detour" -eq 1 ]; then
|
|
||||||
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -qO- "$url" | sed 's/\r$//'
|
|
||||||
else
|
|
||||||
wget -qO- "$url" | sed 's/\r$//'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO: create helper functon
|
|
||||||
# Download URL to temporary file
|
|
||||||
download_to_tempfile() {
|
|
||||||
local url="$1"
|
|
||||||
local filepath="$2"
|
|
||||||
|
|
||||||
config_get_bool detour "main" "detour" "0"
|
|
||||||
if [ "$detour" -eq 1 ]; then
|
|
||||||
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -O "$filepath" "$url"
|
|
||||||
else
|
|
||||||
wget -O "$filepath" "$url"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if grep -q $'\r' "$filepath"; then
|
|
||||||
log "$filename has Windows line endings (CRLF). Converting to Unix (LF)"
|
|
||||||
sed -i 's/\r$//' "$filepath"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: $0 COMMAND
|
Usage: $0 COMMAND
|
||||||
|
|||||||
@@ -176,3 +176,33 @@ migrate_config_key() {
|
|||||||
sed -i "s/$key_type $old_key_name/$key_type $new_key_name/g" "$config"
|
sed -i "s/$key_type $old_key_name/$key_type $new_key_name/g" "$config"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Download URL content directly
|
||||||
|
download_to_stream() {
|
||||||
|
local url="$1"
|
||||||
|
local http_proxy_url="${2}"
|
||||||
|
|
||||||
|
if [ -n "$http_proxy_url" ]; then
|
||||||
|
http_proxy="$http_proxy_url" https_proxy="$http_proxy_url" wget -qO- "$url" | sed 's/\r$//'
|
||||||
|
else
|
||||||
|
wget -qO- "$url" | sed 's/\r$//'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download URL to temporary file
|
||||||
|
download_to_tempfile() {
|
||||||
|
local url="$1"
|
||||||
|
local filepath="$2"
|
||||||
|
local http_proxy_url="${3}"
|
||||||
|
|
||||||
|
if [ -n "$http_proxy_url" ]; then
|
||||||
|
http_proxy="$http_proxy_url" https_proxy="$http_proxy_url" wget -O "$filepath" "$url"
|
||||||
|
else
|
||||||
|
wget -O "$filepath" "$url"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q $'\r' "$filepath"; then
|
||||||
|
log "$filename has Windows line endings (CRLF). Converting to Unix (LF)"
|
||||||
|
sed -i 's/\r$//' "$filepath"
|
||||||
|
fi
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user