check api response exit code

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
2026-11-28 02:04:34 +00:00
parent 97f720fed7
commit 15bde01fb6
+26 -1
View File
@@ -89,6 +89,10 @@ get_album_id() {
--data-urlencode "name=$1" \ --data-urlencode "name=$1" \
--data-urlencode "secret=$secret" \ --data-urlencode "secret=$secret" \
"$cfg_service_url/albumctl.json?m=new" ) "$cfg_service_url/albumctl.json?m=new" )
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
get_api_status <<< "$api_response" get_api_status <<< "$api_response"
@@ -165,6 +169,10 @@ upload() {
"${misc_curl_args[@]}" \ "${misc_curl_args[@]}" \
-A 'zerofiles.org upload script' \ -A 'zerofiles.org upload script' \
"$cfg_service_url/maw.json" ) "$cfg_service_url/maw.json" )
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
if (( flag_shortlink )); then if (( flag_shortlink )); then
if (( flag_directlink )); then if (( flag_directlink )); then
@@ -210,6 +218,10 @@ get_shortlink() {
api_response=$( curl --data-urlencode "url=$url" \ api_response=$( curl --data-urlencode "url=$url" \
--data-urlencode "secret=$secret" \ --data-urlencode "secret=$secret" \
"$cfg_service_url/shrink.json" ) "$cfg_service_url/shrink.json" )
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
get_api_status <<< "$api_response" get_api_status <<< "$api_response"
@@ -254,7 +266,11 @@ _mktemp() {
get_my_ip() { get_my_ip() {
declare api_response api_status api_status_message my_ip declare api_response api_status api_status_message my_ip
api_response=$( curl "$cfg_service_url/ip.json" ) api_response=$( curl -f "$cfg_service_url/ip.json" )
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
get_api_status <<< "$api_response" get_api_status <<< "$api_response"
@@ -274,6 +290,10 @@ login() {
api_response=$( curl --get \ api_response=$( curl --get \
--data-urlencode "login=$login" \ --data-urlencode "login=$login" \
"$cfg_service_url/token_request.json" ) "$cfg_service_url/token_request.json" )
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
if get_api_status <<< "$api_response"; then if get_api_status <<< "$api_response"; then
printf 'Check your email.\n' printf 'Check your email.\n'
@@ -307,6 +327,11 @@ get_token() {
} }
api_response=$(curl -b "$cfg_file.cookiejar" -sl "$cfg_service_url/api_token.json") api_response=$(curl -b "$cfg_file.cookiejar" -sl "$cfg_service_url/api_token.json")
(( $? )) && {
err "Failed to get a response from the API, folding."
return 1
}
rm -f "$cfg_file.cookiejar" rm -f "$cfg_file.cookiejar"
if get_api_status <<< "$api_response"; then if get_api_status <<< "$api_response"; then