refactor(storage): move file management routes from user to admin namespace

- Remove file list, stats, download, and deletion routes from '/api/v1/upload'
- Move these endpoints under '/api/v1/admin/uploads'
- Remove user-specific filtering from files query and statistics to aggregate system-wide uploads by default
- Allow admins to bypass ownership check when downloading private files
- Update backend unit tests, Swagger documentation, and frontend service client and components
This commit is contained in:
ryan
2026-06-13 16:04:21 +08:00
parent dbabe8b8d7
commit 8b19ffed90
13 changed files with 908 additions and 818 deletions
+299 -280
View File
@@ -2618,6 +2618,258 @@ const docTemplate = `{
}
}
},
"/api/v1/admin/uploads": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "分页获取系统上传的文件列表,支持文件名关键词、业务类型、扩展名、上传用户ID过滤",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "获取文件列表",
"parameters": [
{
"type": "integer",
"description": "页码(默认 1)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量(默认 20,最大 100)",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "文件名关键词(模糊匹配)",
"name": "keyword",
"in": "query"
},
{
"type": "string",
"description": "业务分类过滤",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "扩展名过滤",
"name": "extension",
"in": "query"
},
{
"type": "integer",
"format": "int64",
"description": "上传用户 ID",
"name": "user_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/upload.listFilesResponse"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/uploads/download/batch": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "传入多个文件 ID,后台实时将其打包压缩为 ZIP 流并输出,自动处理文件名重复冲突",
"consumes": [
"application/json"
],
"produces": [
"application/octet-stream"
],
"tags": [
"admin"
],
"summary": "批量打包下载",
"parameters": [
{
"description": "包含文件 ID 数组 of string 的请求体",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/upload.batchDownloadRequest"
}
}
],
"responses": {
"200": {
"description": "成功下载打包后的 ZIP",
"schema": {
"type": "file"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "打包失败",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/uploads/download/{id}": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "根据文件 ID 获取文件,以附件形式 (Attachment) 强制开启客户端浏览器下载",
"produces": [
"application/octet-stream"
],
"tags": [
"admin"
],
"summary": "下载单文件",
"parameters": [
{
"type": "string",
"description": "文件 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "图片质量 (low, medium, high, origin),默认为 origin",
"name": "quality",
"in": "query"
}
],
"responses": {
"200": {
"description": "成功下载文件",
"schema": {
"type": "file"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"404": {
"description": "文件不存在",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/uploads/stats": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "返回系统级的总文件数、占用大小、最近 7 天新增趋势、文件类型/格式分布等数据",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "获取文件统计数据",
"responses": {
"200": {
"description": "获取成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/upload.fileStatsResponse"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无管理员权限",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/uploads/types": {
"get": {
"security": [
@@ -2676,6 +2928,52 @@ const docTemplate = `{
}
}
},
"/api/v1/admin/uploads/{id}": {
"delete": {
"security": [
{
"SessionCookie": []
}
],
"description": "将文件状态置为 deleted(软删除),不会立即清理底层存储对象",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "删除文件",
"parameters": [
{
"type": "string",
"description": "文件 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无权操作",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"404": {
"description": "文件不存在",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/admin/users": {
"get": {
"security": [
@@ -3646,285 +3944,6 @@ const docTemplate = `{
}
}
},
"/api/v1/upload/download/batch": {
"post": {
"security": [
{
"SessionCookie": []
}
],
"description": "传入多个文件 ID,后台实时将其打包压缩为 ZIP 流并输出,自动处理文件名重复冲突",
"consumes": [
"application/json"
],
"produces": [
"application/octet-stream"
],
"tags": [
"upload"
],
"summary": "批量打包下载",
"parameters": [
{
"description": "包含文件 ID 数组的请求体",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/upload.batchDownloadRequest"
}
}
],
"responses": {
"200": {
"description": "成功下载打包后的 ZIP",
"schema": {
"type": "file"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "打包失败",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/upload/download/{id}": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "根据文件 ID 获取文件,以附件形式 (Attachment) 强制开启客户端浏览器下载",
"produces": [
"application/octet-stream"
],
"tags": [
"upload"
],
"summary": "下载单文件",
"parameters": [
{
"type": "string",
"description": "文件 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "图片质量 (low, medium, high, origin),默认为 origin",
"name": "quality",
"in": "query"
}
],
"responses": {
"200": {
"description": "成功下载文件",
"schema": {
"type": "file"
}
},
"400": {
"description": "参数错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"404": {
"description": "文件不存在",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "服务内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/upload/my": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "分页获取当前登录用户上传的文件,支持文件名关键词、业务类型、扩展名过滤",
"produces": [
"application/json"
],
"tags": [
"upload"
],
"summary": "获取我的文件列表",
"parameters": [
{
"type": "integer",
"description": "页码(默认 1)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量(默认 20,最大 100)",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "文件名关键词(模糊匹配)",
"name": "keyword",
"in": "query"
},
{
"type": "string",
"description": "业务分类过滤",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "扩展名过滤",
"name": "extension",
"in": "query"
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/upload.listMyFilesResponse"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/upload/stats": {
"get": {
"security": [
{
"SessionCookie": []
}
],
"description": "返回当前用户的总文件数、占用大小、最近 7 天新增趋势、文件类型/格式分布等数据",
"produces": [
"application/json"
],
"tags": [
"upload"
],
"summary": "获取文件统计数据",
"responses": {
"200": {
"description": "获取成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/util.ResponseAny"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/upload.fileStatsResponse"
}
}
}
]
}
},
"401": {
"description": "未登录",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/upload/{id}": {
"delete": {
"security": [
{
"SessionCookie": []
}
],
"description": "将文件状态置为 deleted(软删除),不会立即清理底层存储对象",
"produces": [
"application/json"
],
"tags": [
"upload"
],
"summary": "删除文件",
"parameters": [
{
"type": "string",
"description": "文件 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"403": {
"description": "无权操作",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
},
"404": {
"description": "文件不存在",
"schema": {
"$ref": "#/definitions/util.ResponseAny"
}
}
}
}
},
"/api/v1/user-info": {
"get": {
"security": [
@@ -5983,7 +6002,7 @@ const docTemplate = `{
}
}
},
"upload.listMyFilesResponse": {
"upload.listFilesResponse": {
"type": "object",
"properties": {
"items": {