From 9d319cfa2d85853086a66bcfb6697340d41ad1cd Mon Sep 17 00:00:00 2001 From: erio Date: Mon, 13 Apr 2026 21:54:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20batch=202=20audit=20fixes=20=E2=80=94=20?= =?UTF-8?q?diffSettings=20notify=20fields,=20slog=20migration,=20frontend?= =?UTF-8?q?=20constants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit H5: diffSettings now tracks 5 balance/quota notify fields in audit log M15: log.Printf audit log migrated to slog.Info, removed "log" import M14: New frontend/src/constants/account.ts with shared constants QuotaNotifyToggle.vue uses QUOTA_THRESHOLD_TYPE_FIXED/PERCENTAGE L2: UsageTable.vue uses BILLING_MODE_TOKEN/IMAGE from billingMode.ts --- backend/cmd/server/VERSION | 2 +- .../internal/handler/admin/setting_handler.go | 41 +++++++++++++++---- .../components/account/QuotaNotifyToggle.vue | 12 +++--- .../src/components/admin/usage/UsageTable.vue | 8 ++-- frontend/src/constants/account.ts | 10 +++++ 5 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 frontend/src/constants/account.ts diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index 0ac4459d..bc34277a 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.110.47 +0.1.110.48 diff --git a/backend/internal/handler/admin/setting_handler.go b/backend/internal/handler/admin/setting_handler.go index bc6d183c..0c1606ea 100644 --- a/backend/internal/handler/admin/setting_handler.go +++ b/backend/internal/handler/admin/setting_handler.go @@ -5,11 +5,10 @@ import ( "encoding/hex" "encoding/json" "fmt" - "log" + "log/slog" "net/http" "regexp" "strings" - "time" "github.com/Wei-Shaw/sub2api/internal/config" "github.com/Wei-Shaw/sub2api/internal/handler/dto" @@ -1120,11 +1119,11 @@ func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.Sys subject, _ := middleware.GetAuthSubjectFromContext(c) role, _ := middleware.GetUserRoleFromContext(c) - log.Printf("AUDIT: settings updated at=%s user_id=%d role=%s changed=%v", - time.Now().UTC().Format(time.RFC3339), - subject.UserID, - role, - changed, + slog.Info("settings updated", + "audit", true, + "user_id", subject.UserID, + "role", role, + "changed", changed, ) } @@ -1358,6 +1357,22 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings, if before.EnableCCHSigning != after.EnableCCHSigning { changed = append(changed, "enable_cch_signing") } + // Balance & quota notification + if before.BalanceLowNotifyEnabled != after.BalanceLowNotifyEnabled { + changed = append(changed, "balance_low_notify_enabled") + } + if before.BalanceLowNotifyThreshold != after.BalanceLowNotifyThreshold { + changed = append(changed, "balance_low_notify_threshold") + } + if before.BalanceLowNotifyRechargeURL != after.BalanceLowNotifyRechargeURL { + changed = append(changed, "balance_low_notify_recharge_url") + } + if before.AccountQuotaNotifyEnabled != after.AccountQuotaNotifyEnabled { + changed = append(changed, "account_quota_notify_enabled") + } + if !equalNotifyEmailEntries(before.AccountQuotaNotifyEmails, after.AccountQuotaNotifyEmails) { + changed = append(changed, "account_quota_notify_emails") + } return changed } @@ -1414,6 +1429,18 @@ func equalIntSlice(a, b []int) bool { return true } +func equalNotifyEmailEntries(a, b []service.NotifyEmailEntry) bool { + if len(a) != len(b) { + return false + } + for i := range a { + if a[i].Email != b[i].Email || a[i].Verified != b[i].Verified || a[i].Disabled != b[i].Disabled { + return false + } + } + return true +} + // TestSMTPRequest 测试SMTP连接请求 type TestSMTPRequest struct { SMTPHost string `json:"smtp_host"` diff --git a/frontend/src/components/account/QuotaNotifyToggle.vue b/frontend/src/components/account/QuotaNotifyToggle.vue index 0548f661..954d0929 100644 --- a/frontend/src/components/account/QuotaNotifyToggle.vue +++ b/frontend/src/components/account/QuotaNotifyToggle.vue @@ -1,4 +1,6 @@