From d3b8ef44ed9236fa4e5958ef3f93bb6078a0af0a Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Sat, 7 Apr 2018 06:29:36 +0000 Subject: [PATCH 1/5] Download Attachment changes. Support for Edge and change to Blob --- js/privatebin.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/js/privatebin.js b/js/privatebin.js index a39c38a..dffa4a2 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1925,7 +1925,34 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { { var imagePrefix = 'data:image/'; - $attachmentLink.attr('href', attachmentData); + if (window.Blob) { + var base64Start = attachmentData.indexOf(',') + 1; + var contentTypeEnd = attachmentData.indexOf(';'); + + var contentType = attachmentData.substring(5, contentTypeEnd); + var buf = Base64.atob(attachmentData.substring(base64Start)); + var bufLength = buf.length; + var array = new Uint8Array(bufLength); + + for (var i = 0; i < bufLength; i++) { + array[i] = buf.charCodeAt(i); + } + + var file = new window.Blob([ array ], { type: contentType }); + + if (navigator.msSaveBlob) { + $attachmentLink.bind('click', function () { + navigator.msSaveBlob(file, fileName); + }); + } else if (window.URL && window.URL.createObjectURL) { + $attachmentLink.attr('href', window.URL.createObjectURL(file)); + } else { + $attachmentLink.attr('href', attachmentData); + } + } else { + $attachmentLink.attr('href', attachmentData); + } + if (typeof fileName !== 'undefined') { $attachmentLink.attr('download', fileName); } @@ -1971,6 +1998,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { me.hideAttachmentPreview(); $attachmentLink.prop('href', ''); $attachmentLink.prop('download', ''); + $attachmentLink.unbind('click'); $attachmentPreview.html(''); }; From 2925fa8bfcf70d258fffb13962232345102c9940 Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Sun, 8 Apr 2018 22:36:55 +0000 Subject: [PATCH 2/5] Requested Changes, IE Download fix only --- js/privatebin.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index dffa4a2..f9fe5f9 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1925,12 +1925,22 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { { var imagePrefix = 'data:image/'; - if (window.Blob) { + // IE does not support setting a data URI on an a element + // Convert dataURI to a Blob and use msSaveBlob to download + if (window.Blob && navigator.msSaveBlob) { + // data URI format: data:[][;base64], + + // position in data URI string of where data begins var base64Start = attachmentData.indexOf(',') + 1; + // position in data URI string of where contentType ends var contentTypeEnd = attachmentData.indexOf(';'); + // extract contentType var contentType = attachmentData.substring(5, contentTypeEnd); + // extract data and convert to binary var buf = Base64.atob(attachmentData.substring(base64Start)); + + // Transform into a Blob var bufLength = buf.length; var array = new Uint8Array(bufLength); @@ -1940,15 +1950,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { var file = new window.Blob([ array ], { type: contentType }); - if (navigator.msSaveBlob) { - $attachmentLink.bind('click', function () { - navigator.msSaveBlob(file, fileName); - }); - } else if (window.URL && window.URL.createObjectURL) { - $attachmentLink.attr('href', window.URL.createObjectURL(file)); - } else { - $attachmentLink.attr('href', attachmentData); - } + $attachmentLink.bind('click', function () { + navigator.msSaveBlob(file, fileName); + }); } else { $attachmentLink.attr('href', attachmentData); } From 60cedd7fb56fb8add77fcd3e3a3126bef3598ade Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Mon, 9 Apr 2018 04:44:37 +0000 Subject: [PATCH 3/5] Only create Blob for Download for IE upon click event --- js/privatebin.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index f9fe5f9..9b1f33f 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1928,30 +1928,29 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { // IE does not support setting a data URI on an a element // Convert dataURI to a Blob and use msSaveBlob to download if (window.Blob && navigator.msSaveBlob) { - // data URI format: data:[][;base64], - - // position in data URI string of where data begins - var base64Start = attachmentData.indexOf(',') + 1; - // position in data URI string of where contentType ends - var contentTypeEnd = attachmentData.indexOf(';'); + $attachmentLink.bind('click', function () { + // data URI format: data:[][;base64], - // extract contentType - var contentType = attachmentData.substring(5, contentTypeEnd); - // extract data and convert to binary - var buf = Base64.atob(attachmentData.substring(base64Start)); + // position in data URI string of where data begins + var base64Start = attachmentData.indexOf(',') + 1; + // position in data URI string of where mediaType ends + var mediaTypeEnd = attachmentData.indexOf(';'); - // Transform into a Blob - var bufLength = buf.length; - var array = new Uint8Array(bufLength); + // extract mediaType + var mediaType = attachmentData.substring(5, mediaTypeEnd); + // extract data and convert to binary + var decodedData = Base64.atob(attachmentData.substring(base64Start)); - for (var i = 0; i < bufLength; i++) { - array[i] = buf.charCodeAt(i); - } + // Transform into a Blob + var decodedDataLength = decodedData.length; + var buf = new Uint8Array(decodedDataLength); - var file = new window.Blob([ array ], { type: contentType }); + for (var i = 0; i < decodedDataLength; i++) { + buf[i] = decodedData.charCodeAt(i); + } - $attachmentLink.bind('click', function () { - navigator.msSaveBlob(file, fileName); + var blob = new window.Blob([ buf ], { type: mediaType }); + navigator.msSaveBlob(blob, fileName); }); } else { $attachmentLink.attr('href', attachmentData); From 3f28f01b0ebaf3c7a78c44daf30b55a184327059 Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Mon, 9 Apr 2018 15:57:58 +0000 Subject: [PATCH 4/5] Switch from bind / unbind to on / off --- js/privatebin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 9b1f33f..c453788 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1928,7 +1928,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { // IE does not support setting a data URI on an a element // Convert dataURI to a Blob and use msSaveBlob to download if (window.Blob && navigator.msSaveBlob) { - $attachmentLink.bind('click', function () { + $attachmentLink.off('click').on('click', function () { // data URI format: data:[][;base64], // position in data URI string of where data begins @@ -2001,7 +2001,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { me.hideAttachmentPreview(); $attachmentLink.prop('href', ''); $attachmentLink.prop('download', ''); - $attachmentLink.unbind('click'); + $attachmentLink.off('click'); $attachmentPreview.html(''); }; From 5bee666a6b29701034e036ee3ce7a390257a2e61 Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Mon, 9 Apr 2018 16:40:10 +0000 Subject: [PATCH 5/5] Update SRI hashes --- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 890d159..a10a315 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index ee95728..6ddbd59 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): - +