forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr.controller.ts
More file actions
115 lines (105 loc) · 3.75 KB
/
Copy pathocr.controller.ts
File metadata and controls
115 lines (105 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Controller, Post, Get, Body, Param, Query, ValidationPipe, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
import { OcrQueueService } from './ocr-queue.service';
import { CreateOcrJobDto } from './dto/ocr-job.dto';
import { OcrJob, OcrJobStatus } from './entities/ocr-job.entity';
@ApiTags('OCR')
@Controller('ocr')
export class OcrController {
constructor(private readonly ocrQueueService: OcrQueueService) {}
/**
* Create a new OCR job
* Accepts image data either as URL or file upload
*/
@Post('jobs')
@ApiOperation({ summary: 'Create a new OCR job' })
@ApiResponse({ status: 201, description: 'OCR job created', type: OcrJob })
async createJob(
@Body(ValidationPipe) dto: CreateOcrJobDto,
): Promise<OcrJob> {
return this.ocrQueueService.createJob(dto);
}
/**
* Get OCR job details by ID
*/
@Get('jobs/:id')
@ApiOperation({ summary: 'Get OCR job details by ID' })
@ApiParam({ name: 'id', description: 'OCR Job ID (UUID)' })
@ApiResponse({ status: 200, description: 'Job details', type: OcrJob })
async getJob(@Param('id') id: string): Promise<OcrJob> {
return this.ocrQueueService.getJob(id);
}
/**
* Get OCR job progress
*/
@Get('jobs/:id/progress')
@ApiOperation({ summary: 'Get OCR job progress' })
@ApiParam({ name: 'id', description: 'OCR Job ID (UUID)' })
@ApiResponse({ status: 200, description: 'Job progress' })
async getJobProgress(@Param('id') id: string): Promise<{ progress: number; status: string }> {
return this.ocrQueueService.getJobProgress(id);
}
/**
* Get all jobs needing manual review
*/
@Get('jobs/review/needs')
@ApiOperation({ summary: 'Get all OCR jobs that need manual review' })
@ApiResponse({ status: 200, description: 'List of jobs needing review', type: [OcrJob] })
async getJobsNeedingReview(): Promise<OcrJob[]> {
return this.ocrQueueService.getJobsNeedingReview();
}
/**
* Retry a failed OCR job
*/
@Post('jobs/:id/retry')
@ApiOperation({ summary: 'Retry a failed OCR job' })
@ApiParam({ name: 'id', description: 'OCR Job ID (UUID)' })
@ApiResponse({ status: 200, description: 'Job retry initiated', type: OcrJob })
async retryJob(@Param('id') id: string): Promise<OcrJob> {
return this.ocrQueueService.retryJob(id);
}
/**
* Cancel a pending OCR job
*/
@Post('jobs/:id/cancel')
@ApiOperation({ summary: 'Cancel a pending OCR job' })
@ApiParam({ name: 'id', description: 'OCR Job ID (UUID)' })
@ApiResponse({ status: 204, description: 'Job cancelled' })
async cancelJob(@Param('id') id: string): Promise<void> {
return this.ocrQueueService.cancelJob(id);
}
/**
* Get queue statistics
*/
@Get('stats')
@ApiOperation({ summary: 'Get OCR queue statistics' })
@ApiResponse({ status: 200, description: 'Queue stats' })
async getStats(): Promise<{
pending: number;
processing: number;
completed: number;
failed: number;
needsReview: number;
}> {
return this.ocrQueueService.getQueueStats();
}
/**
* Get failed jobs
*/
@Get('jobs/failed')
@ApiOperation({ summary: 'Get all failed OCR jobs' })
@ApiResponse({ status: 200, description: 'List of failed jobs', type: [OcrJob] })
async getFailedJobs(): Promise<OcrJob[]> {
return this.ocrQueueService.getFailedJobs();
}
/**
* Manually trigger processing for a job
*/
@Post('jobs/:id/process')
@ApiOperation({ summary: 'Manually trigger processing for a job' })
@ApiParam({ name: 'id', description: 'OCR Job ID (UUID)' })
@ApiResponse({ status: 200, description: 'Processing triggered', type: OcrJob })
async processJobManually(@Param('id') id: string): Promise<OcrJob> {
return this.ocrQueueService.processJobManually(id);
}
}