fix url uploads, clarify the purpose of --max-filesize
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
@@ -37,7 +37,7 @@ usage() {
|
|||||||
-u|--shorten <URL> # Generate a shortlink from URL.
|
-u|--shorten <URL> # Generate a shortlink from URL.
|
||||||
-S|--short-url # Get a shortlink when uploading a file.
|
-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.
|
-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-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.
|
-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.
|
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
|
||||||
@@ -52,7 +52,7 @@ usage() {
|
|||||||
|
|
||||||
Config options (~/.config/ufw):
|
Config options (~/.config/ufw):
|
||||||
secret # Your personal token. Get it at https://8fw.me/settings_form
|
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:
|
# Others are self-explanatory:
|
||||||
cfg_url_regex
|
cfg_url_regex
|
||||||
cfg_tmp_dir
|
cfg_tmp_dir
|
||||||
@@ -111,11 +111,12 @@ upload() {
|
|||||||
|
|
||||||
target="$1"
|
target="$1"
|
||||||
|
|
||||||
|
|
||||||
if is_url "$target"; then
|
if is_url "$target"; then
|
||||||
flag_rm=1
|
flag_rm=1
|
||||||
file=$(_mktemp "$cfg_tmp_dir")
|
file=$(_mktemp "$cfg_tmp_dir")
|
||||||
|
|
||||||
get_max_filesize || { return 1; }
|
get_max_filesize || return 1
|
||||||
|
|
||||||
curl --max-filesize "$max_filesize_bytes" "$target" > "$file"
|
curl --max-filesize "$max_filesize_bytes" "$target" > "$file"
|
||||||
curl_result=$?
|
curl_result=$?
|
||||||
@@ -131,8 +132,13 @@ upload() {
|
|||||||
else
|
else
|
||||||
file="$target"
|
file="$target"
|
||||||
|
|
||||||
[[ -f "$file" ]] || {
|
[[ -s "$file" ]] || {
|
||||||
err "No such file: ${file}"
|
if [[ -f "$file" ]]; then
|
||||||
|
err "File is empty: ${file}"
|
||||||
|
else
|
||||||
|
err "File does not exist: ${file}"
|
||||||
|
fi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
@@ -460,17 +466,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for t in "${args[@]}"; do
|
for t in "${args[@]}"; do
|
||||||
if [[ -s "$t" ]]; then
|
upload "$t" || return $?
|
||||||
upload "$t" || return $?
|
|
||||||
else
|
|
||||||
if [[ -f "$t" ]]; then
|
|
||||||
err "$t is empty"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
err "$t not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user