From db6681f448948156a494f4043b22e02c45810c39 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Mon, 21 Nov 2022 19:09:37 +0800 Subject: [PATCH] fix(avatar): add default cache max age for avatar response --- service/user/setting.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/user/setting.go b/service/user/setting.go index 8d7f619..4387df2 100644 --- a/service/user/setting.go +++ b/service/user/setting.go @@ -76,6 +76,8 @@ type ThemeChose struct { Theme string `json:"theme" binding:"required,hexcolor|rgb|rgba|hsl"` } +const avatarMaxAge = 3600 + // Update 更新主题设定 func (service *ThemeChose) Update(c *gin.Context, user *model.User) serializer.Response { user.OptionsSerialized.PreferredTheme = service.Theme @@ -194,6 +196,8 @@ func (service *AvatarService) Get(c *gin.Context) serializer.Response { "l": model.GetSettingByName("avatar_size_l"), } + c.Header("Cache-Control", fmt.Sprintf("max-age=%d", avatarMaxAge)) + // Gravatar 头像重定向 if user.Avatar == "gravatar" { server := model.GetSettingByName("gravatar_server")