clienside hash check

This commit is contained in:
Jack L. Frost 2015-06-21 09:52:29 +03:00
parent 75897a38f7
commit 30c57c8685

17
sup
View File

@ -8,7 +8,7 @@ _self="${0##*/}"
cfg_url_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+' cfg_url_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
cfg_tmp_dir="/tmp/$USER/sup"; TEMPDIR="$cfg_tmp_dir" cfg_tmp_dir="/tmp/$USER/sup"; TEMPDIR="$cfg_tmp_dir"
cfg_script_url='https://zfh.so/upload' cfg_service_url='https://zfh.so'
cfg_screenshot_ext='png' cfg_screenshot_ext='png'
[[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; } [[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; }
@ -38,7 +38,7 @@ sup.usage() {
# Others are self-explanatory: # Others are self-explanatory:
cfg_url_regex cfg_url_regex
cfg_tmp_dir cfg_tmp_dir
cfg_script_url cfg_service_url
EOF EOF
} }
@ -48,7 +48,16 @@ sup.env() {
done done
} }
sup.get_hash() {
read file_hash _ < <( sha1sum "$1" )
}
sup.upload() { sup.upload() {
sup.get_hash "$file"
if curl -fsL "${cfg_service_url}/hell/${file_hash}" &>/dev/null; then
printf '%s\n' "${cfg_service_url}/hell/${file_hash}"
else
curl -fsL \ curl -fsL \
-F file="@$file" \ -F file="@$file" \
-F upload_mode='api' \ -F upload_mode='api' \
@ -56,7 +65,8 @@ sup.upload() {
-F secret="$secret" \ -F secret="$secret" \
-F submit="" \ -F submit="" \
-A 'zerofiles.org upload script' \ -A 'zerofiles.org upload script' \
"$cfg_script_url" "$cfg_service_url/upload"
fi
} }
sup.mktemp() { sup.mktemp() {
@ -197,6 +207,7 @@ main() {
if sup.upload; then if sup.upload; then
if (( "$flag_rm" )); then if (( "$flag_rm" )); then
sup.msg "Removing file: $file"
rm "$file" rm "$file"
fi fi
else else