diff --git a/frontend/src/components/Recipe/ContextMenu.vue b/frontend/src/components/Recipe/ContextMenu.vue index b8f221b0e..25cb8c8a0 100644 --- a/frontend/src/components/Recipe/ContextMenu.vue +++ b/frontend/src/components/Recipe/ContextMenu.vue @@ -109,7 +109,7 @@ export default { this.$router.push(`/recipe/${this.slug}` + "?edit=true"); break; case "download": - console.log("Download"); + await this.downloadJson(); break; default: break; @@ -127,6 +127,25 @@ export default { () => console.log("Copied Failed", copyText) ); }, + async downloadJson() { + const recipe = await api.recipes.requestDetails(this.slug); + this.downloadString(JSON.stringify(recipe, "", 4), "text/json", recipe.slug+'.json'); + }, + downloadString(text, fileType, fileName) { + let blob = new Blob([text], { type: fileType }); + + let a = document.createElement("a"); + a.download = fileName; + a.href = URL.createObjectURL(blob); + a.dataset.downloadurl = [fileType, a.download, a.href].join(":"); + a.style.display = "none"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + setTimeout(function() { + URL.revokeObjectURL(a.href); + }, 1500); + }, }, };