Share stored document retry flow across tender detail and vault
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Sunucu tarafı hesap servisleri: plan/kota, kullanıcı verisi, API anahtarları, belgeler.
|
||||
* (Önceden bunların hepsi localStorage'daydı veya sahteydi.)
|
||||
*/
|
||||
import { getToken } from './auth';
|
||||
import { getToken } from './auth.js';
|
||||
|
||||
const auth = () => ({ Authorization: `Bearer ${getToken()}`, 'Content-Type': 'application/json' });
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* korunuyor). Bir kullanıcı dokümanı yükleyince kalemler havuza yazılıyor ve
|
||||
* o ihale herkesin kartında kalemleriyle görünüyor.
|
||||
*/
|
||||
import { getToken } from './auth';
|
||||
import { getToken } from './auth.js';
|
||||
|
||||
/** Bir ihalenin tüm kalemleri. */
|
||||
export async function kalemleriGetir(ikn) {
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
Reference in New Issue
Block a user