feat(routing): GET/POST /v1/me/routing 端点 + openapi

This commit is contained in:
wangjia
2026-07-28 07:49:03 +08:00
parent 3a2c48541c
commit 49f62d9b14
5 changed files with 455 additions and 0 deletions
+128
View File
@@ -249,6 +249,55 @@ paths:
"500":
$ref: "#/components/responses/Internal"
/me/routing:
get:
operationId: getRoutingProfile
summary: 获取当前用户的分流配置
description: |
可配置分流(#5 之上的用户自定义规则)。用户未自定义时返回默认档案
(等价于原硬编码行为:智能分流 + 国内直连 + 无自定义规则)。
tags: [Account]
responses:
"200":
description: 分流档案
content:
application/json:
schema:
$ref: "#/components/schemas/RoutingProfile"
"401":
$ref: "#/components/responses/Unauthorized"
"500":
$ref: "#/components/responses/Internal"
post:
operationId: saveRoutingProfile
summary: 保存当前用户的分流配置
description: |
整份覆盖式保存(非增量 patch)。校验失败时不部分保存,一次性返回全部违规字段。
tags: [Account]
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/RoutingProfile"
responses:
"200":
description: 保存成功,返回规整化(去重/裁剪)后的档案
content:
application/json:
schema:
$ref: "#/components/schemas/RoutingProfile"
"400":
description: 校验失败(逐条错误,不部分保存)
content:
application/json:
schema:
$ref: "#/components/schemas/RoutingValidationError"
"401":
$ref: "#/components/responses/Unauthorized"
"500":
$ref: "#/components/responses/Internal"
# ── 商业闭环 ─────────────────────────────────────────────
/redeem:
@@ -1131,6 +1180,85 @@ components:
format: date-time
description: 最后活跃时间(UTC ISO-8601
# ── 可配置分流 ───────────────────────────────────────────
RoutingRule:
type: object
required: [type, value, action, enabled]
properties:
type:
type: string
enum: [domain, domain_suffix, domain_keyword, ip_cidr, geoip, geosite]
value:
type: string
description: geoip/geosite 目前仅白名单 cn(自托管规则集);ip_cidr 需合法 CIDR
example: x.com
action:
type: string
enum: [direct, proxy, reject]
note:
type: string
enabled:
type: boolean
RoutingBuiltin:
type: object
properties:
china_direct:
type: boolean
description: 国内域名/IP 直连
lan_direct:
type: boolean
description: 局域网直连
private_via_tunnel:
type: boolean
description: 私有服务域名强制走隧道(家庭内网穿透场景)
RoutingProfile:
type: object
required: [mode, builtin, rules, final]
properties:
mode:
type: string
enum: [rule, global, direct]
builtin:
$ref: "#/components/schemas/RoutingBuiltin"
rules:
type: array
maxItems: 200
items:
$ref: "#/components/schemas/RoutingRule"
final:
type: string
enum: [proxy, direct]
RoutingValidationError:
type: object
required: [code, message_zh, message_en, errors]
properties:
code:
type: string
example: routing_invalid
message_zh:
type: string
example: 规则校验未通过
message_en:
type: string
example: Rule validation failed
errors:
type: array
items:
type: object
required: [index, field, reason]
properties:
index:
type: integer
description: -1 表示档案级字段(mode/final/rules 数量),否则为 rules 下标
field:
type: string
reason:
type: string
# ── 商业 ───────────────────────────────────────────────
Plan: