normalize downloads around api download function

This commit is contained in:
Stewart Allen 2022-01-07 19:43:06 -05:00
commit 2720b37e1f
2 changed files with 33 additions and 13 deletions

View file

@ -86,24 +86,36 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
const driver = KIRI.driver.LASER; const driver = KIRI.driver.LASER;
function download_svg() { function download_svg() {
saveAs(new Blob( API.util.download(
[driver.exportSVG(settings, data)], driver.exportSVG(settings, data),
{type:"application/octet-stream"}), $('print-filename').value + ".svg"
$('print-filename').value + ".svg"); );
// saveAs(new Blob(
// [driver.exportSVG(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".svg");
} }
function download_dxf() { function download_dxf() {
saveAs(new Blob( API.util.download(
[driver.exportDXF(settings, data)], driver.exportDXF(settings, data),
{type:"application/octet-stream"}), $('print-filename').value + ".dxf"
$('print-filename').value + ".dxf"); );
// saveAs(new Blob(
// [driver.exportDXF(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".dxf");
} }
function download_gcode() { function download_gcode() {
saveAs(new Blob( API.util.download(
[driver.exportGCode(settings, data)], driver.exportGCode(settings, data),
{type:"application/octet-stream"}), $('print-filename').value + ".gcode"
$('print-filename').value + ".gcode"); );
// saveAs(new Blob(
// [driver.exportGCode(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".gcode");
} }
API.ajax("/kiri/output-laser.html", function(html) { API.ajax("/kiri/output-laser.html", function(html) {
@ -397,7 +409,8 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
function download() { function download() {
filename = $('print-filename').value; filename = $('print-filename').value;
saveAs(getBlob(), filename + "." + fileext); API.util.download(gcode, filename + "." + fileext);
// saveAs(getBlob(), filename + "." + fileext);
} }
function pad(v) { function pad(v) {

View file

@ -3344,6 +3344,13 @@
let url = WIN.URL.createObjectURL(new Blob([data], {type: "octet/stream"})); let url = WIN.URL.createObjectURL(new Blob([data], {type: "octet/stream"}));
$('mod-any').innerHTML = `<a id="_dexport_" href="${url}" download="${filename}">x</a>`; $('mod-any').innerHTML = `<a id="_dexport_" href="${url}" download="${filename}">x</a>`;
$('_dexport_').click(); $('_dexport_').click();
// fixes Chrome/iOS download, but loses name and breaks others
// let reader = new FileReader();
// let out = new Blob([data], {type: 'octet/stream'});
// reader.onload = function(e){
// window.location.href = reader.result;
// }
// reader.readAsDataURL(out);
} }
// prevent safari from exiting full screen mode // prevent safari from exiting full screen mode