diff --git a/src/main.py b/src/main.py index fea3275..af2b1e9 100644 --- a/src/main.py +++ b/src/main.py @@ -493,6 +493,5 @@ def camera_status(): else: socketio.emit("camera_status", False) - if __name__ == "__main__": app.run(use_reloader=False, host="0.0.0.0", ssl_context="adhoc") diff --git a/src/static/js/webcam.js b/src/static/js/webcam.js index 69926f0..aa35687 100644 --- a/src/static/js/webcam.js +++ b/src/static/js/webcam.js @@ -198,10 +198,11 @@ function setup_events(){ const data = await take_picture(); if (!data) { - throw new Error("No image was captured"); + console.error("Print failed: No image was captured"); + } else { + console.log("Printing picture"); + const print_status = await print_picture(data); } - - await print_picture(data); } catch (e) { console.error("Print failed:", e); alert(`Failed to print: ${e.message || e}`); @@ -241,7 +242,8 @@ function take_picture() { const w = video.videoWidth; const h = video.videoHeight; if (!w || !h) { - throw new Error(`Invalid video dimensions: ${w} × ${h}`); + console.log(`Invalid video dimensions: ${w} × ${h}`); + return null; } canvas.width = w; @@ -252,7 +254,8 @@ function take_picture() { console.log("Captured image:", data.slice(0, 30), "length:", data.length); if (data.length < 100) { - throw new Error("Captured image is empty"); + console.log("Captured image is empty"); + return null } return data; } @@ -272,10 +275,15 @@ async function print_picture(data) { formData.set("cut", true); formData.set("process", false); - fetch("/api/print/img", { + const res = await fetch("/api/print/img", { method: "POST", body: formData }); + if(!res.ok){ + throw new Error("Printing failed" + res.statusText); + } else { + return true; + } } function flip_cameras(){