fix(quota): change OCR/Vision pre-check from amount=0 to amount=1
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 40s
Deploy API Server / current-integration (push) Successful in 33s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Has been cancelled

amount=0 only validated configuration access. amount=1 now checks that at
least 1 page of quota is available before allowing document import.
Per-page reserve/commit/release requires RAG Worker (Python) changes.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-27 09:17:28 +08:00
parent 18ef334f0d
commit 8495de77f8

View File

@ -19,13 +19,14 @@ export class DocumentImportController {
@ApiOperation({ summary: '创建导入任务' })
async createImport(@CurrentUser() user: UserPayload, @Body() dto: CreateImportDto) {
const userId = user.id;
// M-MEMBER-01-CLOSE-01D: OCR/Vision 预检——导入创建时检查可用额度
// 实际逐页计量由 RAG Worker 侧完成
// M-MEMBER-01-CLOSE-04A: OCR/Vision 预检——导入创建时验证至少 1 页可用
// 逐页 reserve/commit/release 需 RAG Worker 侧实现Python
const opId = `import:${userId}:${Date.now()}`;
const ocrCheck = await this.quotaGuard.check(userId, 'ocr_pages', `${opId}:ocr`, 0);
const visionCheck = await this.quotaGuard.check(userId, 'vision_pages', `${opId}:vision`, 0);
const ocrCheck = await this.quotaGuard.check(userId, 'ocr_pages', `${opId}:ocr`, 1);
const visionCheck = await this.quotaGuard.check(userId, 'vision_pages', `${opId}:vision`, 1);
if (!ocrCheck.allowed || !visionCheck.allowed) {
throw new BadRequestException({ errorCode: 'QUOTA_EXCEEDED', message: 'OCR/Vision quota exceeded', quotaType: !ocrCheck.allowed ? 'ocr_pages' : 'vision_pages', limit: !ocrCheck.allowed ? ocrCheck.limit : visionCheck.limit, used: !ocrCheck.allowed ? ocrCheck.used : visionCheck.used, remaining: 0, upgradeAvailable: true });
const blocked = !ocrCheck.allowed ? ocrCheck : visionCheck;
throw new BadRequestException({ errorCode: 'QUOTA_EXCEEDED', message: 'OCR/Vision quota exceeded', quotaType: blocked.quotaType, limit: blocked.limit, used: blocked.used, remaining: blocked.remaining, resetAt: blocked.resetAt, upgradeAvailable: blocked.upgradeAvailable });
}
return this.service.createImport({ ...dto, userId });
}