Browse Source

Support for the new shortlink feature.

master
Jack L. Frost 7 years ago
parent
commit
9424b975ed
  1. 91
      sup

91
sup

@ -31,6 +31,7 @@ sup.usage() {
-F # Make a fullscreen shot instead of prompting for a window/area. Implies -s.
-D <num> # Delay the shot by <num> seconds.
-p # Make the file private. Requires \$secret to be set in the config.
-u # Generate a shortlink from URL.
Config options (~/.suprc):
secret # Your personal token. Get it at https://zfh.so/settings_form
@ -53,12 +54,39 @@ sup.get_hash() {
}
sup.upload() {
if (( flag_scrot )); then
file=$(sup.scrot) || { return 1; }
else
(( $# )) || {
sup.usage
return 1
}
target="$1"
if sup.if_url "$target"; then
file=$(sup.mktemp "$cfg_tmp_dir")
curl -skL "$target" > "$file" || {
sup.err "Could not download file."
return 1
}
else
file="$target"
[[ -f "$file" ]] || {
sup.err "No such file: ${file}"
return 1
}
fi
fi
sup.get_hash "$file"
if curl -fsL "${cfg_service_url}/hell/${file_hash}" &>/dev/null; then
if curl -fsL "${cfg_service_url}/api?mode=file&file=${file_hash}" >/dev/null; then
printf '%s\n' "${cfg_service_url}/hell/${file_hash}"
else
curl -fsL \
if curl -fsL \
-F file="@$file" \
-F upload_mode='api' \
-F flag_private="$flag_private" \
@ -66,6 +94,23 @@ sup.upload() {
-F submit="" \
-A 'zerofiles.org upload script' \
"$cfg_service_url/upload"
then
if (( flag_rm )); then
sup.msg "Removing file: $file"
rm "$file"
fi
else
sup.err 'Something has gone wrong with the upload.'
return 7
fi
fi
}
sup.url() {
declare url=$1
if ! curl -fsL "$cfg_service_url/api?mode=url_add&url=${url}&raw=1"; then
sup.err 'Something went wrong!'
fi
}
@ -166,6 +211,8 @@ main() {
flag_scrot='1'
flag_scrot_fullscreen='1'
;;
-u|--url) action='url';;
-h|--help|--usage) sup.usage; return;;
@ -178,42 +225,10 @@ main() {
sup.env
if (( flag_scrot )); then
file=$(sup.scrot) || { return 1; }
else
(( $# )) || {
sup.usage
return 1
}
target="$1"
if sup.if_url "$target"; then
file=$(sup.mktemp "$cfg_tmp_dir")
curl -skL "$target" > "$file" || {
sup.err "Could not download file."
return 1
}
else
file="$target"
[[ -f "$file" ]] || {
sup.err "No such file: ${file}"
return 1
}
fi
fi
if sup.upload; then
if (( "$flag_rm" )); then
sup.msg "Removing file: $file"
rm "$file"
fi
else
sup.err 'Something has gone wrong with the upload.'
return 7
fi
case "${action:-upload}" in
upload) sup.upload;;
url) sup.url "$1";;
esac
}
sup.set_argv "$@"

Loading…
Cancel
Save