From 77cd75a33275bb9d4d13d26d860e405fc108c3a1 Mon Sep 17 00:00:00 2001 From: atmaranto <35581227+atmaranto@users.noreply.github.com> Date: Thu, 7 Mar 2024 04:41:54 -0600 Subject: [PATCH] Download as Python file Added fork warning --- js/save-as-script.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/save-as-script.js b/js/save-as-script.js index 60432a6..28ffddd 100644 --- a/js/save-as-script.js +++ b/js/save-as-script.js @@ -26,11 +26,15 @@ app.registerExtension({ } app.graphToPrompt().then(async (p) => { - const json = JSON.stringify({name: filename, workflow: JSON.stringify(p.output, null, 2)}, null, 2); // convert the data to a JSON string + const json = JSON.stringify({name: filename + ".json", workflow: JSON.stringify(p.output, null, 2)}, null, 2); // convert the data to a JSON string var response = await api.fetchApi(`/saveasscript`, { method: "POST", body: json }); if(response.status == 200) { - const blob = new Blob([await response.text()], {type: "application/json"}); + const blob = new Blob([await response.text()], {type: "text/python;charset=utf-8"}); const url = URL.createObjectURL(blob); + if(!filename.endsWith(".py")) { + filename += ".py"; + } + const a = $el("a", { href: url, download: filename,