From 5693beea4626ff1780a101f0cf46148ecaa833c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=A8=E9=9B=AA?= Date: Tue, 18 Aug 2026 09:46:07 +0800 Subject: [PATCH] fix: keep legacy subscription URLs working --- backend/internal/router/subscription.go | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/backend/internal/router/subscription.go b/backend/internal/router/subscription.go index a403b76..a32deec 100644 --- a/backend/internal/router/subscription.go +++ b/backend/internal/router/subscription.go @@ -13,8 +13,8 @@ import ( "gorm.io/gorm" ) -func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *config.Config) { - handler := func(c *gin.Context) { +func subscriptionHandler(db *gorm.DB, cfg *config.Config) gin.HandlerFunc { + return func(c *gin.Context) { if db == nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "database is not configured"}) return @@ -83,20 +83,22 @@ func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *co c.Header("Cache-Control", "no-store") c.Data(http.StatusOK, "text/plain; charset=utf-8", converted) } +} - // Keep the current canonical API path and accept legacy subscription URLs - // so existing clients do not start returning 404 after an upgrade. +func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *config.Config) { + handler := subscriptionHandler(db, cfg) api.GET("/client/sub/:token", handler) api.GET("/client/sub/:token/", handler) +} - // Legacy paths are registered on the engine root by SetupRouterWithDeps. - // The aliases below are attached to the same handler through the parent - // router group so all subscription URLs share exactly the same behavior. - root := api.Group("/") - root.GET("/sub/:token", handler) - root.GET("/sub/:token/", handler) - root.GET("/api/client/sub/:token", handler) - root.GET("/api/client/sub/:token/", handler) +// RegisterLegacySubscriptionRoutes keeps subscription links generated by +// older releases working after upgrading to the /api/v1 route layout. +func RegisterLegacySubscriptionRoutes(r *gin.Engine, db *gorm.DB, cfg *config.Config) { + handler := subscriptionHandler(db, cfg) + r.GET("/sub/:token", handler) + r.GET("/sub/:token/", handler) + r.GET("/api/client/sub/:token", handler) + r.GET("/api/client/sub/:token/", handler) } func writeSubInfo(c *gin.Context, db *gorm.DB, tok string) {