Generate zip files before download

Previously, zip files were only downloaded if they already
existed. Now, they are created with  an action, then
downloaded from the result.

Chrome now insists on downloading the files as `output.zip`, I can't see why this has changed, but perhaps it's related
to the security warning. This seems to be specific to zip files.
This commit is contained in:
Richard Bowman 2024-01-17 13:16:19 +00:00
parent b35db02f34
commit 50cf8e6f78

View file

@ -42,13 +42,15 @@
<div class="uk-card"> <div class="uk-card">
<div class="uk-card-body"> <div class="uk-card-body">
<h3 class="uk-card-title">{{ item.name }}</h3> <h3 class="uk-card-title">{{ item.name }}</h3>
<a <task-submitter
:href="`${scansUri}/${item.name}/images.zip`" submit-label="Download ZIP"
:download="`${item.name}_images.zip`" :can-terminate="false"
class="uk-button uk-button-default" :submit-data="{'scan_name': item.name}"
> :button-primary="true"
Download images :submit-url="createZipOfScanUri"
</a> @response="downloadZipFile"
@error="modalError"
/>
<button class="uk-button" @click="deleteScan(item.name)"> <button class="uk-button" @click="deleteScan(item.name)">
Delete Delete
</button> </button>
@ -73,9 +75,11 @@
<script> <script>
import axios from "axios"; import axios from "axios";
import taskSubmitter from '../genericComponents/taskSubmitter.vue';
// Export main app // Export main app
export default { export default {
components: { taskSubmitter },
name: "ScanListContent", name: "ScanListContent",
data: function() { data: function() {
@ -92,6 +96,9 @@ export default {
"readproperty", "readproperty",
true true
); );
},
createZipOfScanUri() {
return this.thingActionUrl("smart_scan", "create_zip_of_scan");
} }
}, },
@ -186,6 +193,17 @@ export default {
// if the confirmation was cancelled, it's rejected with null error // if the confirmation was cancelled, it's rejected with null error
if (e) this.modalError(e); if (e) this.modalError(e);
} }
},
async downloadZipFile(response) {
const scan_name = response.input.scan_name;
const filename = `${scan_name}_images.zip`
const url = response.output.href;
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", filename);
console.log(link);
document.body.appendChild(link);
link.click();
} }
} }
}; };