From 2948a24fe89d08a4cd93889a949d3480c6450919 Mon Sep 17 00:00:00 2001 From: Ducky Date: Mon, 1 Apr 2024 22:22:27 +0100 Subject: [PATCH] sh.zio.notify: add file support --- usr/local/bin/sh.zio.notify | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/usr/local/bin/sh.zio.notify b/usr/local/bin/sh.zio.notify index b523a91..10be2bc 100755 --- a/usr/local/bin/sh.zio.notify +++ b/usr/local/bin/sh.zio.notify @@ -5,20 +5,11 @@ _PLUG_DESCRIPTION="" _PLUG_ARGS=( "message;m;;string;(No Message)" "title;t;;string;(No Title)" + "file;f;;path" "level;l;;string;info" "invoked-by;i;;string" ) -function get_cache_header() { - topic="$1" - - if [[ "$topic" == "zio_test" ]]; then - echo "" - else - echo "Cache: no" - fi -} - function get_level_emoji() { case "$1" in "critical"|"error") echo "⛔" ;; @@ -75,11 +66,28 @@ function main() { "topic": "'$n_topic'" }' - curl -d "$body" \ - -H "Authorization: Bearer $token" \ - -H "$(get_cache_header "$n_topic")" \ - -H "Markdown: yes" \ - "https://ntfy.zio.sh/" + curl_command="curl -d \"$body\"" + curl_command+=" -H \"Authorization: Bearer $token\"" + curl_command+=" -H \"Markdown: yes\"" + + if [[ "$n_topic" == "zio_test" ]]; then + curl_command+=" -H \"Cache: no\"" + fi + + if [[ "$_file" != "" ]]; then + if [[ ! -f "$_file" ]]; then + die "Cannot attach '$_file': file does not exist" + fi + + full_file="$(realpath -s "$_file")" + + curl_command+=" -T \"$full_file\"" + curl_command+=" -H \"Filename: $(basename "$full_file")\"" + fi + + curl_command+=" https://ntfy.zio.sh/" + + echo $curl_command } if [[ $_PLUG_INVOKED != "true" ]]; then