Abort PR upload if no server is available (#922)

* gracefully abort PR upload
* timeout if api doesn't respond in 15secs
This commit is contained in:
bnkai 2020-11-06 04:15:50 +02:00 committed by GitHub
parent 8a04e5df62
commit ccc2df7315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -5,8 +5,19 @@ uploadFile()
{
FILE=$1
BASENAME="$(basename "${FILE}")"
# get available server from gofile api
server=$(curl https://apiv2.gofile.io/getServer |cut -d "," -f 2 | cut -d "\"" -f 6)
serverApi=$(curl -m 15 https://apiv2.gofile.io/getServer)
resp=$(echo "$serverApi" | cut -d "\"" -f 4)
# if no server is available abort
if [ $resp != "ok" ] ; then
echo "Upload of $BASENAME failed! Server not available."
echo
return
fi
server=$(echo "$serverApi" | cut -d "," -f 2 | cut -d "\"" -f 6)
# abort if it takes more than two minutes to upload
uploadedTo=$(curl -m 120 -F "email=stash@stashapp.cc" -F "file=@$FILE" "https://$server.gofile.io/uploadFile")
resp=$(echo "$uploadedTo" | cut -d "\"" -f 4)