Skip to content

Commit a5d826c

Browse files
committed
feat(file): add ENV for skip the file access verification
1 parent 5cffab8 commit a5d826c

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

internal/base/middleware/visit_img_auth.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020
package middleware
2121

2222
import (
23-
"github.com/apache/answer/internal/base/constant"
24-
"github.com/gin-gonic/gin"
2523
"net/http"
24+
"os"
2625
"strings"
26+
27+
"github.com/apache/answer/internal/base/constant"
28+
"github.com/gin-gonic/gin"
2729
)
2830

2931
// VisitAuth when user visit the site image, check visit token. This only for private mode.
3032
func (am *AuthUserMiddleware) VisitAuth() gin.HandlerFunc {
3133
return func(ctx *gin.Context) {
34+
if len(os.Getenv("SKIP_FILE_ACCESS_VERIFY")) > 0 {
35+
ctx.Next()
36+
return
37+
}
3238
// If visit brand image, no need to check visit token. Because the brand image is public.
3339
if strings.HasPrefix(ctx.Request.URL.Path, "/uploads/branding/") {
3440
ctx.Next()

internal/controller/user_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,5 +726,5 @@ func (uc *UserController) setVisitCookies(ctx *gin.Context, visitToken string, f
726726
return
727727
}
728728
ctx.SetCookie(constant.UserVisitCookiesCacheKey,
729-
visitToken, constant.UserVisitCacheTime, "/", parsedURL.Host, true, true)
729+
visitToken, constant.UserVisitCacheTime, "/", parsedURL.Hostname(), true, true)
730730
}

0 commit comments

Comments
 (0)