新增配置管理功能及多存储支持

- 添加管理员端 API,用于获取和更新完整配置。
- 添加公共端 API,用于获取非敏感配置信息。
- 增加本地存储(LocalStorage)、S3(S3Storage)、和 WebDAV(WebDAVStorage)存储类型的实现。
- 支持热更新存储配置和保存配置文件至磁盘。
- 更新 Swagger 文档以包含新接口定义。
This commit is contained in:
2026-01-14 14:15:20 +08:00
parent 1ffa16cf48
commit fe656fb298
13 changed files with 1043 additions and 6 deletions

View File

@@ -426,6 +426,80 @@ const docTemplate = `{
}
}
},
"/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",
@@ -698,6 +772,38 @@ const docTemplate = `{
}
}
},
"/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 下载单个文件",
@@ -831,6 +937,149 @@ const docTemplate = `{
}
}
},
"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": {
@@ -979,6 +1228,25 @@ const docTemplate = `{
}
}
},
"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": {