max filesize
This commit is contained in:
parent
a4e0a119a8
commit
8befbdf3da
34
sup
34
sup
|
@ -15,6 +15,7 @@ cfg_url_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
|
||||||
cfg_tmp_dir="$XDG_RUNTIME_DIR/sup"; TEMPDIR="$cfg_tmp_dir"
|
cfg_tmp_dir="$XDG_RUNTIME_DIR/sup"; TEMPDIR="$cfg_tmp_dir"
|
||||||
cfg_service_url='https://8fw.me'
|
cfg_service_url='https://8fw.me'
|
||||||
cfg_screenshot_ext='png'
|
cfg_screenshot_ext='png'
|
||||||
|
cfg_max_filesize='200M'
|
||||||
|
|
||||||
[[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; }
|
[[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; }
|
||||||
|
|
||||||
|
@ -42,10 +43,12 @@ sup.usage() {
|
||||||
-D <num> # Delay the shot by <num> seconds.
|
-D <num> # Delay the shot by <num> seconds.
|
||||||
-p # Make the file private. Requires \$secret to be set in the config.
|
-p # Make the file private. Requires \$secret to be set in the config.
|
||||||
-u # Generate a shortlink from URL.
|
-u # Generate a shortlink from URL.
|
||||||
|
-m # Maximum filesize (in megabytes)
|
||||||
|
|
||||||
Config options (~/.suprc):
|
Config options (~/.suprc):
|
||||||
secret # Your personal token. Get it at https://zfh.so/settings_form
|
secret # Your personal token. Get it at https://zfh.so/settings_form
|
||||||
cfg_screenshot_ext # Screenshot file type, used by scrot.
|
cfg_screenshot_ext # Screenshot file type, used by scrot.
|
||||||
|
cfg_max_filesize # Maximum filesize in megabytes.
|
||||||
# Others are self-explanatory:
|
# Others are self-explanatory:
|
||||||
cfg_url_regex
|
cfg_url_regex
|
||||||
cfg_tmp_dir
|
cfg_tmp_dir
|
||||||
|
@ -63,6 +66,22 @@ sup.get_hash() {
|
||||||
read file_hash _ < <( sha1sum "$1" )
|
read file_hash _ < <( sha1sum "$1" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sup.get_max_filesize() {
|
||||||
|
if [[ $cfg_max_filesize =~ ^[0-9]+[BKMG]?$ ]]; then
|
||||||
|
max_filesize_base="${cfg_max_filesize//[BKMG]/}"
|
||||||
|
|
||||||
|
case "$cfg_max_filesize" in
|
||||||
|
*K) max_filesize_bytes=$(( max_filesize_base * 1024 ));;
|
||||||
|
*M) max_filesize_bytes=$(( max_filesize_base * 1024 * 1024 ));;
|
||||||
|
*G) max_filesize_bytes=$(( max_filesize_base * 1024 * 1024 * 1024 ));;
|
||||||
|
*) max_filesize_bytes=$max_filesize_base;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
sup.err "Wrong cfg_max_filesize: $cfg_max_filesize"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
sup.upload() {
|
sup.upload() {
|
||||||
if (( flag_scrot )); then
|
if (( flag_scrot )); then
|
||||||
flag_rm=1
|
flag_rm=1
|
||||||
|
@ -79,10 +98,19 @@ sup.upload() {
|
||||||
flag_rm=1
|
flag_rm=1
|
||||||
file=$(sup.mktemp "$cfg_tmp_dir")
|
file=$(sup.mktemp "$cfg_tmp_dir")
|
||||||
|
|
||||||
curl -skL "$target" > "$file" || {
|
sup.get_max_filesize || { return 1; }
|
||||||
sup.err "Could not download file."
|
|
||||||
|
curl --max-filesize "$max_filesize_bytes" -skL "$target" > "$file"
|
||||||
|
curl_result=$?
|
||||||
|
|
||||||
|
if (( curl_result )); then
|
||||||
|
case "$curl_result" in
|
||||||
|
63) sup.err "File exceeds cfg_max_filesize";;
|
||||||
|
*) sup.err "Could not download file.";;
|
||||||
|
esac
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
fi
|
||||||
else
|
else
|
||||||
file="$target"
|
file="$target"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user