From f8d2c316589dfbc044b902eff9454bb141b19d20 Mon Sep 17 00:00:00 2001 From: dimon Date: Tue, 2 Jun 2026 22:04:05 +0800 Subject: [PATCH] Send-test uses form auth values directly (no save required) The "send test" button now passes the currently typed token / login / password to /api/test, falling back to saved defaults. Previously the test only used saved settings, so testing before clicking Save sent no auth and failed with 403 on access-controlled ntfy servers. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/main.py | 13 ++++++++----- app/schemas.py | 4 ++++ app/static/app.js | 6 +++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index 9de796f..a5a6b45 100644 --- a/app/main.py +++ b/app/main.py @@ -526,8 +526,11 @@ async def test_notification( server = data.server.strip() or s.default_ntfy_server if not data.topic.strip(): raise HTTPException(400, "Укажите тему") - # Use a custom server's own auth only if it matches the default; otherwise - # fall back to the configured default-server credentials. + # Prefer auth typed in the form right now; fall back to saved defaults so + # the test works whether or not settings were saved first. + token = s.default_ntfy_token if data.token is None else data.token.strip() + username = s.default_ntfy_username if data.username is None else data.username.strip() + password = s.default_ntfy_password if data.password is None else data.password try: await ntfy.publish( server=server, @@ -536,9 +539,9 @@ async def test_notification( message="Тестовое уведомление — всё работает!", tags="white_check_mark", priority=3, - token=s.default_ntfy_token, - username=s.default_ntfy_username, - password=s.default_ntfy_password, + token=token, + username=username, + password=password, ) except Exception as exc: # noqa: BLE001 raise HTTPException(502, f"Не удалось отправить: {exc}") diff --git a/app/schemas.py b/app/schemas.py index 5d51779..a04a50b 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -78,6 +78,10 @@ class SettingsIn(BaseModel): class TestIn(BaseModel): server: str = "" topic: str + # Optional auth from the form; falls back to saved default-server creds. + token: str | None = None + username: str | None = None + password: str | None = None class PreviewIn(BaseModel): diff --git a/app/static/app.js b/app/static/app.js index 51a2e40..f7894f3 100644 --- a/app/static/app.js +++ b/app/static/app.js @@ -435,7 +435,11 @@ $("#test-btn").onclick = async () => { if (!topic) { toast(t("toast.needTestTopic"), "err"); return; } try { const r = await api("POST", "/api/test", { - server: sForm.default_ntfy_server.value.trim(), topic, + server: sForm.default_ntfy_server.value.trim(), + topic, + token: sForm.default_ntfy_token.value.trim(), + username: sForm.default_ntfy_username.value.trim(), + password: sForm.default_ntfy_password.value, }); toast(t("toast.sentTo", { dest: r.sent_to })); } catch (err) { toast(err.message, "err"); }