diff options
| author | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-09-21 16:08:16 +0500 |
|---|---|---|
| committer | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-09-21 16:08:16 +0500 |
| commit | 8930caf6179c064b062fe3fd3c2873cfbc8d9b3b (patch) | |
| tree | 378acdd896c75655db29a5da7928e8c506cf6df3 /units | |
| parent | b8dde1bd253e0404f0de8e3cfa52709c932b4ce2 (diff) | |
units/*: Update submodules and units to follow new standard
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
Diffstat (limited to 'units')
| -rw-r--r-- | units/export.zsh | 97 | ||||
| -rw-r--r-- | units/ib_common.zsh | 3 | ||||
| -rw-r--r-- | units/ib_file.zsh | 24 | ||||
| -rw-r--r-- | units/ib_hash.zsh | 16 | ||||
| -rw-r--r-- | units/ib_name.zsh | 4 | ||||
| -rw-r--r-- | units/ib_search.zsh | 3 | ||||
| -rw-r--r-- | units/sn_auth.zsh | 40 | ||||
| -rw-r--r-- | units/sn_get.zsh | 81 | ||||
| -rw-r--r-- | units/sn_search.zsh | 56 |
9 files changed, 150 insertions, 174 deletions
diff --git a/units/export.zsh b/units/export.zsh index c2d2755..13ec40a 100644 --- a/units/export.zsh +++ b/units/export.zsh @@ -8,48 +8,49 @@ then return 0 fi +until mkdir "${cache}/${user_id}.lock" +do + sleep 1 +done + rm -f "${cache}/${user_id}.tar" if ! tar c -hf "${cache}/${user_id}.tar" "${user_config}" then output_text="Something went wrong, try again later" + + rmdir "${cache}/${user_id}.lock" return 0 fi -output_file="${cache}/${update_id}_sendChatAction.json" -dump+=(${output_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --data-urlencode "chat_id=${chat_id}" \ - --data-urlencode "action=upload_document" \ - --get \ - --max-time ${internal_timeout} \ - --output "${output_file}" \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((internal_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/bot${api_token}/sendChatAction" +if ! output_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --data-urlencode "chat_id=${chat_id}" \ + --data-urlencode "action=upload_document" \ + --get \ + --max-time ${internal_timeout} \ + --proxy "${internal_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((internal_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${api_address}/bot${api_token}/sendChatAction" +)" then log_text="sendChatAction (${update_id}): Failed to access Telegram Bot API" - . "${units}/log.zsh" - . "${units}/dump.zsh" fi -if [[ -z "${log_text}" ]] && ! jq -e '.' "${output_file}" > /dev/null +if [[ -z "${log_text}" ]] && ! jq -e '.' <<< "${output_data}" > /dev/null then log_text="sendChatAction (${update_id}): An unknown error occurred" - . "${units}/log.zsh" - . "${units}/dump.zsh" fi -if [[ -z "${log_text}" && "$(jq -r '.ok' "${output_file}")" != "true" ]] +if [[ -z "${log_text}" && "$(jq -r '.ok' <<< "${output_data}")" != "true" ]] then - error_description="$(jq -r '.description' "${output_file}")" + error_description="$(jq -r '.description' <<< "${output_data}")" if [[ "${error_description}" != "null" ]] then @@ -59,51 +60,48 @@ then fi . "${units}/log.zsh" - . "${units}/dump.zsh" fi -output_file="${cache}/${update_id}_sendDocument.json" -dump+=(${output_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --form "chat_id=${chat_id}" \ - --form "document=@${cache}/${user_id}.tar" \ - --form "reply_parameters=${reply_parameters}" \ - --get \ - --max-time ${internal_timeout} \ - --output "${output_file}" \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((internal_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/bot${api_token}/sendDocument" +if ! output_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --form "chat_id=${chat_id}" \ + --form "document=@${cache}/${user_id}.tar" \ + --form "reply_parameters=${reply_parameters}" \ + --get \ + --max-time ${internal_timeout} \ + --proxy "${internal_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((internal_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${api_address}/bot${api_token}/sendDocument" +)" then output_text="Failed to send user data" - log_text="sendDocument (${update_id}): Failed to access Telegram Bot API" + log_text="sendDocument (${update_id}): Failed to access Telegram Bot API" . "${units}/log.zsh" - . "${units}/dump.zsh" + rmdir "${cache}/${user_id}.lock" return 0 fi -if ! jq -e '.' "${output_file}" > /dev/null +if ! jq -e '.' <<< "${output_data}" > /dev/null then output_text="An unknown error occurred" - log_text="sendDocument (${update_id}): An unknown error occurred" + log_text="sendDocument (${update_id}): An unknown error occurred" . "${units}/log.zsh" - . "${units}/dump.zsh" + rmdir "${cache}/${user_id}.lock" return 0 fi -if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]] +if [[ "$(jq -r '.ok' <<< "${output_data}")" != "true" ]] then output_text="Failed to send user data" - error_description="$(jq -r '.description' "${output_file}")" + error_description="$(jq -r '.description' <<< "${output_data}")" if [[ "${error_description}" != "null" ]] then @@ -113,5 +111,6 @@ then fi . "${units}/log.zsh" - . "${units}/dump.zsh" fi + +rmdir "${cache}/${user_id}.lock" diff --git a/units/ib_common.zsh b/units/ib_common.zsh index d2f89c2..78571c7 100644 --- a/units/ib_common.zsh +++ b/units/ib_common.zsh @@ -52,6 +52,3 @@ then else ib_query="id:${ib_post_id}" fi - -ib_hash="$(sha1sum <<< "${user_id}${ib_board}${ib_query}" | cut -d ' ' -f 1)" -. "${units}/ib_file.zsh" diff --git a/units/ib_file.zsh b/units/ib_file.zsh index ec1bf71..220c6ff 100644 --- a/units/ib_file.zsh +++ b/units/ib_file.zsh @@ -2,14 +2,6 @@ # Copyright (C) 2024-2025 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -until mkdir "${cache}/${ib_hash}.lock" -do - sleep 1 -done - -ib_file="${cache}/${ib_hash}.json" -dump+=(${ib_file##*/}) - if [[ -f "${ib_file}" && "${cache_mode}" != "none" ]] then ib_ctime=$(strftime %s) @@ -17,7 +9,6 @@ then if [[ $((ib_ctime - ib_mtime)) -le ${cache_time} ]] then - rmdir "${cache}/${ib_hash}.lock" return 0 fi fi @@ -28,7 +19,6 @@ then if [[ -n "${output_text}" ]] then - rmdir "${cache}/${ib_hash}.lock" return 0 fi fi @@ -75,14 +65,13 @@ then output_title="An error occurred" output_text="Failed to access ${ib_name} API" notification_text="${output_text}" + log_text="ib_file (${update_id}): ${output_text}" + . "${units}/log.zsh" next_offset=${inline_page:-0} - . "${units}/log.zsh" - . "${units}/dump.zsh" - - rm -fr "${ib_file}" "${cache}/${ib_hash}.lock" + rm -f "${ib_file}" return 0 fi @@ -91,12 +80,11 @@ then output_title="An error occurred" output_text="An unknown error occurred" notification_text="${output_text}" - log_text="ib_file (${update_id}): ${output_text}" + log_text="ib_file (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" - rm -fr "${ib_file}" "${cache}/${ib_hash}.lock" + rm -f "${ib_file}" return 0 fi @@ -133,5 +121,3 @@ then rm -f "${ib_file}" fi - -rmdir "${cache}/${ib_hash}.lock" diff --git a/units/ib_hash.zsh b/units/ib_hash.zsh index e4df49c..b58bb0d 100644 --- a/units/ib_hash.zsh +++ b/units/ib_hash.zsh @@ -2,6 +2,7 @@ # Copyright (C) 2024-2025 Danil Lisin # SPDX-License-Identifier: Apache-2.0 +rm -f "${ib_post}" ib_mode="p" . "${units}/ib_config.zsh" @@ -15,8 +16,21 @@ fi ib_query="md5:${ib_post_md5}" ib_hash="$(sha1sum <<< "${user_id}${ib_board}${ib_query}" | cut -d ' ' -f 1)" +ib_file="${cache}/${ib_hash}.json" + +until mkdir "${cache}/${ib_hash}.lock" +do + sleep 1 +done + . "${units}/ib_file.zsh" +if [[ -n "${output_text}" ]] +then + rmdir "${cache}/${ib_hash}.lock" + exit 0 +fi + if [[ -z "${output_text}" ]] then ib_id="$(jq -r ".${ib_iarray}[0].${ib_iid}" "${ib_file}")" @@ -35,3 +49,5 @@ then printf "%s\n" "${ib_id}" > "${ib_post}" fi + +rmdir "${cache}/${ib_hash}.lock" diff --git a/units/ib_name.zsh b/units/ib_name.zsh index 58133c5..9e8f392 100644 --- a/units/ib_name.zsh +++ b/units/ib_name.zsh @@ -7,11 +7,11 @@ then return 0 fi -reply_text="$(jq -r '.message.reply_to_message.text' "${update}")" +reply_text="$(jq -r '.message.reply_to_message.text' <<< "${update}")" if [[ "${reply_text}" == "null" ]] then - reply_text="$(jq -r '.message.reply_to_message.caption' "${update}")" + reply_text="$(jq -r '.message.reply_to_message.caption' <<< "${update}")" fi if [[ "${reply_text}" == "null" ]] diff --git a/units/ib_search.zsh b/units/ib_search.zsh index 421106f..423b5a1 100644 --- a/units/ib_search.zsh +++ b/units/ib_search.zsh @@ -69,6 +69,3 @@ if [[ -n "${ib_iwildcard}" ]] then ib_query="$(sed "s/${ib_iwildcard}/\\\\${ib_iwildcard}/g" <<< "${ib_query}" | tr '*' "${ib_iwildcard}")" fi - -ib_hash="$(sha1sum <<< "${user_id}${ib_mode}${ib_board}${ib_page}${ib_query}" | cut -d ' ' -f 1)" -. "${units}/ib_file.zsh" diff --git a/units/sn_auth.zsh b/units/sn_auth.zsh index 4aa8cce..d962113 100644 --- a/units/sn_auth.zsh +++ b/units/sn_auth.zsh @@ -17,44 +17,40 @@ else return 0 fi -sn_file="${cache}/${update_id}_search.json" -dump+=(${sn_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --data-urlencode "output_type=2" \ - --data-urlencode "api_key=${sn_key}" \ - --get \ - --max-time ${external_timeout} \ - --output "${sn_file}" \ - --proxy "${external_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "https://saucenao.com/search.php" +if ! sn_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --data-urlencode "output_type=2" \ + --data-urlencode "api_key=${sn_key}" \ + --get \ + --max-time ${external_timeout} \ + --proxy "${external_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "https://saucenao.com/search.php" +)" then output_text="Failed to access SauceNAO API" - log_text="sn_auth (${update_id}): ${output_text}" + log_text="sn_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${sn_file}" > /dev/null +if ! jq -e '.' <<< "${sn_data}" > /dev/null then output_text="An unknown error occurred" - log_text="sn_auth (${update_id}): ${output_text}" + log_text="sn_auth (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -sn_status="$(jq -r '.header.status' "${sn_file}")" +sn_status="$(jq -r '.header.status' <<< "${sn_data}")" case "${sn_status}" in (-3) diff --git a/units/sn_get.zsh b/units/sn_get.zsh index 2c28069..a6cbf7b 100644 --- a/units/sn_get.zsh +++ b/units/sn_get.zsh @@ -4,8 +4,8 @@ if [[ -z "${file_id}" ]] then - message_id="$(jq -r '.message.reply_to_message.message_id' "${update}")" - file_id="$(jq -r '.message.reply_to_message.photo.[1].file_id' "${update}")" + message_id="$(jq -r '.message.reply_to_message.message_id' <<< "${update}")" + file_id="$(jq -r '.message.reply_to_message.photo.[1].file_id' <<< "${update}")" if [[ "${message_id}" == "null" || "${message_id}" == "${message_thread_id}" ]] then @@ -20,46 +20,42 @@ then fi fi -output_file="${cache}/${update_id}_getFile.json" -dump+=(${output_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --data-urlencode "file_id=${file_id}" \ - --get \ - --max-time ${internal_timeout} \ - --output "${output_file}" \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/bot${api_token}/getFile" +if ! output_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --data-urlencode "file_id=${file_id}" \ + --get \ + --max-time ${internal_timeout} \ + --proxy "${internal_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${api_address}/bot${api_token}/getFile" +)" then output_text="Failed to get image file" - log_text="getFile (${update_id}): Failed to access Telegram Bot API" + log_text="getFile (${update_id}): Failed to access Telegram Bot API" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${output_file}" > /dev/null +if ! jq -e '.' <<< "${output_data}" > /dev/null then output_text="An unknown error occurred" - log_text="getFile (${update_id}): An unknown error occurred" + log_text="getFile (${update_id}): An unknown error occurred" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]] +if [[ "$(jq -r '.ok' <<< "${output_data}")" != "true" ]] then output_text="Failed to get image file" - error_description="$(jq -r '.description' "${output_file}")" + error_description="$(jq -r '.description' <<< "${output_data}")" if [[ "${error_description}" != "null" ]] then @@ -69,42 +65,37 @@ then fi . "${units}/log.zsh" - . "${units}/dump.zsh" - return 0 fi -file_path="$(jq -r '.result.file_path' "${output_file}")" +file_path="$(jq -r '.result.file_path' <<< "${output_data}")" if [[ "${api_address}" != "${local_address}" ]] then - output_file="${cache}/${update_id}_file.jpg" - dump+=(${output_file##*/}) - - if ! curl --connect-timeout ${connrefused_timeout} \ - --max-time ${internal_timeout} \ - --output "${output_file}" \ - --proxy "${internal_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "${api_address}/file/bot${api_token}/${file_path}" + if ! output_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --max-time ${internal_timeout} \ + --proxy "${internal_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "${api_address}/file/bot${api_token}/${file_path}" + )" then output_text="Failed to download image file" - log_text="getFile (${update_id}): Failed to access Telegram Bot API" + log_text="getFile (${update_id}): Failed to access Telegram Bot API" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi - if [[ "$(jq -r '.ok' "${output_file}")" == "false" ]] + if [[ "$(jq -r '.ok' <<< "${output_data}")" == "false" ]] then output_text="Failed to download image file" - error_description="$(jq -r '.description' "${output_file}")" + error_description="$(jq -r '.description' <<< "${output_data}")" if [[ "${error_description}" != "null" ]] then @@ -114,8 +105,6 @@ then fi . "${units}/log.zsh" - . "${units}/dump.zsh" - return 0 fi diff --git a/units/sn_search.zsh b/units/sn_search.zsh index 94fc109..920071a 100644 --- a/units/sn_search.zsh +++ b/units/sn_search.zsh @@ -2,52 +2,48 @@ # Copyright (C) 2024-2025 Danil Lisin # SPDX-License-Identifier: Apache-2.0 -sn_file="${cache}/${update_id}_search.json" -dump+=(${sn_file##*/}) - -if ! curl --connect-timeout ${connrefused_timeout} \ - --form "output_type=2" \ - --form "api_key=${sn_key}" \ - --form "dbs[]=9" \ - --form "dbs[]=12" \ - --form "dbs[]=25" \ - --form "dbs[]=26" \ - --form "dbs[]=27" \ - --form "dbs[]=30" \ - --form "dedupe=2" \ - --form "${sn_query}" \ - --get \ - --max-time ${external_timeout} \ - --output "${sn_file}" \ - --proxy "${external_proxy}" \ - --retry 1 \ - --retry-connrefused \ - --retry-max-time $((external_timeout - connrefused_timeout)) \ - --silent \ - --user-agent "${useragent}" \ - "https://saucenao.com/search.php" +if ! sn_data="$( + curl --connect-timeout ${connrefused_timeout} \ + --form "output_type=2" \ + --form "api_key=${sn_key}" \ + --form "dbs[]=9" \ + --form "dbs[]=12" \ + --form "dbs[]=25" \ + --form "dbs[]=26" \ + --form "dbs[]=27" \ + --form "dbs[]=30" \ + --form "dedupe=2" \ + --form "${sn_query}" \ + --get \ + --max-time ${external_timeout} \ + --proxy "${external_proxy}" \ + --retry 1 \ + --retry-connrefused \ + --retry-max-time $((external_timeout - connrefused_timeout)) \ + --silent \ + --user-agent "${useragent}" \ + "https://saucenao.com/search.php" +)" then output_text="Failed to access SauceNAO API" - log_text="sn_search (${update_id}): ${output_text}" + log_text="sn_search (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -if ! jq -e '.' "${sn_file}" > /dev/null +if ! jq -e '.' <<< "${sn_data}" > /dev/null then output_text="An unknown error occurred" - log_text="sn_search (${update_id}): ${output_text}" + log_text="sn_search (${update_id}): ${output_text}" . "${units}/log.zsh" - . "${units}/dump.zsh" return 0 fi -sn_status="$(jq -r '.header.status' "${sn_file}")" +sn_status="$(jq -r '.header.status' <<< "${sn_data}")" case "${sn_status}" in (-2) |
