Skip to content

Commit

Permalink
chore(JGIVEN-3): Fix Pako zip parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
l-1squared committed Oct 11, 2024
1 parent 88f2ba2 commit 76482c9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
8 changes: 4 additions & 4 deletions legacy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"debug": "webpack-dev-server -d --progress",
"test": "karma start --debug --single-run --browsers jsdom",
"test-watch": "karma start --debug",
"build": "mkdir dist && webpack --progress",
"build": "mkdir dist && webpack --progress --mode=development",
"integration-test": "yarn build && rm -rf integration && cp -r dist integration && cp -r data integration",
"analyze-bundle": "webpack --json | webpack-bundle-size-analyzer"
},
Expand Down Expand Up @@ -87,6 +87,6 @@
"jquery": "3.5.0",
"lodash": "4.17.21",
"modernizr": "^3.8.0",
"pako": "^1.0.3"
"pako": "^2.1.0"
}
}
80 changes: 45 additions & 35 deletions legacy/src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,49 @@ var pako = require('pako')
* This variable can also be used by the custom Javascript file.
*/
window.jgivenReport = {
scenarios: [],
customNavigationLinks: [],

setTags: function setTags (tagFile) {
this.tagFile = tagFile;
},

setMetaData: function setMetaData (metaData) {
this.metaData = metaData;
_.forEach(metaData.data, function (x) {
document.writeln("<script src='data/" + x + "'></script>");
});
},

addZippedScenarios: function addZippedScenarios (zip) {
var string = pako.ungzip(atob(zip), {to: 'string'})
var unzipped = JSON.parse(string);
this.addScenarios(unzipped.scenarios);
},

addScenarios: function addScenarios (scenarios) {
this.scenarios = this.scenarios.concat(scenarios);
},

setAllScenarios: function setAllScenarios (allScenarios) {
this.scenarios = allScenarios;
},

addNavigationLink: function addNavigationLink (link) {
this.customNavigationLinks.push(link);
},

setTitle: function setTitle (title) {
this.metaData.title = title;
}
scenarios: [],
customNavigationLinks: [],

setTags: function setTags(tagFile) {
this.tagFile = tagFile;
},

setMetaData: function setMetaData(metaData) {
this.metaData = metaData;
_.forEach(metaData.data, function (x) {
document.writeln("<script src='data/" + x + "'></script>");
});
},

addZippedScenarios: function addZippedScenarios(zip) {
var string = pako.inflate(this.base64ToUint8Array(zip), {to: 'string'})
var unzipped = JSON.parse(string);
this.addScenarios(unzipped.scenarios);
},

base64ToUint8Array(base64) {
const binaryString = window.atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
},

addScenarios: function addScenarios(scenarios) {
this.scenarios = this.scenarios.concat(scenarios);
},

setAllScenarios: function setAllScenarios(allScenarios) {
this.scenarios = allScenarios;
},

addNavigationLink: function addNavigationLink(link) {
this.customNavigationLinks.push(link);
},

setTitle: function setTitle(title) {
this.metaData.title = title;
}
};
8 changes: 4 additions & 4 deletions legacy/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4287,10 +4287,10 @@ p-try@^2.0.0:
resolved "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==

pako@^1.0.3:
version "1.0.11"
resolved "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
pako@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

param-case@^3.0.4:
version "3.0.4"
Expand Down

0 comments on commit 76482c9

Please sign in to comment.