From 2bac851e6da0566629b1a1a921d9698c92352f9c Mon Sep 17 00:00:00 2001 From: imeepos Date: Mon, 8 Sep 2025 11:06:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AE=9E=E7=8E=B0=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84CurrentUser=E8=A3=85=E9=A5=B0=E5=99=A8?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增CurrentUser装饰器和CurrentUserData类型定义 - 替换content-moderation.controller.ts中的模拟装饰器实现 - 修复测试文件中的用户数据结构,确保包含必要的platform字段 - 修复app.module.ts中已删除控制器的引用 - 优化Swagger配置使用环境变量定义服务器地址 --- .env.example | 3 ++- src/config/swagger.config.ts | 12 +++++++++--- .../controllers/content-moderation.controller.ts | 4 +--- src/decorators/current-user.decorator.ts | 2 +- src/generate-swagger-json.ts | 12 ++++++++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 29dc9b2..733b80d 100644 --- a/.env.example +++ b/.env.example @@ -28,7 +28,8 @@ BYTEDANCE_APP_SECRET=04a026867fbd1ba52174c7c21d94cbc7361ec378 # 内容审核配置 # 图片审核回调地址(重要:抖音审核完成后会调用此接口) AUDIT_CALLBACK_URL=https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com/api/v1/content-moderation/bytedance/callback - +TEST_SERVER_URL=https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com +PROD_SERVER_URL=https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com # 抖音内容审核API地址 BYTEDANCE_AUDIT_API_URL=https://developer.toutiao.com/api/apps/v2/content/audit/image diff --git a/src/config/swagger.config.ts b/src/config/swagger.config.ts index 542b2d9..aa841dc 100644 --- a/src/config/swagger.config.ts +++ b/src/config/swagger.config.ts @@ -48,9 +48,15 @@ export function setupSwagger(app: INestApplication): void { .addTag('AI模板系统', 'AI图片/视频生成模板管理') .addTag('积分系统', '积分获取、消耗、查询管理') .addTag('扩展服务', '预留的扩展功能接口') - .addServer('http://localhost:3000', '开发环境') - .addServer('https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', '测试环境') - .addServer('https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', '生产环境') + .addServer(`http://localhost:${process.env.PORT || 3003}`, '开发环境') + .addServer( + process.env.TEST_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', + '测试环境', + ) + .addServer( + process.env.PROD_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', + '生产环境', + ) .build(); const document = SwaggerModule.createDocument(app as any, config, { diff --git a/src/content-moderation/controllers/content-moderation.controller.ts b/src/content-moderation/controllers/content-moderation.controller.ts index 1436cec..6b83d14 100644 --- a/src/content-moderation/controllers/content-moderation.controller.ts +++ b/src/content-moderation/controllers/content-moderation.controller.ts @@ -22,9 +22,7 @@ import { } from '../dto/audit-response.dto'; import { PlatformAuthGuard } from '../../platform/guards/platform-auth.guard'; import { PlatformType } from '../../entities/platform-user.entity'; -import { - ResponseUtil, -} from '../../utils/response.util'; +import { ResponseUtil } from '../../utils/response.util'; import { CurrentUser } from '../../decorators/current-user.decorator'; import type { CurrentUserData } from '../../decorators/current-user.decorator'; diff --git a/src/decorators/current-user.decorator.ts b/src/decorators/current-user.decorator.ts index 36bbe0d..fcc424b 100644 --- a/src/decorators/current-user.decorator.ts +++ b/src/decorators/current-user.decorator.ts @@ -11,4 +11,4 @@ export const CurrentUser = createParamDecorator( const request = ctx.switchToHttp().getRequest(); return request.user; }, -); \ No newline at end of file +); diff --git a/src/generate-swagger-json.ts b/src/generate-swagger-json.ts index 4f2ea81..a8a6ef8 100644 --- a/src/generate-swagger-json.ts +++ b/src/generate-swagger-json.ts @@ -58,8 +58,16 @@ async function generateSwaggerJson() { .addTag('积分系统', '积分获取、消耗、查询管理') .addTag('扩展服务', '预留的扩展功能接口') .addServer(`http://localhost:${process.env.PORT || 3003}`, '开发环境') - .addServer(process.env.TEST_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', '测试环境') - .addServer(process.env.PROD_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', '生产环境') + .addServer( + process.env.TEST_SERVER_URL || + 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', + '测试环境', + ) + .addServer( + process.env.PROD_SERVER_URL || + 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com', + '生产环境', + ) .build(); const document = SwaggerModule.createDocument(app as any, config);