From bbedb3a488a12132f1a3978a8bbc49bae008664f Mon Sep 17 00:00:00 2001 From: alimy Date: Wed, 8 Jun 2022 21:14:14 +0800 Subject: [PATCH] fixed change avatar failure error --- internal/routers/api/api.go | 4 +++- internal/routers/api/user.go | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/routers/api/api.go b/internal/routers/api/api.go index f71491a1..9049e110 100644 --- a/internal/routers/api/api.go +++ b/internal/routers/api/api.go @@ -6,9 +6,11 @@ import ( ) var ( - objectStorage core.ObjectStorageService + objectStorage core.ObjectStorageService + attachmentChecker core.AttachmentCheckService ) func Initialize() { objectStorage = dao.NewObjectStorageService() + attachmentChecker = dao.NewAttachmentCheckerService() } diff --git a/internal/routers/api/user.go b/internal/routers/api/user.go index 30b1da97..30f53155 100644 --- a/internal/routers/api/user.go +++ b/internal/routers/api/user.go @@ -3,7 +3,6 @@ package api import ( "fmt" "net/http" - "strings" "unicode/utf8" "github.com/gin-gonic/gin" @@ -204,7 +203,7 @@ func ChangeAvatar(c *gin.Context) { user = u.(*model.User) } - if strings.Index(param.Avatar, "https://"+global.AliOSSSetting.Domain) != 0 { + if err := attachmentChecker.Check(param.Avatar); err != nil { response.ToErrorResponse(errcode.InvalidParams) return }