fix url uploads, clarify the purpose of --max-filesize

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
2026-11-28 01:01:34 +00:00
parent 0c13f8bd8b
commit 6fdee2ab73
+12 -16
View File
@@ -37,7 +37,7 @@ usage() {
-u|--shorten <URL> # Generate a shortlink from URL.
-S|--short-url # Get a shortlink when uploading a file.
-P|--page-url # Get a link to the file page instead of a direct one.
-m|--max-filesize <num>[suf] # Maximum filesize (takes K, M and G suffixes).
-m|--max-filesize <num>[suf] # Maximum file size to download when uploading by url (takes K, M and G suffixes).
-a|--album-id # Add the file to an album.
-A|--album-name # Add the file to an album by name. The album will be created, if necessary.
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
@@ -52,7 +52,7 @@ usage() {
Config options (~/.config/ufw):
secret # Your personal token. Get it at https://8fw.me/settings_form
cfg_max_filesize # Maximum filesize (takes K, M and G suffixes).
cfg_max_filesize # Maximum size of file to download when uploading by url (takes K, M and G suffixes).
# Others are self-explanatory:
cfg_url_regex
cfg_tmp_dir
@@ -111,11 +111,12 @@ upload() {
target="$1"
if is_url "$target"; then
flag_rm=1
file=$(_mktemp "$cfg_tmp_dir")
get_max_filesize || { return 1; }
get_max_filesize || return 1
curl --max-filesize "$max_filesize_bytes" "$target" > "$file"
curl_result=$?
@@ -131,8 +132,13 @@ upload() {
else
file="$target"
[[ -f "$file" ]] || {
err "No such file: ${file}"
[[ -s "$file" ]] || {
if [[ -f "$file" ]]; then
err "File is empty: ${file}"
else
err "File does not exist: ${file}"
fi
return 1
}
fi
@@ -460,17 +466,7 @@ main() {
fi
for t in "${args[@]}"; do
if [[ -s "$t" ]]; then
upload "$t" || return $?
else
if [[ -f "$t" ]]; then
err "$t is empty"
return 1
else
err "$t not found"
return 1
fi
fi
upload "$t" || return $?
done
;;