diff options
author | jaseg <git@jaseg.de> | 2023-04-09 17:53:54 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-04-10 23:57:15 +0200 |
commit | 888ae71889dfb4a9698f8f2607b649d384dd3738 (patch) | |
tree | 06f45df9adeddaf079c8bcc7a3376e90c8e06efc /gerbonara/cad/protoserve_data/protoserve.html | |
parent | fba189c69534fe0e88851e35716fe0e5d07a5c98 (diff) | |
download | gerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.tar.gz gerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.tar.bz2 gerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.zip |
protoserve: Gerber download works
Diffstat (limited to 'gerbonara/cad/protoserve_data/protoserve.html')
-rw-r--r-- | gerbonara/cad/protoserve_data/protoserve.html | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gerbonara/cad/protoserve_data/protoserve.html b/gerbonara/cad/protoserve_data/protoserve.html index 4b116b2..7bc9a30 100644 --- a/gerbonara/cad/protoserve_data/protoserve.html +++ b/gerbonara/cad/protoserve_data/protoserve.html @@ -268,7 +268,7 @@ input { <div id="links"> <a href="#controls">Settings</a> <a href="#preview">Preview</a> - <a href='/download'> + <a id="link-gerbers" href='#'> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em"> <title>Download</title> <!--! Font Awesome Pro 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32V274.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7V32zM64 352c-35.3 0-64 28.7-64 64v32c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V416c0-35.3-28.7-64-64-64H346.5l-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352H64zm368 56a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"/> @@ -863,7 +863,7 @@ input { } } - previewBlobURL = null; + let previewBlobURL = null; previewReloader = new RateLimiter(async () => { const response = await fetch('preview.svg', { method: 'POST', @@ -892,6 +892,30 @@ input { }); } + let downloadObjectURL = null; + document.querySelector('#link-gerbers').addEventListener('click', async () => { + const response = await fetch('gerbers.zip', { + method: 'POST', + mode: 'same-origin', + cache: 'no-cache', + headers: {'Content-Type': 'application/json'}, + body: serialize(), + }); + const data = await response.blob(); + /* cf. https://gist.github.com/devloco/5f779216c988438777b76e7db113d05c */ + const zipBlob = new Blob([data], { type: 'application/zip' }); + + if (downloadObjectURL) { + URL.revokeObjectURL(downloadObjectURL); + } + + downloadObjectURL = URL.createObjectURL(zipBlob); + let link = document.createElement('a'); + link.href = downloadObjectURL; + link.download = 'gerbers.zip'; + link.click(); + }); + hookupPreviewUpdate(document.querySelector('.group.board')); previewReloader.scheduleCall(); </script> |