feat: async DrHider — POST job + poll + download, v0.5/v1.0.188
Deploy contracts-flask / validate (push) Successful in 0s

This commit is contained in:
2026-06-29 16:16:18 +04:00
parent 58bc73385d
commit a2a094969b
5 changed files with 80 additions and 25 deletions
+26 -12
View File
@@ -64,7 +64,7 @@
<a href="/">Сверка договоров</a>
<span class="sep">|</span>
<strong>DrHider</strong>
<span style="font-size:11px;color:var(--muted);">v0.4</span>
<span style="font-size:11px;color:var(--muted);">v0.5</span>
</header>
<main>
@@ -121,21 +121,35 @@ function render() {
BTN.onclick = async () => {
if (!files.length) return;
BTN.disabled = true;
setStatus('progress', '⏳ Отправка на сервер...');
setStatus('progress', '⏳ Отправка...');
const fd = new FormData(); files.forEach(f => fd.append('files', f));
try {
setStatus('progress', '⏳ Обработка (может занять до минуты)...');
const r = await fetch('/api/drhider', { method:'POST', body:fd });
if (!r.ok) {
const txt = await r.text();
throw new Error(txt);
// Шаг 1: старт задачи
const r1 = await fetch('/api/drhider', { method:'POST', body:fd });
if (!r1.ok) throw new Error(await r1.text());
const j = await r1.json();
if (!j.ok) throw new Error(j.error);
const jobId = j.job_id;
// Шаг 2: опрос
for (let i = 0; i < 120; i++) {
await new Promise(r => setTimeout(r, 2000));
const r2 = await fetch('/api/drhider/' + jobId + '/status');
const s = await r2.json();
if (s.error) throw new Error(s.error);
if (s.done) {
setStatus('progress', '⏳ Скачивание...');
const r3 = await fetch('/api/drhider/' + jobId + '/download');
if (!r3.ok) throw new Error(await r3.text());
const blob = await r3.blob();
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'drhider_output.zip'; a.click();
setStatus('done', '✅ Готово!');
break;
}
setStatus('progress', '⏳ Обработка... (' + ((i+1)*2) + 'с)');
}
const blob = await r.blob();
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'drhider_output.zip'; a.click();
setStatus('done', '✅ Готово! ZIP скачан.');
} catch(e) {
setStatus('error', '❌ ' + (e.name === 'TimeoutError' ? 'Сервер не ответил за 5 минут' : e.message || 'Неизвестная ошибка'));
console.error('DrHider error:', e);
setStatus('error', '❌ ' + (e.message || 'Ошибка'));
}
BTN.disabled = false;
};