Send-test uses form auth values directly (no save required)
build-and-push / docker (push) Has been cancelled

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) <noreply@anthropic.com>
This commit is contained in:
dimon
2026-06-02 22:04:05 +08:00
parent e696537fe1
commit f8d2c31658
3 changed files with 17 additions and 6 deletions
+8 -5
View File
@@ -526,8 +526,11 @@ async def test_notification(
server = data.server.strip() or s.default_ntfy_server server = data.server.strip() or s.default_ntfy_server
if not data.topic.strip(): if not data.topic.strip():
raise HTTPException(400, "Укажите тему") raise HTTPException(400, "Укажите тему")
# Use a custom server's own auth only if it matches the default; otherwise # Prefer auth typed in the form right now; fall back to saved defaults so
# fall back to the configured default-server credentials. # 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: try:
await ntfy.publish( await ntfy.publish(
server=server, server=server,
@@ -536,9 +539,9 @@ async def test_notification(
message="Тестовое уведомление — всё работает!", message="Тестовое уведомление — всё работает!",
tags="white_check_mark", tags="white_check_mark",
priority=3, priority=3,
token=s.default_ntfy_token, token=token,
username=s.default_ntfy_username, username=username,
password=s.default_ntfy_password, password=password,
) )
except Exception as exc: # noqa: BLE001 except Exception as exc: # noqa: BLE001
raise HTTPException(502, f"Не удалось отправить: {exc}") raise HTTPException(502, f"Не удалось отправить: {exc}")
+4
View File
@@ -78,6 +78,10 @@ class SettingsIn(BaseModel):
class TestIn(BaseModel): class TestIn(BaseModel):
server: str = "" server: str = ""
topic: 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): class PreviewIn(BaseModel):
+5 -1
View File
@@ -435,7 +435,11 @@ $("#test-btn").onclick = async () => {
if (!topic) { toast(t("toast.needTestTopic"), "err"); return; } if (!topic) { toast(t("toast.needTestTopic"), "err"); return; }
try { try {
const r = await api("POST", "/api/test", { 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 })); toast(t("toast.sentTo", { dest: r.sent_to }));
} catch (err) { toast(err.message, "err"); } } catch (err) { toast(err.message, "err"); }