65 lines
3.1 KiB
Go
65 lines
3.1 KiB
Go
package v1
|
||
|
||
import "github.com/gogf/gf/v2/frame/g"
|
||
|
||
// ============================================================================
|
||
// 管理端附件管理契约(迭代-2026-09-29):upload / list / delete
|
||
//
|
||
// 所有上传(含用户端头像)都会登记到 attachments 表;本模块提供后台统一查看、
|
||
// 上传日期、删除。删除为「记录软删 + 文件本体按引用检查」:仍被头像/封面等引用
|
||
// 的文件只移除记录不删文件,返回 removed_file=false 说明这一点。
|
||
// ============================================================================
|
||
|
||
// AdminUploadReq 管理端上传(multipart/form-data,文件字段名 file,表单字段 scene=cover|attachment)
|
||
type AdminUploadReq struct {
|
||
g.Meta `path:"/admin/upload" method:"post" mime:"multipart/form-data" tags:"admin" summary:"管理端上传文件"`
|
||
Scene string `v:"required|in:cover,attachment#请指定上传场景|不支持的上传场景" json:"scene"`
|
||
}
|
||
type AdminUploadRes struct {
|
||
Id int64 `json:"id"` // 附件登记 id(0 = 登记跳过/失败,不影响文件可用)
|
||
Url string `json:"url"` // 绝对 URL(按 site.base_url 现拼,直接展示用)
|
||
Path string `json:"path"` // 相对路径(/static/...)—— 商品封面等库内只存这个
|
||
FileName string `json:"file_name"` // 原始文件名
|
||
Ext string `json:"ext"` // 扩展名(小写含点)
|
||
SizeBytes int64 `json:"size_bytes"` // 字节
|
||
}
|
||
|
||
// AdminAttachmentItem 附件列表项(响应 snake_case)
|
||
type AdminAttachmentItem struct {
|
||
Id int64 `json:"id"`
|
||
Scene string `json:"scene"` // avatar / cover / attachment
|
||
FileName string `json:"file_name"`
|
||
FilePath string `json:"file_path"`
|
||
Url string `json:"url"` // 绝对 URL(现拼)
|
||
Ext string `json:"ext"`
|
||
SizeBytes int64 `json:"size_bytes"`
|
||
Md5 string `json:"md5"`
|
||
UploaderId int64 `json:"uploader_id"`
|
||
UploaderType string `json:"uploader_type"` // admin / user
|
||
IsReferenced bool `json:"is_referenced"` // 是否仍被头像/封面/其他记录引用
|
||
IsImage bool `json:"is_image"` // 是否图片(可缩略预览)
|
||
CreatedAt string `json:"created_at"` // 上传日期
|
||
}
|
||
|
||
// AdminAttachmentListReq 附件列表
|
||
type AdminAttachmentListReq struct {
|
||
g.Meta `path:"/admin/attachment/list" method:"get" tags:"admin" summary:"附件列表"`
|
||
Keyword string `json:"keyword"` // 文件名模糊
|
||
Scene string `json:"scene"` // 空=全部;avatar/cover/attachment
|
||
Page int `json:"page"`
|
||
PageSize int `json:"pageSize"`
|
||
}
|
||
type AdminAttachmentListRes struct {
|
||
List []AdminAttachmentItem `json:"list"`
|
||
Total int `json:"total"`
|
||
}
|
||
|
||
// AdminAttachmentDeleteReq 删除附件(记录软删;文件本体无引用时才落盘删除)
|
||
type AdminAttachmentDeleteReq struct {
|
||
g.Meta `path:"/admin/attachment/delete" method:"post" tags:"admin" summary:"删除附件"`
|
||
Id int64 `v:"required" json:"id"`
|
||
}
|
||
type AdminAttachmentDeleteRes struct {
|
||
RemovedFile bool `json:"removed_file"` // false = 文件仍被引用,仅移除了登记记录
|
||
}
|