Skip to content

Commit

Permalink
[apprise] fix apprise invalid json error.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizunge committed Sep 13, 2024
1 parent 843c406 commit 86827ef
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,37 @@ start_web_server() {
static-web-server --port="${WEB_PORT}" --root="${WEB_FOLDER}" --log-level=warn --compression=false
}

# Replace newline with '\n'
_replace_newline() {
local STRING="${1}"
echo "${STRING}" | sed 's/$/\\n/' | tr -d '\n'
}

_notify_via_apprise() {
local APPRISE_URL="${1}"
local URL="${1}"
local TYPE="${2}"
local TITLE="${3}"
local BODY="${4}"
[ -z "${APPRISE_URL}" ] && log INFO "Skip notifying via apprise. APPRISE_URL is empty." && return 1
if [ -z "${URL}" ]; then
log DEBUG "Skip sending notification via Apprise."
return 0
fi
# info, success, warning, failure
if [ "${TYPE}" != "info" ] && [ "${TYPE}" != "success" ] && [ "${TYPE}" != "warning" ] && [ "${TYPE}" != "failure" ]; then
TYPE="info"
fi
[ -z "${BODY}" ] && BODY="${TITLE}"
curl -X POST -H "Content-Type: application/json" --data "{\"title\": \"${TITLE}\", \"body\": \"${BODY}\", \"type\": \"${TYPE}\"}" "${APPRISE_URL}"
TITLE=$(_replace_newline "${TITLE}")
BODY=$(_replace_newline "${BODY}")
local LOG=
if LOG=$(curl --silent --show-error -X POST -H "Content-Type: application/json" --data "{\"title\": \"${TITLE}\", \"body\": \"${BODY}\", \"type\": \"${TYPE}\"}" "${URL}" 2>&1); then
log INFO "Sent notification via Apprise:"
echo "${LOG}" | log_lines INFO
else
log WARN "Failed to send notification via Apprise:"
echo "${LOG}" | log_lines WARN
fi
return 0
}

_post_blocky_lists_refresh() {
Expand Down

0 comments on commit 86827ef

Please sign in to comment.