last updates

This commit is contained in:
2025-10-20 21:05:31 +02:00
parent 8d28600318
commit ac52d6eec5
6 changed files with 65 additions and 27 deletions

View File

@@ -6,25 +6,42 @@
<title>Výsledky pro "{{ query }}" - vontor.cz</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script>
function download(fmt) {
const payload = { format: fmt, results: JSON.parse(document.getElementById('json-data').textContent) };
function download(format) {
const resultsJsonElement = document.getElementById('json-data');
const results = JSON.parse(resultsJsonElement.textContent);
const requestPayload = { format, results };
fetch('/export', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
}).then(r => {
if (r.ok) return r.blob();
return r.json().then(j=>{throw j});
}).then(blob=>{
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'results.' + fmt;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}).catch(e=>{ alert('Export failed: ' + JSON.stringify(e));});
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestPayload)
})
.then(function(response) {
if (response.ok){
return response.blob();
}
//error
return response.json().then(function(errorBody) { throw errorBody; });
})
.then(function(fileBlob) {
//blob
const objectUrl = window.URL.createObjectURL(fileBlob);
const downloadLink = document.createElement('a');
downloadLink.href = objectUrl;
downloadLink.download = 'results.' + format;
document.body.appendChild(downloadLink);
downloadLink.click();
downloadLink.remove();
window.URL.revokeObjectURL(objectUrl);
})
.catch(function(error) {
alert('Export failed: ' + JSON.stringify(error));
});
}
</script>
</head>