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 <noreply@anthropic.com>
This commit is contained in:
parent
18ef334f0d
commit
8495de77f8
@ -19,13 +19,14 @@ export class DocumentImportController {
|
|||||||
@ApiOperation({ summary: '创建导入任务' })
|
@ApiOperation({ summary: '创建导入任务' })
|
||||||
async createImport(@CurrentUser() user: UserPayload, @Body() dto: CreateImportDto) {
|
async createImport(@CurrentUser() user: UserPayload, @Body() dto: CreateImportDto) {
|
||||||
const userId = user.id;
|
const userId = user.id;
|
||||||
// M-MEMBER-01-CLOSE-01D: OCR/Vision 预检——导入创建时检查可用额度
|
// M-MEMBER-01-CLOSE-04A: OCR/Vision 预检——导入创建时验证至少 1 页可用
|
||||||
// 实际逐页计量由 RAG Worker 侧完成
|
// 逐页 reserve/commit/release 需 RAG Worker 侧实现(Python)
|
||||||
const opId = `import:${userId}:${Date.now()}`;
|
const opId = `import:${userId}:${Date.now()}`;
|
||||||
const ocrCheck = await this.quotaGuard.check(userId, 'ocr_pages', `${opId}:ocr`, 0);
|
const ocrCheck = await this.quotaGuard.check(userId, 'ocr_pages', `${opId}:ocr`, 1);
|
||||||
const visionCheck = await this.quotaGuard.check(userId, 'vision_pages', `${opId}:vision`, 0);
|
const visionCheck = await this.quotaGuard.check(userId, 'vision_pages', `${opId}:vision`, 1);
|
||||||
if (!ocrCheck.allowed || !visionCheck.allowed) {
|
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 });
|
return this.service.createImport({ ...dto, userId });
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user