From 6d5a1410965dca3ae1f8930d4cd9a08bdc85349b Mon Sep 17 00:00:00 2001 From: ShukeBta <272197458+ShukeBta@users.noreply.github.com> Date: Sat, 27 Jun 2026 12:20:05 +0800 Subject: [PATCH] split cloud qr handlers --- internal/handler/cloud.go | 39 ---------------------------- internal/handler/cloud_qr.go | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 39 deletions(-) create mode 100644 internal/handler/cloud_qr.go diff --git a/internal/handler/cloud.go b/internal/handler/cloud.go index 9156e89..5ee7ea8 100644 --- a/internal/handler/cloud.go +++ b/internal/handler/cloud.go @@ -297,42 +297,3 @@ func cloudMountLibraryName(typ, dir, displayDir string) string { } return base } - -// cloud115QRStartHandler begins a 115 QR-code login and returns the session + -// QR image URL for the frontend to render. -func cloud115QRStartHandler(svc *service.Container) gin.HandlerFunc { - return func(c *gin.Context) { - if c.Param("type") != cloud.Type115 { - c.JSON(http.StatusBadRequest, gin.H{"error": "qr login is only supported for 115"}) - return - } - sess, err := cloud.QRStart(c.Request.Context(), nil) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - return - } - c.JSON(http.StatusOK, sess) - } -} - -// cloud115QRPollHandler polls a 115 QR session; on confirmation it returns the -// session cookie so the frontend can save it as the storage credential. -func cloud115QRPollHandler(svc *service.Container) gin.HandlerFunc { - return func(c *gin.Context) { - if c.Param("type") != cloud.Type115 { - c.JSON(http.StatusBadRequest, gin.H{"error": "qr login is only supported for 115"}) - return - } - var sess cloud.QRSession - if err := c.ShouldBindJSON(&sess); err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) - return - } - st, err := cloud.QRPoll(c.Request.Context(), nil, &sess) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - return - } - c.JSON(http.StatusOK, st) - } -} diff --git a/internal/handler/cloud_qr.go b/internal/handler/cloud_qr.go new file mode 100644 index 0000000..f04013d --- /dev/null +++ b/internal/handler/cloud_qr.go @@ -0,0 +1,49 @@ +package handler + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "github.com/ShukeBta/MediaStationGo/internal/service" + "github.com/ShukeBta/MediaStationGo/internal/service/cloud" +) + +// cloud115QRStartHandler begins a 115 QR-code login and returns the session + +// QR image URL for the frontend to render. +func cloud115QRStartHandler(svc *service.Container) gin.HandlerFunc { + return func(c *gin.Context) { + if c.Param("type") != cloud.Type115 { + c.JSON(http.StatusBadRequest, gin.H{"error": "qr login is only supported for 115"}) + return + } + sess, err := cloud.QRStart(c.Request.Context(), nil) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, sess) + } +} + +// cloud115QRPollHandler polls a 115 QR session; on confirmation it returns the +// session cookie so the frontend can save it as the storage credential. +func cloud115QRPollHandler(svc *service.Container) gin.HandlerFunc { + return func(c *gin.Context) { + if c.Param("type") != cloud.Type115 { + c.JSON(http.StatusBadRequest, gin.H{"error": "qr login is only supported for 115"}) + return + } + var sess cloud.QRSession + if err := c.ShouldBindJSON(&sess); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + st, err := cloud.QRPoll(c.Request.Context(), nil, &sess) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, st) + } +}