From 8495de77f8944b00798c4f4b5bfd5312d8b93140 Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 27 Jun 2026 09:17:28 +0800 Subject: [PATCH] fix(quota): change OCR/Vision pre-check from amount=0 to amount=1 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 --- .../document-import/document-import.controller.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/document-import/document-import.controller.ts b/src/modules/document-import/document-import.controller.ts index 053d683..992a9b9 100644 --- a/src/modules/document-import/document-import.controller.ts +++ b/src/modules/document-import/document-import.controller.ts @@ -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 }); }