Files
FileRelay/docs/swagger.json
hxuanyu fe656fb298 新增配置管理功能及多存储支持
- 添加管理员端 API,用于获取和更新完整配置。
- 添加公共端 API,用于获取非敏感配置信息。
- 增加本地存储(LocalStorage)、S3(S3Storage)、和 WebDAV(WebDAVStorage)存储类型的实现。
- 支持热更新存储配置和保存配置文件至磁盘。
- 更新 Swagger 文档以包含新接口定义。
2026-01-14 14:15:20 +08:00

1294 lines
42 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"swagger": "2.0",
"info": {
"description": "自托管的文件暂存柜后端系统 API 文档",
"title": "文件暂存柜 API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"basePath": "/",
"paths": {
"/admin/api-tokens": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "获取系统中所有 API Token 的详详信息(不包含哈希)",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "获取 API Token 列表",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/model.APIToken"
}
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
},
"post": {
"security": [
{
"AdminAuth": []
}
],
"description": "创建一个新的 API Token返回原始 Token仅显示一次",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "创建 API Token",
"parameters": [
{
"description": "Token 信息",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/admin.CreateTokenRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/admin.CreateTokenResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/api-tokens/{id}": {
"delete": {
"security": [
{
"AdminAuth": []
}
],
"description": "根据 ID 永久删除 API Token",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "删除 API Token",
"parameters": [
{
"type": "integer",
"description": "Token ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/api-tokens/{id}/revoke": {
"post": {
"security": [
{
"AdminAuth": []
}
],
"description": "将 API Token 标记为已撤销,使其失效但保留记录",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "撤销 API Token",
"parameters": [
{
"type": "integer",
"description": "Token ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/batches": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "分页查询所有文件批次,支持按状态过滤和取件码模糊搜索",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "获取批次列表",
"parameters": [
{
"type": "integer",
"description": "页码 (默认 1)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量 (默认 20)",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "状态 (active/expired/deleted)",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "取件码 (模糊搜索)",
"name": "pickup_code",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/admin.ListBatchesResponse"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/batches/{batch_id}": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "根据批次 ID 获取批次信息及关联的文件列表",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "获取批次详情",
"parameters": [
{
"type": "string",
"description": "批次 ID (UUID)",
"name": "batch_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.FileBatch"
}
}
}
]
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
},
"put": {
"security": [
{
"AdminAuth": []
}
],
"description": "允许修改备注、过期策略、最大下载次数、状态等",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "修改批次信息",
"parameters": [
{
"type": "string",
"description": "批次 ID (UUID)",
"name": "batch_id",
"in": "path",
"required": true
},
{
"description": "修改内容",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/admin.UpdateBatchRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.FileBatch"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
},
"delete": {
"security": [
{
"AdminAuth": []
}
],
"description": "标记批次为已删除,并物理删除关联的存储文件",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "删除批次",
"parameters": [
{
"type": "string",
"description": "批次 ID (UUID)",
"name": "batch_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/config": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "获取系统的完整配置文件内容(仅管理员)",
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "获取完整配置",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/config.Config"
}
}
}
},
"put": {
"security": [
{
"AdminAuth": []
}
],
"description": "更新系统的配置文件内容(仅管理员)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "更新配置",
"parameters": [
{
"description": "新配置内容",
"name": "config",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/config.Config"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/admin/login": {
"post": {
"description": "通过密码换取 JWT Token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin"
],
"summary": "管理员登录",
"parameters": [
{
"description": "登录请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/admin.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/admin.LoginResponse"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/api/batches": {
"post": {
"description": "上传一个或多个文件并创建一个提取批次",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"Public"
],
"summary": "上传文件",
"parameters": [
{
"type": "file",
"description": "文件列表",
"name": "files",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "备注",
"name": "remark",
"in": "formData"
},
{
"type": "string",
"description": "过期类型 (time/download/permanent)",
"name": "expire_type",
"in": "formData"
},
{
"type": "integer",
"description": "过期天数 (针对 time 类型)",
"name": "expire_days",
"in": "formData"
},
{
"type": "integer",
"description": "最大下载次数 (针对 download 类型)",
"name": "max_downloads",
"in": "formData"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/public.UploadResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/api/batches/text": {
"post": {
"description": "中转一段长文本内容并创建一个提取批次",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Public"
],
"summary": "发送长文本",
"parameters": [
{
"description": "文本内容及配置",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/public.UploadTextRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/public.UploadResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/api/batches/{pickup_code}": {
"get": {
"description": "根据取件码获取文件批次详详情和文件列表",
"produces": [
"application/json"
],
"tags": [
"Public"
],
"summary": "获取批次信息",
"parameters": [
{
"type": "string",
"description": "取件码",
"name": "pickup_code",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/public.PickupResponse"
}
}
}
]
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/api/batches/{pickup_code}/download": {
"get": {
"description": "根据取件码将批次内的所有文件打包为 ZIP 格式一次性下载",
"produces": [
"application/zip"
],
"tags": [
"Public"
],
"summary": "批量下载文件",
"parameters": [
{
"type": "string",
"description": "取件码",
"name": "pickup_code",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "file"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
},
"/api/config": {
"get": {
"description": "获取前端展示所需的非敏感配置数据",
"produces": [
"application/json"
],
"tags": [
"Public"
],
"summary": "获取公共配置",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/model.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/public.PublicConfig"
}
}
}
]
}
}
}
}
},
"/api/files/{file_id}/download": {
"get": {
"description": "根据文件 ID 下载单个文件",
"produces": [
"application/octet-stream"
],
"tags": [
"Public"
],
"summary": "下载单个文件",
"parameters": [
{
"type": "string",
"description": "文件 ID (UUID)",
"name": "file_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "file"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/model.Response"
}
},
"410": {
"description": "Gone",
"schema": {
"$ref": "#/definitions/model.Response"
}
}
}
}
}
},
"definitions": {
"admin.CreateTokenRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"expire_at": {
"type": "string"
},
"name": {
"type": "string",
"example": "Test Token"
},
"scope": {
"type": "string",
"example": "upload,pickup"
}
}
},
"admin.CreateTokenResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.APIToken"
},
"token": {
"type": "string"
}
}
},
"admin.ListBatchesResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/model.FileBatch"
}
},
"page": {
"type": "integer"
},
"page_size": {
"type": "integer"
},
"total": {
"type": "integer"
}
}
},
"admin.LoginRequest": {
"type": "object",
"required": [
"password"
],
"properties": {
"password": {
"type": "string",
"example": "admin"
}
}
},
"admin.LoginResponse": {
"type": "object",
"properties": {
"token": {
"type": "string"
}
}
},
"admin.UpdateBatchRequest": {
"type": "object",
"properties": {
"expire_at": {
"type": "string"
},
"expire_type": {
"type": "string"
},
"max_downloads": {
"type": "integer"
},
"remark": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"config.APITokenConfig": {
"type": "object",
"properties": {
"allowAdminAPI": {
"type": "boolean"
},
"enabled": {
"type": "boolean"
},
"maxTokens": {
"type": "integer"
}
}
},
"config.Config": {
"type": "object",
"properties": {
"apitoken": {
"$ref": "#/definitions/config.APITokenConfig"
},
"database": {
"$ref": "#/definitions/config.DatabaseConfig"
},
"security": {
"$ref": "#/definitions/config.SecurityConfig"
},
"site": {
"$ref": "#/definitions/config.SiteConfig"
},
"storage": {
"$ref": "#/definitions/config.StorageConfig"
},
"upload": {
"$ref": "#/definitions/config.UploadConfig"
}
}
},
"config.DatabaseConfig": {
"type": "object",
"properties": {
"path": {
"type": "string"
}
}
},
"config.SecurityConfig": {
"type": "object",
"properties": {
"adminPasswordHash": {
"type": "string"
},
"jwtsecret": {
"type": "string"
},
"pickupCodeLength": {
"type": "integer"
},
"pickupFailLimit": {
"type": "integer"
}
}
},
"config.SiteConfig": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"config.StorageConfig": {
"type": "object",
"properties": {
"local": {
"type": "object",
"properties": {
"path": {
"type": "string"
}
}
},
"s3": {
"type": "object",
"properties": {
"accessKey": {
"type": "string"
},
"bucket": {
"type": "string"
},
"endpoint": {
"type": "string"
},
"region": {
"type": "string"
},
"secretKey": {
"type": "string"
},
"useSSL": {
"type": "boolean"
}
}
},
"type": {
"type": "string"
},
"webDAV": {
"type": "object",
"properties": {
"password": {
"type": "string"
},
"root": {
"type": "string"
},
"url": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
}
},
"config.UploadConfig": {
"type": "object",
"properties": {
"maxBatchFiles": {
"type": "integer"
},
"maxFileSizeMB": {
"type": "integer"
},
"maxRetentionDays": {
"type": "integer"
}
}
},
"model.APIToken": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"expire_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"last_used_at": {
"type": "string"
},
"name": {
"type": "string"
},
"revoked": {
"type": "boolean"
},
"scope": {
"type": "string"
}
}
},
"model.FileBatch": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"created_at": {
"type": "string"
},
"download_count": {
"type": "integer"
},
"expire_at": {
"type": "string"
},
"expire_type": {
"description": "time / download / permanent",
"type": "string"
},
"file_items": {
"type": "array",
"items": {
"$ref": "#/definitions/model.FileItem"
}
},
"id": {
"type": "string"
},
"max_downloads": {
"type": "integer"
},
"pickup_code": {
"type": "string"
},
"remark": {
"type": "string"
},
"status": {
"description": "active / expired / deleted",
"type": "string"
},
"type": {
"description": "file / text",
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"model.FileItem": {
"type": "object",
"properties": {
"batch_id": {
"type": "string"
},
"created_at": {
"type": "string"
},
"id": {
"type": "string"
},
"mime_type": {
"type": "string"
},
"original_name": {
"type": "string"
},
"size": {
"type": "integer"
},
"storage_path": {
"type": "string"
}
}
},
"model.Response": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"data": {},
"msg": {
"type": "string",
"example": "success"
}
}
},
"public.PickupResponse": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"download_count": {
"type": "integer"
},
"expire_at": {
"type": "string"
},
"expire_type": {
"type": "string"
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/model.FileItem"
}
},
"max_downloads": {
"type": "integer"
},
"remark": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"public.PublicConfig": {
"type": "object",
"properties": {
"api_token": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"site": {
"$ref": "#/definitions/config.SiteConfig"
},
"upload": {
"$ref": "#/definitions/config.UploadConfig"
}
}
},
"public.UploadResponse": {
"type": "object",
"properties": {
"batch_id": {
"type": "string"
},
"expire_at": {
"type": "string"
},
"pickup_code": {
"type": "string"
}
}
},
"public.UploadTextRequest": {
"type": "object",
"required": [
"content"
],
"properties": {
"content": {
"type": "string",
"example": "这是一段长文本内容..."
},
"expire_days": {
"type": "integer",
"example": 7
},
"expire_type": {
"type": "string",
"example": "time"
},
"max_downloads": {
"type": "integer",
"example": 5
},
"remark": {
"type": "string",
"example": "文本备注"
}
}
}
},
"securityDefinitions": {
"AdminAuth": {
"description": "Type \"Bearer \u003cyour-jwt-token\u003e\" to authenticate.",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}