From 53714957d4bed97ecd95005643e7abbd22585df6 Mon Sep 17 00:00:00 2001 From: Maria Lisina Date: Mon, 22 Sep 2025 17:43:38 +0500 Subject: auth/*: Update auth units to follow new standard Signed-off-by: Maria Lisina --- auth/donmai.zsh | 42 +++++++++++++++++++----------------------- auth/moebooru.zsh | 35 ++++++++++++++++------------------- auth/sankakucomplex.zsh | 44 ++++++++++++++++++++------------------------ 3 files changed, 55 insertions(+), 66 deletions(-) (limited to 'auth') diff --git a/auth/donmai.zsh b/auth/donmai.zsh index f6f445f..e957fd8 100644 --- a/auth/donmai.zsh +++ b/auth/donmai.zsh @@ -2,49 +2,45 @@ # Copyright (C) 2024-2025 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -ib_auth_file="${cache}/${update_id}_profile.json" -dump+=(${ib_auth_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request GET \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user "${ib_login}:${ib_key}" \ - --user-agent "${useragent}" \ - "${ib_auth}/profile.json" +if ! ib_auth_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --max-time ${external_timeout} \ + --proxy "${external_proxy}" \ + --request GET \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user "${ib_login}:${ib_key}" \ + --user-agent "${useragent}" \ + "${ib_auth}/profile.json" +)" then output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" + log_text="ib_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${ib_auth_file}" > /dev/null +if ! jq -e '.' <<< "${ib_auth_data}" > /dev/null then output_text="An unknown error occurred" - log_text="ib_auth (${update_id}): ${output_text}" + log_text="ib_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if [[ "$(jq -r '.success' "${ib_auth_file}")" == "false" ]] +if [[ "$(jq -r '.success' <<< "${ib_auth_data}")" == "false" ]] then - output_text="Error: $(jq -r '.message' "${ib_auth_file}" | htmlescape)" + output_text="Error: $(jq -r '.message' <<< "${ib_auth_data}" | htmlescape)" return 0 fi -if [[ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]] +if [[ "$(jq -r '.name' <<< "${ib_auth_data}")" != "${ib_login}" ]] then output_text="Failed to verify user authorization" return 0 diff --git a/auth/moebooru.zsh b/auth/moebooru.zsh index 5458b11..1c3d573 100644 --- a/auth/moebooru.zsh +++ b/auth/moebooru.zsh @@ -2,33 +2,30 @@ # Copyright (C) 2024-2025 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -ib_auth_file="${cache}/${update_id}_user.json" -dump+=(${ib_auth_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --data-urlencode "username=${ib_login}" \ - --data-urlencode "api_key=${ib_key}" \ - --get \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/user.json" +if ! ib_auth_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --data-urlencode "username=${ib_login}" \ + --data-urlencode "api_key=${ib_key}" \ + --get \ + --max-time ${external_timeout} \ + --proxy "${external_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/user.json" +)" then output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" + log_text="ib_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${ib_auth_file}" > /dev/null +if ! jq -e '.' <<< "${ib_auth_data}" > /dev/null then output_text="Invalid username or API key" fi diff --git a/auth/sankakucomplex.zsh b/auth/sankakucomplex.zsh index 45b9d3a..3eabc78 100644 --- a/auth/sankakucomplex.zsh +++ b/auth/sankakucomplex.zsh @@ -9,48 +9,44 @@ ib_login_data="$( '{"login": $login, "password": $password}' )" -ib_auth_file="${cache}/${update_id}_token.json" -dump+=(${ib_auth_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --data "${ib_login_data}" \ - --header "Content-Type: application/json" \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request POST \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/auth/token" +if ! ib_auth_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --data "${ib_login_data}" \ + --header "Content-Type: application/json" \ + --max-time ${external_timeout} \ + --proxy "${external_proxy}" \ + --request POST \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/auth/token" +)" then output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" + log_text="ib_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${ib_auth_file}" > /dev/null +if ! jq -e '.' <<< "${ib_auth_data}" > /dev/null then output_text="An unknown error occurred" - log_text="ib_auth (${update_id}): ${output_text}" + log_text="ib_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if [[ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]] +if [[ "$(jq -r '.success' <<< "${ib_auth_data}")" != "true" ]] then - output_text="Error: $(jq -r '.error' "${ib_auth_file}" | htmlescape)" + output_text="Error: $(jq -r '.error' <<< "${ib_auth_data}" | htmlescape)" return 0 fi -jq -r '.access_token' "${ib_auth_file}" > "${token_file}" +jq -r '.access_token' <<< "${ib_auth_data}" > "${token_file}" strftime %s > "${timestamp_file}" -- cgit v1.2.3