v7.0.0: API upload/process/download, session.py, фронт без обработки — всё на бэкенде
Deploy drhider / validate (push) Waiting to run

This commit is contained in:
2026-07-13 08:12:20 +04:00
parent e590d8ab9a
commit 18922b486b
6 changed files with 299 additions and 84 deletions
+44 -33
View File
@@ -155,51 +155,62 @@ async function uploadFiles() {
if (sf.length === 0) return;
ub.disabled = true;
const total = sf.length;
let ok = 0, fail = 0;
let sid = '';
// Фаза 1: загрузка всех файлов
for (let i = 0; i < total; i++) {
const f = sf[i], n = i + 1;
const t0 = performance.now();
const timer = setInterval(() => {
const sec = Math.round((performance.now() - t0) / 1000);
ss(i, '<span style="color:#2563eb">⏳ ' + sec + 'с</span>');
}, 200);
ss(i, '<span style="color:#2563eb">⏳ загрузка</span>');
st.className = 'status progress';
st.textContent = 'Файл ' + n + '/' + total + ': ' + f.name;
st.textContent = 'Загрузка ' + n + '/' + total + ': ' + f.name;
const fd = new FormData();
fd.append('files', f, f.name);
if (sid) fd.append('session', sid);
try {
const blob = await new Promise((resolve, reject) => {
const x = new XMLHttpRequest();
x.open('POST', '/api/drhider');
x.responseType = 'blob';
x.timeout = 600000;
x.onload = () => x.status === 200 ? resolve(x.response) : reject(new Error('Сервер ' + x.status));
x.onerror = () => reject(new Error('Сеть'));
x.ontimeout = () => reject(new Error('Таймаут'));
x.send(fd);
});
clearInterval(timer);
const el = ((performance.now() - t0) / 1000).toFixed(1);
// Скачиваем ZIP как есть — бэкенд всё сделал
const u = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = u;
a.download = f.name.replace(/\.[^.]+$/, '') + '_obfuscated.zip';
a.click();
URL.revokeObjectURL(u);
ss(i, '<span style="color:#22c55e">✓ ' + el + 'с</span>');
ok++;
const resp = await fetch('/api/upload', { method: 'POST', body: fd });
const data = await resp.json();
if (!data.ok) throw new Error(data.error);
sid = data.session;
ss(i, '<span style="color:#22c55e">✓ загружен</span>');
} catch (err) {
clearInterval(timer);
ss(i, '<span style="color:#ef4444">✗</span>');
fail++;
st.className = 'status error';
st.textContent = 'Ошибка загрузки: ' + err.message;
ub.disabled = false;
return;
}
if (i < total - 1) await new Promise(r => setTimeout(r, 300));
}
st.className = fail === 0 ? 'status done' : 'status error';
st.textContent = fail === 0 ? '✅ Готово! ' + ok + '/' + total : 'Готово: ' + ok + ' OK, ' + fail + ' ошибок из ' + total;
// Фаза 2: обработка (один запрос, ждём)
for (let i = 0; i < total; i++) ss(i, '<span style="color:#2563eb">⏳</span>');
st.className = 'status progress';
st.textContent = 'Обработка...';
const t0 = performance.now();
const ptimer = setInterval(() => {
const sec = Math.round((performance.now() - t0) / 1000);
st.textContent = 'Обработка... ' + sec + 'с';
}, 1000);
try {
const resp = await fetch('/api/process/' + sid, { method: 'POST' });
const data = await resp.json();
clearInterval(ptimer);
if (!data.ok) throw new Error(data.error);
st.className = 'status done';
st.textContent = '✅ Обработано ' + data.files + ' файлов за ' + ((performance.now() - t0) / 1000).toFixed(1) + 'с';
} catch (err) {
clearInterval(ptimer);
st.className = 'status error';
st.textContent = 'Ошибка: ' + err.message;
ub.disabled = false;
return;
}
// Фаза 3: скачивание
const a = document.createElement('a');
a.href = '/api/download/' + sid;
a.download = 'drhider_output.zip';
a.click();
ub.disabled = false;
}
</script>