From ed62cc90de34a54c5f4f25fceac72a3174a699ea Mon Sep 17 00:00:00 2001 From: SkyfallWasTaken Date: Sat, 20 Jul 2024 19:22:43 +0100 Subject: [PATCH] Add authenticated ntfy --- README.md | 3 ++- src/lib.rs | 4 +++- wrangler.toml | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a60a74..effa214 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,11 @@ ## Environment variables ### Secrets - `SLACK_WEBHOOK_URL` - Slack webhook to call on updates -- `NTFY_URL` - URL for ntfy +- `NTFY_AUTH_TOKEN` - Auth token for ntfy ### Variables - `ARCADE_SHOP_URL` - Shop URL to fetch +- `NTFY_URL` - URL for ntfy ## Tech Stack - **Cloudflare Workers** for running the monitor on the edge. diff --git a/src/lib.rs b/src/lib.rs index 1621471..84593d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,8 @@ pub async fn scheduled(event: ScheduledEvent, env: Env, _ctx: ScheduleContext) { async fn run_scrape(env: Env) -> Result { let shop_url = Url::parse(&env.var("ARCADE_SHOP_URL")?.to_string())?; let slack_webhook_url = env.secret("SLACK_WEBHOOK_URL")?.to_string(); - let ntfy_url = env.secret("NTFY_URL")?.to_string(); + let ntfy_url = env.var("NTFY_URL")?.to_string(); + let ntfy_auth_token = env.secret("NTFY_AUTH_TOKEN")?.to_string(); let client = Client::new(); let kv = env.kv("SHOP_ITEMS")?; @@ -77,6 +78,7 @@ async fn run_scrape(env: Env) -> Result { // ntfy webhook client .post(ntfy_url) + .bearer_auth(ntfy_auth_token) .header("X-Title", "Changes detected in Arcade Shop") .header("X-Priority", "high") .body(changes) diff --git a/wrangler.toml b/wrangler.toml index 469b420..7c55bd0 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,6 +12,7 @@ crons = ["*/20 * * * *"] # Run every twenty minutes mode = "smart" [vars] +NTFY_URL = "https://ntfy.hackclub.app/arcade-monitor" ARCADE_SHOP_URL = "https://hackclub.com/arcade/shop/" [[kv_namespaces]]