From 1b3ae4494041dfad318c868490da120a10536560 Mon Sep 17 00:00:00 2001 From: sagitchu Date: Fri, 3 Apr 2026 17:37:05 +0800 Subject: [PATCH] feat: show license expiry date when commercial license is activated --- go-backend/internal/http/handler/handler.go | 9 +++++++++ go-backend/internal/http/handler/jobs.go | 7 +++++++ go-backend/internal/license/keygen.go | 5 ++++- vite-frontend/src/pages/config.tsx | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/go-backend/internal/http/handler/handler.go b/go-backend/internal/http/handler/handler.go index 133b44e..8c6a1e8 100644 --- a/go-backend/internal/http/handler/handler.go +++ b/go-backend/internal/http/handler/handler.go @@ -871,6 +871,15 @@ func (h *Handler) licenseActivate(w http.ResponseWriter, r *http.Request) { return } + expiry := valResp.Data.Attributes.Expiry + if expiry == "" { + expiry = "never" + } + if err := h.repo.UpsertConfig("license_expiry", expiry, now); err != nil { + response.WriteJSON(w, response.Err(-2, err.Error())) + return + } + response.WriteJSON(w, response.OKEmpty()) } diff --git a/go-backend/internal/http/handler/jobs.go b/go-backend/internal/http/handler/jobs.go index 1e11182..70a8896 100644 --- a/go-backend/internal/http/handler/jobs.go +++ b/go-backend/internal/http/handler/jobs.go @@ -74,6 +74,13 @@ func (h *Handler) validateLicenseJob() { // License is invalid (e.g., revoked, suspended, expired). Downgrade the system. now := time.Now().UnixMilli() _ = h.repo.UpsertConfig("is_commercial", "false", now) + } else { + now := time.Now().UnixMilli() + expiry := valResp.Data.Attributes.Expiry + if expiry == "" { + expiry = "never" + } + _ = h.repo.UpsertConfig("license_expiry", expiry, now) } } diff --git a/go-backend/internal/license/keygen.go b/go-backend/internal/license/keygen.go index d38fc44..c94aeea 100644 --- a/go-backend/internal/license/keygen.go +++ b/go-backend/internal/license/keygen.go @@ -30,7 +30,10 @@ type ValidateResponse struct { Code string `json:"code"` } `json:"meta"` Data struct { - ID string `json:"id"` + ID string `json:"id"` + Attributes struct { + Expiry string `json:"expiry"` + } `json:"attributes"` } `json:"data"` } diff --git a/vite-frontend/src/pages/config.tsx b/vite-frontend/src/pages/config.tsx index 25c38fb..283d712 100644 --- a/vite-frontend/src/pages/config.tsx +++ b/vite-frontend/src/pages/config.tsx @@ -981,7 +981,7 @@ export default function ConfigPage() { variant="bordered" onChange={(e) => setLicenseKeyInput(e.target.value)} isDisabled={configs.is_commercial === "true"} - description={configs.is_commercial === "true" ? "已激活商业版授权" : "需商业授权才能修改站名、图标并隐藏页脚品牌"} + description={configs.is_commercial === "true" ? (configs.license_expiry && configs.license_expiry !== "never" ? `已激活商业版授权 (有效期至: ${new Date(configs.license_expiry).toLocaleDateString()})` : "已激活商业版授权 (永久有效)") : "需商业授权才能修改站名、图标并隐藏页脚品牌"} />