All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 59s
RateLimitService could not be injected into feature modules due to NestJS DI module isolation. Replaced with a global Guard that uses @RateLimit() decorator metadata to apply per-endpoint limits. - RateLimitGuard: checks Redis counters, throws 429 on exceed - Decorators: LoginRateLimit, FeedbackRateLimit, AiAnalysisRateLimit, FileUploadRateLimit - Applied to: auth (login), feedback, ai-analysis, files endpoints Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { Controller, Post, Get, Body, Param } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
import { AiAnalysisService } from './ai-analysis.service';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import { AiAnalysisRateLimit } from '../../common/decorators/rate-limit.decorator';
|
|
import type { UserPayload } from '../../common/types';
|
|
|
|
@ApiTags('ai-analysis')
|
|
@Controller('ai-analysis')
|
|
export class AiAnalysisController {
|
|
constructor(private readonly service: AiAnalysisService) {}
|
|
|
|
@Post()
|
|
@AiAnalysisRateLimit()
|
|
@ApiOperation({ summary: '提交主动回忆分析(异步)' })
|
|
async analyze(
|
|
@CurrentUser() user: UserPayload,
|
|
@Body() body: {
|
|
questionText: string;
|
|
knowledgeItemContent: string;
|
|
userAnswer: string;
|
|
sessionId?: string;
|
|
answerId?: string;
|
|
},
|
|
) {
|
|
return this.service.analyze(String(user?.id || 'anonymous'), body);
|
|
}
|
|
|
|
@Post('feynman')
|
|
@AiAnalysisRateLimit()
|
|
@ApiOperation({ summary: '提交费曼解释评估(异步)' })
|
|
async evaluateFeynman(
|
|
@CurrentUser() user: UserPayload,
|
|
@Body() body: {
|
|
knowledgeItemTitle: string;
|
|
knowledgeItemContent: string;
|
|
userExplanation: string;
|
|
sessionId?: string;
|
|
answerId?: string;
|
|
},
|
|
) {
|
|
return this.service.evaluateFeynman(String(user?.id || 'anonymous'), body);
|
|
}
|
|
|
|
@Get('jobs/:id')
|
|
@ApiOperation({ summary: '查询 AI 分析任务状态' })
|
|
async getJobStatus(@Param('id') id: string) {
|
|
return this.service.getJobStatus(id);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取分析结果' })
|
|
async findOne(@Param('id') id: string) {
|
|
return this.service.getResult(id);
|
|
}
|
|
}
|