Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions handleCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ function handleZip(file) {
zip.loadAsync(file)
.then(function (zip) {
$('.zip-select span').text(file.name)
if (!zip.files[`widget.ini`]) {
handleUnsupported(zip)
return
}
zip.files[`widget.ini`].async('string')
.then((data) => {
if (zip.files['manifest.json']) {
zip.files['manifest.json'].async('string').then((data) => {
try {
readFiles(zip, parseJsonManifest(data));
} catch(err) {
alert('The included manifest.json was malformed. '
+ 'Please re-package your widget.');
handleUnsupported(zip);
}
});
} else if (zip.files['widget.ini']) {
zip.files[`widget.ini`].async('string').then((data) => {
pathArray = handleIniData(data);
if (pathArray.length != 5) {
handleUnsupported(zip)
Expand All @@ -100,10 +106,22 @@ function handleZip(file) {
return
}
readFiles(zip, pathArray);
})
});
} else {
handleUnsupported(zip);
}
});
}

function parseJsonManifest(jsonData) {
const json = JSON.parse(jsonData);
if (!json || !json.fileMap) {
throw new Error('Invalid manifest.json');
}
const { html, css, js, fields, data } = json.fileMap;
return [html, css, js, fields, data];
}

function handleUnsupported(zip) {
// alert("This widget is not supported.")
resetSession()
Expand Down Expand Up @@ -493,4 +511,4 @@ const dialog = `
<div class="md-dialog-focus-trap" tabindex="0"></div>
</div>
</div>
`
`