diff --git a/ufw b/ufw index 56d2abb..07dfaee 100755 --- a/ufw +++ b/ufw @@ -37,7 +37,7 @@ usage() { -u|--shorten # 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 [suf] # Maximum filesize (takes K, M and G suffixes). + -m|--max-filesize [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 "" # 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 ;;