bug/backup-download (#245)

* fix blocked download

* + download blocked

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-03-31 20:07:50 -08:00 committed by GitHub
parent 4799fffc93
commit c61906e480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -9,4 +9,5 @@
- Fix Tags/Categories render problems on recipes
- Tags redirect to new tag pages
- Categories redirect to category pages
- Fix Backup download blocked by authentication

View file

@ -37,7 +37,12 @@
<v-divider></v-divider>
<v-card-actions>
<v-btn color="accent" text :href="`/api/backups/${name}/download`">
<v-btn
color="accent"
text
:loading="downloading"
@click="downloadFile(`/api/backups/${name}/download`)"
>
{{ $t("general.download") }}
</v-btn>
<v-spacer></v-spacer>
@ -61,6 +66,7 @@
<script>
import ImportOptions from "@/components/Admin/Backup/ImportOptions";
import axios from "axios";
export default {
components: { ImportOptions },
props: {
@ -83,6 +89,7 @@ export default {
dialog: false,
forceImport: false,
rebaseImport: false,
downloading: false,
};
},
methods: {
@ -109,6 +116,23 @@ export default {
this.close();
this.$emit(event, eventData);
},
async downloadFile(downloadURL) {
this.downloading = true;
const response = await axios({
url: downloadURL,
method: "GET",
responseType: "blob", // important
});
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", `${this.name}.zip`);
document.body.appendChild(link);
link.click();
this.downloading = false;
},
},
};
</script>