Expose document text and OCR page provenance for review
This commit is contained in:
@@ -3,7 +3,7 @@ import { reportDocumentReadError } from './account.js';
|
||||
|
||||
export const readableDocument = (name) => /\.(pdf|txt|md|docx|xlsx|zip)$/i.test(String(name || ''));
|
||||
|
||||
export async function readStoredDocument(document) {
|
||||
export async function inspectStoredDocument(document) {
|
||||
if (!readableDocument(document.ad)) throw new Error('Bu dosya biçiminden metin çıkarımı desteklenmiyor.');
|
||||
const office = /\.(docx|xlsx|zip)$/i.test(document.ad);
|
||||
const response = await fetch(`/api/me/documents/${office ? 'text' : 'download'}?id=${encodeURIComponent(document.id)}`, {
|
||||
@@ -12,14 +12,16 @@ export async function readStoredDocument(document) {
|
||||
if (office) {
|
||||
const result = await response.json().catch(() => ({}));
|
||||
if (!response.ok || !result.success) throw new Error(result.error || 'Belge metni alınamadı.');
|
||||
return result.metin;
|
||||
return {text:result.metin,format:document.ad.split('.').pop()};
|
||||
}
|
||||
if (!response.ok) throw new Error('Belge indirilemedi.');
|
||||
const blob = await response.blob();
|
||||
const { extractText } = await import('./pdfText');
|
||||
return (await extractText(new File([blob],document.ad,{type:document.mime || 'application/octet-stream'}))).text;
|
||||
return extractText(new File([blob],document.ad,{type:document.mime || 'application/octet-stream'}));
|
||||
}
|
||||
|
||||
export async function readStoredDocument(document) { return (await inspectStoredDocument(document)).text; }
|
||||
|
||||
export async function retryDocumentExtraction(document) {
|
||||
if (document.tur !== 'ihale' || !document.ikn) throw new Error('İhaleye bağlı ihale dokümanı gerekli.');
|
||||
const token = getToken();
|
||||
|
||||
Reference in New Issue
Block a user