From c0ece054a00c45d12c064923420ad800a258f49c Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Sat, 16 May 2026 04:13:05 -0700 Subject: [PATCH] x --- internal/middleware/deviceMiddleware.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/middleware/deviceMiddleware.go b/internal/middleware/deviceMiddleware.go index 935c1c6..2ac7a27 100644 --- a/internal/middleware/deviceMiddleware.go +++ b/internal/middleware/deviceMiddleware.go @@ -31,6 +31,8 @@ const ( ctxDecryptedQueryKey = "decrypted_query" ctxEncryptedBodyKey = "encrypted_request_body" ctxDecryptedBodyKey = "decrypted_request_body" + + deviceDecryptSkipPathPublicFileUpload = "/v1/public/file/upload" ) func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) { @@ -70,6 +72,14 @@ func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) { } rw := NewResponseWriter(c, srvCtx) + if shouldSkipDeviceRequestDecrypt(c) { + c.Set(ctxDeviceDecryptStatusKey, "skipped") + c.Set(ctxDeviceDecryptReasonKey, "multipart_upload_passthrough") + c.Writer = rw + c.Next() + rw.FlushAbort() + return + } if !rw.Decrypt() { c.Set(ctxDeviceDecryptStatusKey, "failed") if _, exists := c.Get(ctxDeviceDecryptReasonKey); !exists { @@ -85,6 +95,13 @@ func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) { } } +func shouldSkipDeviceRequestDecrypt(c *gin.Context) bool { + if c.Request.URL.Path != deviceDecryptSkipPathPublicFileUpload { + return false + } + return strings.HasPrefix(strings.ToLower(strings.TrimSpace(c.GetHeader("Content-Type"))), "multipart/form-data") +} + func NewResponseWriter(c *gin.Context, srvCtx *svc.ServiceContext) (rw *ResponseWriter) { rw = &ResponseWriter{ c: c,