This commit is contained in:
2026-10-27 22:55:36 +08:00
parent 1231251ea4
commit 1f6cd63815
5 changed files with 203 additions and 23 deletions
+27
View File
@@ -71,6 +71,32 @@ func (h *Handler) Info(c *gin.Context) {
response.OK(c, f)
}
// List 分页列表查询文件(后台文件管理栏目使用)。支持 query:keyword(原始/落盘文件名)、
// uploader_type、uploader_id、page、size。
func (h *Handler) List(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
keyword := c.Query("keyword")
typ := c.Query("uploader_type")
var uid uint64
if v := c.Query("uploader_id"); v != "" {
uid, _ = strconv.ParseUint(v, 10, 64)
}
list, total, err := h.svc.List(c.Request.Context(), filesvc.ListReq{
UploaderType: typ,
UploaderID: uid,
Keyword: keyword,
Page: page,
Size: size,
})
if err != nil {
c.Error(err)
return
}
response.OK(c, gin.H{"list": list, "total": total, "page": page, "size": size})
}
// Raw 以流形式返回文件内容,按 MIME 设置 Content-Type,供预览/下载。
func (h *Handler) Raw(c *gin.Context) {
id, ok := parseID(c)
@@ -127,6 +153,7 @@ func parseID(c *gin.Context) (uint64, bool) {
func RegisterAdminUpload(g *gin.RouterGroup, h *Handler) {
rg := g.Group("/files")
{
rg.GET("", h.List)
rg.POST("/upload", h.Upload)
rg.GET("/:id", h.Info)
rg.GET("/:id/raw", h.Raw)