Skip to content

Commit

Permalink
Fix JSZip date offset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pkong-ds committed Jun 6, 2024
1 parent 9e6e431 commit 709613e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion public/scripts/download-python-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ function dataURLtoFile(dataurl, filename) {
return new File([u8arr], filename, { type: mime });
}

function getJSZipDateWithOffset() {
// copied workaround to fix JSZip bug https://github.com/Stuk/jszip/issues/369#issuecomment-388324954
const currDate = new Date();
const dateWithOffset = new Date(currDate.getTime() - currDate.getTimezoneOffset() * 60000);

return dateWithOffset
}
async function generateZIP() {
var zip = new JSZip();
var count = 0;
Expand All @@ -36,7 +43,7 @@ async function generateZIP() {
var filename = unescape(k.substring(3, k.length)) + ".png";
var image = await fetch(imgURL);
var imageBlob = await image.blob();
zip.file(filename, imageBlob, { binary: true });
zip.file(filename, imageBlob, { binary: true, date: getJSZipDateWithOffset() });
count++;
if (count == images.size) {
zip.generateAsync({ type: "blob" }).then(function (content) {
Expand Down

0 comments on commit 709613e

Please sign in to comment.