Skip to content

Commit 70266d5

Browse files
authored
Merge pull request #17 from ZatoBox/fix/api
feat: update OCR API base URL handling and add document validation en…
2 parents a088db6 + 15d0573 commit 70266d5

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

frontend/src/services/api.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import type { RequestInit } from 'node-fetch';
44
// Configuración de la API
55
const API_BASE_URL: string =
66
import.meta.env.VITE_API_URL || 'http://localhost:4444/api';
7-
const OCR_API_BASE_URL: string =
8-
import.meta.env.VITE_OCR_API_URL || 'http://127.0.0.1:8001/api/v1';
7+
const OCR_API_BASE_URL_RAW: string =
8+
import.meta.env.VITE_OCR_API_URL || 'http://127.0.0.1:5000';
9+
const OCR_API_BASE_URL: string = (OCR_API_BASE_URL_RAW as string).replace(
10+
/\/+$/g,
11+
''
12+
);
913

1014
export const API_CONFIG = {
1115
BASE_URL: API_BASE_URL,
@@ -457,6 +461,27 @@ export const ocrAPI = {
457461
return await response.json();
458462
},
459463

464+
validateDocument: async (file: File): Promise<OCRResponse> => {
465+
const formData = new FormData();
466+
formData.append('file', file);
467+
468+
const response = await fetch(
469+
`${API_CONFIG.OCR_BASE_URL}/invoice/validate`,
470+
{
471+
method: 'POST',
472+
body: formData,
473+
mode: 'cors',
474+
credentials: 'omit',
475+
}
476+
);
477+
478+
if (!response.ok) {
479+
const errorText = await response.text();
480+
throw new Error(`HTTP error! status: ${response.status} - ${errorText}`);
481+
}
482+
return await response.json();
483+
},
484+
460485
getDebugInfo: async (): Promise<OCRDebugResponse> => {
461486
const response = await fetch(`${API_CONFIG.OCR_BASE_URL}/invoice/debug`, {
462487
method: 'GET',

0 commit comments

Comments
 (0)