Improve model download

This commit is contained in:
Rodolphe Houdas 2021-09-01 01:19:43 +01:00
parent 6809a0a747
commit ecc52fe412
2 changed files with 26 additions and 14 deletions

View file

@ -16,7 +16,7 @@ app = Flask(__name__)
@app.route("/", methods=['POST']) @app.route("/", methods=['POST'])
@cross_origin() @cross_origin(expose_headers=["content-disposition"])
def upload_files(): def upload_files():
project_id = str(uuid4()) project_id = str(uuid4())

View file

@ -114,6 +114,8 @@
inc++; inc++;
}); });
let filename = "";
const send_form = document.getElementById("files-form"); const send_form = document.getElementById("files-form");
send_form.addEventListener("submit", (event) => { send_form.addEventListener("submit", (event) => {
const url = "https://cad.interstellai.re/upload"; const url = "https://cad.interstellai.re/upload";
@ -121,14 +123,19 @@
method: "POST", method: "POST",
body: new FormData(event.target) body: new FormData(event.target)
}) })
.then( res => res.blob() ) .then(res => {
.then( blob => { const header = res.headers.get('content-disposition');
addResult(blob); const parts = header.split(';');
filename = parts[1].split('=')[1].replace(/['"]+/g, '');
return res.blob();
})
.then(blob => {
addResult(blob, filename);
}); });
event.preventDefault(); event.preventDefault();
}); });
function addResult(blob) { function addResult(blob, filename) {
const container = document.getElementById("result-viewer"); const container = document.getElementById("result-viewer");
const title = document.createElement("h3"); const title = document.createElement("h3");
@ -136,24 +143,29 @@
title.textContent = "Result"; title.textContent = "Result";
const dl_icon = document.createElement("i"); const dl_icon = document.createElement("i");
dl_icon.classList.add("fa", "fa-download"); dl_icon.classList.add("fa", "fa-download", "mr2");
dl_icon.setAttribute("aria-hidden", "true"); dl_icon.setAttribute("aria-hidden", "true");
const dl_button = document.createElement("button"); const dl_link = document.createElement("a");
const dl_button = document.createElement("div");
dl_button.appendChild(dl_icon); dl_button.appendChild(dl_icon);
dl_button.appendChild(document.createTextNode(" Download")); dl_button.appendChild(document.createTextNode("Download"));
dl_button.classList.add(..."f4 white bg-green ba b--dark-green mt2 ph4 pv3 center mw5 db shadow-2 grow".split(" ")); dl_button.classList.add(..."f4 white bg-green ba b--dark-green mt2 flex items-center justify-center pv3 center db shadow-2 grow".split(" "));
dl_button.addEventListener("click", (event) => {
const file = window.URL.createObjectURL(blob); dl_link.href = window.URL.createObjectURL(blob);
window.location.assign(file); dl_link.download = filename;
});
dl_link.classList.add(..."center no-underline db mw5".split(" "));
dl_link.appendChild(dl_button);
const threejs_view = document.createElement("div"); const threejs_view = document.createElement("div");
threejs_view.classList.add(..."w-100 center h6".split(" ")); threejs_view.classList.add(..."w-100 center h6".split(" "));
container.appendChild(title); container.appendChild(title);
container.appendChild(threejs_view); container.appendChild(threejs_view);
container.appendChild(dl_button); container.appendChild(dl_link);
init(threejs_view, blob); init(threejs_view, blob);
animate(); animate();