Fix gather extract: poll task status before download

This commit is contained in:
Floppyrj45
2026-02-19 15:57:22 +01:00
parent f4f4c4e81f
commit a3b3a93ef2

View File

@@ -2594,17 +2594,40 @@ async function doExtract() {
return;
}
var blob = await r.blob();
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'gather_extract_s' + Math.round(start) + '_d' + Math.round(duration) + '.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
var taskData = await r.json();
if (!taskData.task_id) {
setInfo('Extract error: no task_id returned');
return;
}
var taskId = taskData.task_id;
setInfo('📥 Processing extract task...');
setInfo('📥 Downloaded: ' + (blob.size / 1e6).toFixed(1) + ' MB');
// Poll until done
while (true) {
await new Promise(function(resolve) { setTimeout(resolve, 2000); });
var sr = await fetch(API + '/tasks/' + taskId);
var sd = await sr.json();
if (sd.status === 'done') {
setInfo('📥 Downloading ZIP...');
var dr = await fetch(API + '/tasks/' + taskId + '/download');
var blob = await dr.blob();
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'gather_extract_s' + Math.round(start) + '_d' + Math.round(duration) + '.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
setInfo('📥 Downloaded: ' + (blob.size / 1e6).toFixed(1) + ' MB');
break;
} else if (sd.status === 'error') {
setInfo('Extract error: ' + (sd.error || 'unknown'));
break;
} else {
setInfo('📥 Processing... ' + (sd.progress || ''));
}
}
} catch(e) {
setInfo('Extract error: ' + e.message);
}