Share stored document retry flow across tender detail and vault

This commit is contained in:
2026-09-06 09:37:56 +03:00
parent ba1f93bd76
commit 6dc6fadda8
7 changed files with 114 additions and 37 deletions
+40
View File
@@ -0,0 +1,40 @@
import { getToken } from './auth.js';
import { reportDocumentReadError } from './account.js';
export const readableDocument = (name) => /\.(pdf|txt|md|docx|xlsx|zip)$/i.test(String(name || ''));
export async function readStoredDocument(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)}`, {
headers: {Authorization:`Bearer ${getToken()}`},
});
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;
}
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;
}
export async function retryDocumentExtraction(document) {
if (document.tur !== 'ihale' || !document.ikn) throw new Error('İhaleye bağlı ihale dokümanı gerekli.');
const token = getToken();
const checkSession = () => { if (!token || token !== getToken()) throw new Error('Oturum değişti; belgeyi yeniden açın.'); };
checkSession();
let text;
try { text = await readStoredDocument(document); }
catch (error) {
checkSession();
try { await reportDocumentReadError(document.id,document.isleme); }
catch { throw new Error(`${error.message} (hata durumu kaydedilemedi; listeyi yenileyin)`); }
throw error;
}
checkSession();
const { kalemCikar } = await import('./kalem.js');
checkSession();
return kalemCikar({ikn:document.ikn,metin:text,dosya:document.ad,documentId:document.id});
}