clienside hash check

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

31
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,15 +48,25 @@ sup.env() {
done done
} }
sup.get_hash() {
read file_hash _ < <( sha1sum "$1" )
}
sup.upload() { sup.upload() {
curl -fsL \ sup.get_hash "$file"
-F file="@$file" \
-F upload_mode='api' \ if curl -fsL "${cfg_service_url}/hell/${file_hash}" &>/dev/null; then
-F flag_private="$flag_private" \ printf '%s\n' "${cfg_service_url}/hell/${file_hash}"
-F secret="$secret" \ else
-F submit="" \ curl -fsL \
-A 'zerofiles.org upload script' \ -F file="@$file" \
"$cfg_script_url" -F upload_mode='api' \
-F flag_private="$flag_private" \
-F secret="$secret" \
-F submit="" \
-A 'zerofiles.org upload script' \
"$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