diff options
| author | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-08-17 16:26:58 +0500 |
|---|---|---|
| committer | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-08-17 16:26:58 +0500 |
| commit | ca558111f309c8e8ccd389df3e76a68bb1340840 (patch) | |
| tree | 9d3340b4577fa3e139733e340f9cb784a2039f35 /auth/sankakucomplex.zsh | |
| parent | a78a32090245e7caf8a35c4dde798aee7bd7ad10 (diff) | |
*/*: Initial new Sankaku Complex support
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
Diffstat (limited to 'auth/sankakucomplex.zsh')
| -rw-r--r-- | auth/sankakucomplex.zsh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/auth/sankakucomplex.zsh b/auth/sankakucomplex.zsh new file mode 100644 index 0000000..86010be --- /dev/null +++ b/auth/sankakucomplex.zsh @@ -0,0 +1,61 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_login_data="$( + jq --null-input --compact-output \ + --arg login "${ib_login}" \ + --arg password "${ib_key}" \ + '{"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" +then + output_text="Failed to access ${ib_name} API" + 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 +then + output_text="An unknown error occurred" + 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" ]] +then + output_text="Error: <code>$(jq -r '.error' "${ib_auth_file}" | htmlescape)</code>" + log_text="ib_auth (${update_id}): Error: $(jq -r '.error' "${ib_auth_file}")" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +jq -r '.access_token' "${ib_auth_file}" > "${token_file}" +strftime %s > "${timestamp_file}" |
