mirror of https://github.com/tycrek/ass.git
better error handling for rm and curl (#104)
Co-authored-by: Josh Moore <josh.moore@jmoore.dev>
This commit is contained in:
parent
fc82a6d6b3
commit
161c3f865e
|
@ -5,16 +5,23 @@ KEY="" # Your ass upload token
|
|||
DOMAIN="" # Your upload domain (without http:// or https://)
|
||||
|
||||
flameshot config -f "$IMAGENAME" # Make sure that Flameshot names the file correctly
|
||||
flameshot gui -r -p "$IMAGEPATH" # Prompt the screenshot GUI
|
||||
flameshot gui -r -p "$IMAGEPATH" > /dev/null # Prompt the screenshot GUI, also append the random gibberish to /dev/null
|
||||
|
||||
# Upload the image and copy the response URL
|
||||
URL=$(curl -X POST \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-H "Accept: application/json" \
|
||||
-H "User-Agent: ShareX/13.4.0" \
|
||||
-H "Authorization: $KEY" \
|
||||
-F "file=@$IMAGEPATH$IMAGENAME.png" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+')
|
||||
# printf instead of echo as echo appends a newline
|
||||
printf "%s" "$URL" | xclip -sel clip
|
||||
FILE="$IMAGEPATH$IMAGENAME.png" # File path and file name combined
|
||||
|
||||
rm "$IMAGEPATH$IMAGENAME.png" # Delete the image locally
|
||||
# Check if file exists to handle Curl and rm errors
|
||||
# then upload the image and copy the response URL
|
||||
if [ -f "$FILE" ]; then
|
||||
echo "$FILE exists."
|
||||
URL=$(curl -X POST \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-H "Accept: application/json" \
|
||||
-H "User-Agent: ShareX/13.4.0" \
|
||||
-H "Authorization: $KEY" \
|
||||
-F "file=@$IMAGEPATH$IMAGENAME.png" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+')
|
||||
# printf instead of echo as echo appends a newline
|
||||
printf "%s" "$URL" | xclip -sel clip
|
||||
rm "$IMAGEPATH$IMAGENAME.png" # Delete the image locally
|
||||
else
|
||||
echo "Aborted."
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue