fix: align admin behavior and Kratos integrations

This commit is contained in:
2026-08-14 14:14:51 +08:00
parent 8c4c6ba661
commit e0b0e1d8c8
123 changed files with 4334 additions and 1877 deletions
+15 -19
View File
@@ -3,6 +3,7 @@ package handler
import (
"strconv"
"kra/internal/biz"
"kra/internal/server/httpx"
servermiddleware "kra/internal/server/middleware"
"kra/internal/service"
@@ -32,7 +33,7 @@ func (h *Media) Upload(c *gin.Context) {
save := c.DefaultQuery("noSave", "0") == "0"
item, err := h.service.Upload(c.Request.Context(), claims.ID, header.Filename, header.Header.Get("Content-Type"), category, opened, save)
if err != nil {
httpx.Fail(c, "上传失败:"+err.Error())
httpx.Fail(c, "上传文件失败")
return
}
httpx.Write(c, httpx.CodeSuccess, gin.H{"file": item}, "上传成功")
@@ -44,7 +45,7 @@ func (h *Media) List(c *gin.Context) {
httpx.Fail(c, "参数错误")
return
}
items, total, err := h.service.MediaList(c.Request.Context(), req.Page, req.PageSize, req.Keyword, req.ClassID, req.Tag, req.UserID)
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})
if err != nil {
httpx.Fail(c, "获取失败")
return
@@ -58,10 +59,10 @@ func (h *Media) Delete(c *gin.Context) {
return
}
if err := h.service.Delete(c.Request.Context(), req.ID); err != nil {
httpx.Fail(c, "删除失败:"+err.Error())
httpx.Fail(c, "删除失败")
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "删除成功")
}
func (h *Media) DeleteMany(c *gin.Context) {
var req dto.IDsRequest
@@ -79,7 +80,7 @@ func (h *Media) DeleteMany(c *gin.Context) {
httpx.Write(c, httpx.CodeSuccess, gin.H{"failedIds": failed}, "部分文件删除失败")
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "批量删除成功")
}
func (h *Media) Find(c *gin.Context) {
id, _ := strconv.ParseUint(c.Query("id"), 10, 64)
@@ -88,7 +89,7 @@ func (h *Media) Find(c *gin.Context) {
httpx.Fail(c, "查询失败")
return
}
httpx.Write(c, httpx.CodeSuccess, item, "获取成功")
httpx.OKWithData(c, item)
}
func (h *Media) Rename(c *gin.Context) {
var req dto.RenameMediaRequest
@@ -100,7 +101,7 @@ func (h *Media) Rename(c *gin.Context) {
httpx.Fail(c, "编辑失败")
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "编辑成功")
}
func (h *Media) ImportURLs(c *gin.Context) {
var req []dto.ImportMediaRequest
@@ -108,16 +109,11 @@ func (h *Media) ImportURLs(c *gin.Context) {
httpx.Fail(c, "参数错误")
return
}
claims := servermiddleware.Claims(c)
if claims == nil {
httpx.Fail(c, "未登录")
if err := h.service.ImportURLRequests(c.Request.Context(), req); err != nil {
httpx.Fail(c, "导入URL失败")
return
}
if err := h.service.ImportURLRequests(c.Request.Context(), claims.ID, req); err != nil {
httpx.Fail(c, "导入失败")
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "导入URL成功")
}
func (h *Media) Storage(c *gin.Context) {
var req dto.StorageListRequest
@@ -148,10 +144,10 @@ func (h *Media) SaveCategory(c *gin.Context) {
return
}
if err := h.service.SaveCategoryRequest(c.Request.Context(), &req); err != nil {
httpx.Fail(c, err.Error())
httpx.Fail(c, "创建/更新失败:"+err.Error())
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "创建/更新成功")
}
func (h *Media) DeleteCategory(c *gin.Context) {
var req dto.IDRequest
@@ -160,10 +156,10 @@ func (h *Media) DeleteCategory(c *gin.Context) {
return
}
if err := h.service.DeleteCategory(c.Request.Context(), req.ID); err != nil {
httpx.Fail(c, err.Error())
httpx.Fail(c, "删除失败")
return
}
httpx.OK(c)
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "删除成功")
}
func (h *Media) InitUpload(c *gin.Context) {