优化首页公告与轮播图
This commit is contained in:
@@ -48,6 +48,14 @@ func (h *Handler) Upload(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Handler) Object(c *gin.Context) {
|
||||
h.writeObject(c, false)
|
||||
}
|
||||
|
||||
func (h *Handler) PublicObject(c *gin.Context) {
|
||||
h.writeObject(c, true)
|
||||
}
|
||||
|
||||
func (h *Handler) writeObject(c *gin.Context, publicOnly bool) {
|
||||
if h.storage == nil {
|
||||
response.ServiceUnavailable(c, "文件存储未连接")
|
||||
return
|
||||
@@ -57,6 +65,10 @@ func (h *Handler) Object(c *gin.Context) {
|
||||
response.BadRequest(c, "文件 key 不正确")
|
||||
return
|
||||
}
|
||||
if publicOnly && !strings.HasPrefix(key, "home-banner/") {
|
||||
response.Error(c, http.StatusNotFound, "not_found", "文件不存在或暂不可访问")
|
||||
return
|
||||
}
|
||||
object, err := h.storage.Get(c.Request.Context(), key)
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusNotFound, "not_found", "文件不存在或暂不可访问")
|
||||
|
||||
Reference in New Issue
Block a user