From 5a88e356e066c21b798153bf4332734a423d1b82 Mon Sep 17 00:00:00 2001 From: kriszcode Date: Sat, 10 Jan 2026 17:52:54 +0100 Subject: [PATCH] Add support for token-based authorization in NTFY notifications and update project configuration --- .gitignore | 1 + Makefile | 7 +++++-- project.env | 3 ++- src/config.json.example | 1 + src/main.js | 9 ++++++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c8326cc..2739559 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ Thumbs.db # project files config.json +secret.json # Keep .gitkeep files so empty folders can be tracked !**/.gitkeep \ No newline at end of file diff --git a/Makefile b/Makefile index 645807b..ea2f7d2 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ publish: git_info echo "Error: Nincs verzió szám"; \ exit 1; \ fi - #@sudo docker login $(DOCKER_REGISTRY) + @sudo docker login $(DOCKER_REGISTRY) @sudo docker build \ --no-cache \ --label version=$(VERSION) \ @@ -74,4 +74,7 @@ publish: git_info --label org.opencontainers.image.source.hash=$(GIT_HASH) \ -t $(DOCKER_REGISTRY)/${OWNER}/$(NAME):$(VERSION) \ . - @sudo docker push $(DOCKER_REGISTRY)/$(NAME):$(VERSION) \ No newline at end of file + @sudo docker push $(DOCKER_REGISTRY)/${OWNER}/$(NAME):$(VERSION) + +create_secret: + cat "${ROOT_DIR}/src/config.json" | jq -c . > ./secret.json \ No newline at end of file diff --git a/project.env b/project.env index 417beb5..05fa3c3 100644 --- a/project.env +++ b/project.env @@ -1,2 +1,3 @@ NAME=imap_notification -DOCKER_REGISTRY=gitea.szabolcsi.dev \ No newline at end of file +DOCKER_REGISTRY=gitea.szabolcsi.dev +OWNER=kriszcode \ No newline at end of file diff --git a/src/config.json.example b/src/config.json.example index 293fa18..7dfacc3 100755 --- a/src/config.json.example +++ b/src/config.json.example @@ -1,5 +1,6 @@ { "lang": "en", + "token": "[optional] your ntfy token", "accounts": [ { "name": "Example", diff --git a/src/main.js b/src/main.js index b11bafb..d88f4b1 100755 --- a/src/main.js +++ b/src/main.js @@ -56,6 +56,13 @@ async function sendNtfy(acc, subject, from, to) { log.debug(`Sending ntfy notification for account [${acc.name}] with topic [${acc.topic}]`, messageBody); + const options = {} + if (config.token) { + options.headers = { + 'Authorization': `Bearer ${config.token}` + } + } + await axios.post(`${NTFY_INTERNAL_URL}`, { topic: acc.topic, title: i18n.t('new_email_title'), @@ -63,7 +70,7 @@ async function sendNtfy(acc, subject, from, to) { priority: 5, tags: ['incoming_envelope'], click: 'message://' - }) + }, options); } catch (err) { log.error(i18n.t('ntfy_call_error'), err.message);