This commit is contained in:
2026-08-16 09:02:39 +08:00
parent c554152f4f
commit f7f6db8695
105 changed files with 2535 additions and 948 deletions
+27 -17
View File
@@ -25,7 +25,9 @@ func (h *Media) Upload(c *gin.Context) {
}
opened, err := header.Open()
if err != nil {
httpx.Fail(c, "读取文件失败")
// Let the upload service surface this as the generic upload
// failure; keep the endpoint message consistent.
httpx.Fail(c, "上传文件失败")
return
}
defer opened.Close()
@@ -41,8 +43,8 @@ func (h *Media) Upload(c *gin.Context) {
func (h *Media) List(c *gin.Context) {
var req dto.MediaListRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
items, total, err := h.service.MediaList(c.Request.Context(), biz.MediaFilter{Page: req.Page, PageSize: req.PageSize, Keyword: req.Keyword, CategoryID: req.ClassID, Tag: req.Tag, UserID: req.UserID, StartCreatedAt: req.StartCreatedAt, EndCreatedAt: req.EndCreatedAt, OrderKey: req.OrderKey, Desc: req.Desc})
@@ -54,8 +56,8 @@ func (h *Media) List(c *gin.Context) {
}
func (h *Media) Delete(c *gin.Context) {
var req dto.IDRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if err := h.service.Delete(c.Request.Context(), req.ID); err != nil {
@@ -66,8 +68,8 @@ func (h *Media) Delete(c *gin.Context) {
}
func (h *Media) DeleteMany(c *gin.Context) {
var req dto.IDsRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
failed := []uint{}
@@ -97,8 +99,8 @@ func (h *Media) Find(c *gin.Context) {
}
func (h *Media) Rename(c *gin.Context) {
var req dto.RenameMediaRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if err := h.service.Rename(c.Request.Context(), req.ID, req.Name); err != nil {
@@ -109,8 +111,8 @@ func (h *Media) Rename(c *gin.Context) {
}
func (h *Media) ImportURLs(c *gin.Context) {
var req []dto.ImportMediaRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if err := h.service.ImportURLRequests(c.Request.Context(), req); err != nil {
@@ -121,8 +123,8 @@ func (h *Media) ImportURLs(c *gin.Context) {
}
func (h *Media) Storage(c *gin.Context) {
var req dto.StorageListRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
items, next, more, err := h.service.Storage(c.Request.Context(), req.Prefix, req.Cursor, req.Limit)
@@ -143,7 +145,7 @@ func (h *Media) Categories(c *gin.Context) {
}
func (h *Media) SaveCategory(c *gin.Context) {
var req dto.CategoryRequest
if c.ShouldBindJSON(&req) != nil {
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, "参数错误")
return
}
@@ -169,10 +171,14 @@ func (h *Media) DeleteCategory(c *gin.Context) {
func (h *Media) InitUpload(c *gin.Context) {
claims := servermiddleware.Claims(c)
var req dto.InitUploadRequest
if claims == nil || c.ShouldBindJSON(&req) != nil {
if claims == nil {
httpx.Fail(c, "参数错误")
return
}
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if config := h.service.MediaConfig(); config.MaxFileSize > 0 && req.FileSize > config.MaxFileSize {
httpx.Fail(c, "文件超过大小上限")
return
@@ -195,7 +201,7 @@ func (h *Media) SaveChunk(c *gin.Context) {
}
opened, err := header.Open()
if err != nil {
httpx.Fail(c, "读取分片失败")
httpx.Fail(c, "分片读取失败")
return
}
defer opened.Close()
@@ -208,10 +214,14 @@ func (h *Media) SaveChunk(c *gin.Context) {
func (h *Media) CompleteUpload(c *gin.Context) {
claims := servermiddleware.Claims(c)
var req dto.CompleteUploadRequest
if claims == nil || c.ShouldBindJSON(&req) != nil {
if claims == nil {
httpx.Fail(c, "参数错误")
return
}
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
item, err := h.service.CompleteUpload(c.Request.Context(), claims.ID, req.UploadID)
if err != nil {
httpx.Fail(c, err.Error())