chore: customDomain openapi doc && new nextapi code snippets (#6082)

* perf: faq

* index

* delete dataset

* delete dataset

* perf: delete dataset

* init

* fix: faq

* refresh

* empty tip

* chore: customDomain openapi doc && new nextapi code snippets

* chore: update doc

* remove ivalid code

* snippets

---------

Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
Finley Ge
2025-12-12 15:28:03 +08:00
committed by GitHub
parent 805cd33a77
commit b22ba1aa53
8 changed files with 291 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import { ApiKeyPath } from './support/openapi';
import { TagsMap } from './tag';
import { PluginPath } from './core/plugin';
import { WalletPath } from './support/wallet';
import { CustomDomainPath } from './support/customDomain';
export const openAPIDocument = createDocument({
openapi: '3.1.0',
@@ -16,7 +17,8 @@ export const openAPIDocument = createDocument({
...ChatPath,
...ApiKeyPath,
...PluginPath,
...WalletPath
...WalletPath,
...CustomDomainPath
},
servers: [{ url: '/api' }],
'x-tagGroups': [
@@ -39,6 +41,10 @@ export const openAPIDocument = createDocument({
{
name: '支付',
tags: [TagsMap.walletBill, TagsMap.walletDiscountCoupon]
},
{
name: '自定义域名',
tags: [TagsMap.customDomain]
}
]
});

View File

@@ -0,0 +1,84 @@
import { z } from 'zod';
import { CustomDomainType, ProviderEnum } from '../../../support/customDomain/type';
// Create custom domain
export const CreateCustomDomainBodySchema = z.object({
domain: z.string().meta({ example: 'chat.example.com', description: '自定义域名' }),
provider: ProviderEnum.meta({
example: 'aliyun',
description: 'DNS 提供商aliyun, tencent, volcengine'
}),
cnameDomain: z.string().meta({ example: 'lb.example.com', description: 'CNAME 目标域名' })
});
export type CreateCustomDomainBodyType = z.infer<typeof CreateCustomDomainBodySchema>;
export const CreateCustomDomainResponseSchema = z.object({
success: z.boolean().meta({ example: true, description: '创建是否成功' })
});
export type CreateCustomDomainResponseType = z.infer<typeof CreateCustomDomainResponseSchema>;
// List custom domains
export const CustomDomainListResponseSchema = z.array(
CustomDomainType.extend({
_id: z
.string()
.optional()
.meta({ example: '68ad85a7463006c963799a05', description: '域名记录 ID' })
})
);
export type CustomDomainListResponseType = z.infer<typeof CustomDomainListResponseSchema>;
// Delete custom domain
export const DeleteCustomDomainQuerySchema = z.object({
domain: z.string().meta({ example: 'chat.example.com', description: '要删除的域名' })
});
export type DeleteCustomDomainQueryType = z.infer<typeof DeleteCustomDomainQuerySchema>;
export const DeleteCustomDomainResponseSchema = z.object({
success: z.boolean().meta({ example: true, description: '删除是否成功' })
});
export type DeleteCustomDomainResponseType = z.infer<typeof DeleteCustomDomainResponseSchema>;
// Check DNS resolve
export const CheckDNSResolveBodySchema = z.object({
domain: z.string().meta({ example: 'chat.example.com', description: '要检查的域名' }),
cnameDomain: z.string().meta({ example: 'lb.example.com', description: 'CNAME 目标域名' })
});
export type CheckDNSResolveBodyType = z.infer<typeof CheckDNSResolveBodySchema>;
export const CheckDNSResolveResponseSchema = z.object({
success: z.boolean().meta({ example: true, description: 'DNS 解析是否成功' }),
message: z
.string()
.optional()
.meta({ example: 'CNAME record not resolved', description: '错误信息' })
});
export type CheckDNSResolveResponseType = z.infer<typeof CheckDNSResolveResponseSchema>;
// Active custom domain
export const ActiveCustomDomainBodySchema = z.object({
domain: z.string().meta({ example: 'chat.example.com', description: '要激活的域名' })
});
export type ActiveCustomDomainBodyType = z.infer<typeof ActiveCustomDomainBodySchema>;
export const ActiveCustomDomainResponseSchema = z.object({
success: z.boolean().meta({ example: true, description: '激活是否成功' })
});
export type ActiveCustomDomainResponseType = z.infer<typeof ActiveCustomDomainResponseSchema>;
// Update domain verify file
export const UpdateDomainVerifyFileBodySchema = z.object({
domain: z.string().meta({ example: 'chat.example.com', description: '域名' }),
path: z
.string()
.meta({ example: '/.well-known/pki-validation/fileauth.txt', description: '验证文件路径' }),
content: z.string().meta({ example: '202312121234567890abcdef', description: '验证文件内容' })
});
export type UpdateDomainVerifyFileBodyType = z.infer<typeof UpdateDomainVerifyFileBodySchema>;
export const UpdateDomainVerifyFileResponseSchema = z.object({
success: z.boolean().meta({ example: true, description: '更新是否成功' })
});
export type UpdateDomainVerifyFileResponseType = z.infer<
typeof UpdateDomainVerifyFileResponseSchema
>;

View File

@@ -0,0 +1,153 @@
import type { OpenAPIPath } from '../../type';
import {
CreateCustomDomainBodySchema,
CreateCustomDomainResponseSchema,
CustomDomainListResponseSchema,
DeleteCustomDomainQuerySchema,
DeleteCustomDomainResponseSchema,
CheckDNSResolveBodySchema,
CheckDNSResolveResponseSchema,
ActiveCustomDomainBodySchema,
ActiveCustomDomainResponseSchema,
UpdateDomainVerifyFileBodySchema,
UpdateDomainVerifyFileResponseSchema
} from './api';
import { TagsMap } from '../../tag';
export const CustomDomainPath: OpenAPIPath = {
'/proApi/support/customDomain/create': {
post: {
summary: '创建自定义域名',
description:
'创建一个新的自定义域名配置,需要高级套餐权限。创建后域名会自动部署到 K8s 集群中',
tags: [TagsMap.customDomain],
requestBody: {
content: {
'application/json': {
schema: CreateCustomDomainBodySchema
}
}
},
responses: {
200: {
description: '成功创建自定义域名',
content: {
'application/json': {
schema: CreateCustomDomainResponseSchema
}
}
}
}
}
},
'/proApi/support/customDomain/list': {
get: {
summary: '获取自定义域名列表',
description: '获取当前团队的所有自定义域名配置列表',
tags: [TagsMap.customDomain],
responses: {
200: {
description: '成功获取自定义域名列表',
content: {
'application/json': {
schema: CustomDomainListResponseSchema
}
}
}
}
}
},
'/proApi/support/customDomain/delete': {
delete: {
summary: '删除自定义域名',
description: '删除指定的自定义域名配置,同时会从 K8s 集群中移除相关资源',
tags: [TagsMap.customDomain],
requestParams: {
query: DeleteCustomDomainQuerySchema
},
responses: {
200: {
description: '成功删除自定义域名',
content: {
'application/json': {
schema: DeleteCustomDomainResponseSchema
}
}
}
}
}
},
'/proApi/support/customDomain/checkDNSResolve': {
post: {
summary: '检查 DNS 解析',
description: '检查自定义域名的 CNAME 记录是否正确配置和解析',
tags: [TagsMap.customDomain],
requestBody: {
content: {
'application/json': {
schema: CheckDNSResolveBodySchema
}
}
},
responses: {
200: {
description: 'DNS 解析检查结果',
content: {
'application/json': {
schema: CheckDNSResolveResponseSchema
}
}
}
}
}
},
'/proApi/support/customDomain/active': {
post: {
summary: '激活自定义域名',
description: '将自定义域名状态设置为激活,并重新部署到 K8s 集群',
tags: [TagsMap.customDomain],
requestBody: {
content: {
'application/json': {
schema: ActiveCustomDomainBodySchema
}
}
},
responses: {
200: {
description: '成功激活自定义域名',
content: {
'application/json': {
schema: ActiveCustomDomainResponseSchema
}
}
}
}
}
},
'/proApi/support/customDomain/updateVerifyFile': {
post: {
summary: '更新域名验证文件',
description:
'更新域名验证文件配置,用于 SSL 证书验证。更新后会在 K8s 中创建或更新对应的 Ingress',
tags: [TagsMap.customDomain],
requestBody: {
content: {
'application/json': {
schema: UpdateDomainVerifyFileBodySchema
}
}
},
responses: {
200: {
description: '成功更新域名验证文件',
content: {
'application/json': {
schema: UpdateDomainVerifyFileResponseSchema
}
}
}
}
}
}
};

View File

@@ -9,6 +9,7 @@ export const TagsMap = {
apiKey: 'APIKey',
walletBill: '订单',
walletDiscountCoupon: '优惠券',
customDomain: '自定义域名',
adminDashboard: '管理员仪表盘'
};