调整路由以符合 RESTful 规范,新增 API Token 撤销功能

This commit is contained in:
2026-01-14 10:13:57 +08:00
parent 9c10dfd496
commit 5160ae78cc
10 changed files with 658 additions and 536 deletions

View File

@@ -165,7 +165,116 @@ const docTemplate = `{
}
}
},
"/admin/batch/{batch_id}": {
"/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": [
{
@@ -317,75 +426,6 @@ const docTemplate = `{
}
}
},
"/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/login": {
"post": {
"description": "通过密码换取 JWT Token",
@@ -438,130 +478,7 @@ const docTemplate = `{
}
}
},
"/api/download/batch/{pickup_code}": {
"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/download/file/{file_id}": {
"get": {
"description": "根据文件 ID 下载单个文件",
"produces": [
"application/octet-stream"
],
"tags": [
"Public"
],
"summary": "下载单个文件",
"parameters": [
{
"type": "integer",
"description": "文件 ID",
"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"
}
}
}
}
},
"/api/pickup/{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/upload": {
"/api/batches": {
"post": {
"description": "上传一个或多个文件并创建一个提取批次",
"consumes": [
@@ -641,7 +558,7 @@ const docTemplate = `{
}
}
},
"/api/upload/text": {
"/api/batches/text": {
"post": {
"description": "中转一段长文本内容并创建一个提取批次",
"consumes": [
@@ -698,6 +615,129 @@ const docTemplate = `{
}
}
}
},
"/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/files/{file_id}/download": {
"get": {
"description": "根据文件 ID 下载单个文件",
"produces": [
"application/octet-stream"
],
"tags": [
"Public"
],
"summary": "下载单个文件",
"parameters": [
{
"type": "integer",
"description": "文件 ID",
"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": {

View File

@@ -158,7 +158,116 @@
}
}
},
"/admin/batch/{batch_id}": {
"/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": [
{
@@ -310,75 +419,6 @@
}
}
},
"/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/login": {
"post": {
"description": "通过密码换取 JWT Token",
@@ -431,130 +471,7 @@
}
}
},
"/api/download/batch/{pickup_code}": {
"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/download/file/{file_id}": {
"get": {
"description": "根据文件 ID 下载单个文件",
"produces": [
"application/octet-stream"
],
"tags": [
"Public"
],
"summary": "下载单个文件",
"parameters": [
{
"type": "integer",
"description": "文件 ID",
"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"
}
}
}
}
},
"/api/pickup/{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/upload": {
"/api/batches": {
"post": {
"description": "上传一个或多个文件并创建一个提取批次",
"consumes": [
@@ -634,7 +551,7 @@
}
}
},
"/api/upload/text": {
"/api/batches/text": {
"post": {
"description": "中转一段长文本内容并创建一个提取批次",
"consumes": [
@@ -691,6 +608,129 @@
}
}
}
},
"/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/files/{file_id}/download": {
"get": {
"description": "根据文件 ID 下载单个文件",
"produces": [
"application/octet-stream"
],
"tags": [
"Public"
],
"summary": "下载单个文件",
"parameters": [
{
"type": "integer",
"description": "文件 ID",
"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": {

View File

@@ -283,7 +283,73 @@ paths:
summary: 删除 API Token
tags:
- Admin
/admin/batch/{batch_id}:
/admin/api-tokens/{id}/revoke:
post:
description: 将 API Token 标记为已撤销,使其失效但保留记录
parameters:
- description: Token ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/model.Response'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/model.Response'
security:
- AdminAuth: []
summary: 撤销 API Token
tags:
- Admin
/admin/batches:
get:
description: 分页查询所有文件批次,支持按状态过滤和取件码模糊搜索
parameters:
- description: 页码 (默认 1)
in: query
name: page
type: integer
- description: 每页数量 (默认 20)
in: query
name: page_size
type: integer
- description: 状态 (active/expired/deleted)
in: query
name: status
type: string
- description: 取件码 (模糊搜索)
in: query
name: pickup_code
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/model.Response'
- properties:
data:
$ref: '#/definitions/admin.ListBatchesResponse'
type: object
"401":
description: Unauthorized
schema:
$ref: '#/definitions/model.Response'
security:
- AdminAuth: []
summary: 获取批次列表
tags:
- Admin
/admin/batches/{batch_id}:
delete:
description: 标记批次为已删除,并物理删除关联的存储文件
parameters:
@@ -374,47 +440,6 @@ paths:
summary: 修改批次信息
tags:
- Admin
/admin/batches:
get:
description: 分页查询所有文件批次,支持按状态过滤和取件码模糊搜索
parameters:
- description: 页码 (默认 1)
in: query
name: page
type: integer
- description: 每页数量 (默认 20)
in: query
name: page_size
type: integer
- description: 状态 (active/expired/deleted)
in: query
name: status
type: string
- description: 取件码 (模糊搜索)
in: query
name: pickup_code
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/model.Response'
- properties:
data:
$ref: '#/definitions/admin.ListBatchesResponse'
type: object
"401":
description: Unauthorized
schema:
$ref: '#/definitions/model.Response'
security:
- AdminAuth: []
summary: 获取批次列表
tags:
- Admin
/admin/login:
post:
consumes:
@@ -446,85 +471,7 @@ paths:
summary: 管理员登录
tags:
- Admin
/api/download/batch/{pickup_code}:
get:
description: 根据取件码将批次内的所有文件打包为 ZIP 格式一次性下载
parameters:
- description: 取件码
in: path
name: pickup_code
required: true
type: string
produces:
- application/zip
responses:
"200":
description: OK
schema:
type: file
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
summary: 批量下载文件
tags:
- Public
/api/download/file/{file_id}:
get:
description: 根据文件 ID 下载单个文件
parameters:
- description: 文件 ID
in: path
name: file_id
required: true
type: integer
produces:
- application/octet-stream
responses:
"200":
description: OK
schema:
type: file
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
"410":
description: Gone
schema:
$ref: '#/definitions/model.Response'
summary: 下载单个文件
tags:
- Public
/api/pickup/{pickup_code}:
get:
description: 根据取件码获取文件批次详详情和文件列表
parameters:
- description: 取件码
in: path
name: pickup_code
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/model.Response'
- properties:
data:
$ref: '#/definitions/public.PickupResponse'
type: object
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
summary: 获取批次信息
tags:
- Public
/api/upload:
/api/batches:
post:
consumes:
- multipart/form-data
@@ -574,7 +521,58 @@ paths:
summary: 上传文件
tags:
- Public
/api/upload/text:
/api/batches/{pickup_code}:
get:
description: 根据取件码获取文件批次详详情和文件列表
parameters:
- description: 取件码
in: path
name: pickup_code
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/model.Response'
- properties:
data:
$ref: '#/definitions/public.PickupResponse'
type: object
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
summary: 获取批次信息
tags:
- Public
/api/batches/{pickup_code}/download:
get:
description: 根据取件码将批次内的所有文件打包为 ZIP 格式一次性下载
parameters:
- description: 取件码
in: path
name: pickup_code
required: true
type: string
produces:
- application/zip
responses:
"200":
description: OK
schema:
type: file
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
summary: 批量下载文件
tags:
- Public
/api/batches/text:
post:
consumes:
- application/json
@@ -609,6 +607,33 @@ paths:
summary: 发送长文本
tags:
- Public
/api/files/{file_id}/download:
get:
description: 根据文件 ID 下载单个文件
parameters:
- description: 文件 ID
in: path
name: file_id
required: true
type: integer
produces:
- application/octet-stream
responses:
"200":
description: OK
schema:
type: file
"404":
description: Not Found
schema:
$ref: '#/definitions/model.Response'
"410":
description: Gone
schema:
$ref: '#/definitions/model.Response'
summary: 下载单个文件
tags:
- Public
securityDefinitions:
AdminAuth:
description: Type "Bearer <your-jwt-token>" to authenticate.