|
|
@@ -5074,12 +5074,26 @@
|
|
|
options.password = prompt("Please enter the password to view the page");
|
|
|
}
|
|
|
name = entry.filename.match(/^([0-9_]+\/)?(.*)$/)[2];
|
|
|
+ let mimeType;
|
|
|
if (entry.filename.match(/index\.html$/) || entry.filename.match(/stylesheet_[0-9]+\.css/) || entry.filename.match(/scripts\/[0-9]+\.js/)) {
|
|
|
dataWriter = new zip.TextWriter();
|
|
|
textContent = await entry.getData(dataWriter, options);
|
|
|
+ if (entry.filename.match(/index\.html$/)) {
|
|
|
+ mimeType = "text/html";
|
|
|
+ } else {
|
|
|
+ if (entry.filename.match(/stylesheet_[0-9]+\.css/)) {
|
|
|
+ mimeType = "text/css";
|
|
|
+ } else if (entry.filename.match(/scripts\/[0-9]+\.js/)) {
|
|
|
+ mimeType = "text/javascript";
|
|
|
+ }
|
|
|
+ if (textContent !== undefined) {
|
|
|
+ content = noBlobURL ? await getDataURI(textContent, mimeType) : URL.createObjectURL(new Blob([textContent], { type: mimeType }));
|
|
|
+ } else {
|
|
|
+ content = "data:text/plain,";
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
const extension = entry.filename.match(/\.([^.]+)/);
|
|
|
- let mimeType;
|
|
|
if (extension && extension[1] && KNOWN_MIMETYPES[extension[1]]) {
|
|
|
mimeType = KNOWN_MIMETYPES[extension[1]];
|
|
|
} else {
|
|
|
@@ -5092,7 +5106,7 @@
|
|
|
content = URL.createObjectURL(blob);
|
|
|
}
|
|
|
}
|
|
|
- resources.push({ filename: entry.filename, name, url: entry.comment, content, blob, textContent, parentResources: [] });
|
|
|
+ resources.push({ filename: entry.filename, name, url: entry.comment, content, mimeType, blob, textContent, parentResources: [] });
|
|
|
}));
|
|
|
await zipReader.close();
|
|
|
let docContent, origDocContent, url;
|
|
|
@@ -5110,7 +5124,7 @@
|
|
|
}
|
|
|
const isScript = resource.filename.match(/scripts\/[0-9]+\.js/);
|
|
|
if (!isScript) {
|
|
|
- resources.forEach(innerResource => {
|
|
|
+ await Promise.all(resources.map(async innerResource => {
|
|
|
if (innerResource.filename.startsWith(prefixPath) && innerResource.filename != resource.filename) {
|
|
|
const filename = innerResource.filename.substring(prefixPath.length);
|
|
|
if (!filename.match(/manifest\.json$/)) {
|
|
|
@@ -5122,15 +5136,10 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ }));
|
|
|
+ resource.content = await getDataURI(resource.textContent, resource.mimeType);
|
|
|
}
|
|
|
- let mimeType;
|
|
|
- if (resource.filename.match(/stylesheet_[0-9]+\.css/)) {
|
|
|
- mimeType = "text/css";
|
|
|
- } else if (isScript) {
|
|
|
- mimeType = "text/javascript";
|
|
|
- } else if (resource.filename.match(/index\.html$/)) {
|
|
|
- mimeType = "text/html";
|
|
|
+ if (resource.filename.match(/index\.html$/)) {
|
|
|
if (shadowRootScriptURL) {
|
|
|
resource.textContent = resource.textContent.replace(/<script data-template-shadow-root.*<\/script>/g, "<script data-template-shadow-root src=" + shadowRootScriptURL + "></" + "script>");
|
|
|
}
|
|
|
@@ -5138,21 +5147,19 @@
|
|
|
if (resource.filename.match(/^([0-9_]+\/)?index\.html$/)) {
|
|
|
docContent = resource.textContent;
|
|
|
url = resource.url;
|
|
|
- } else {
|
|
|
- const reader = new FileReader();
|
|
|
- if (resource.textContent) {
|
|
|
- reader.readAsDataURL(new Blob([resource.textContent], { type: mimeType + ";charset=utf-8" }));
|
|
|
- resource.content = await new Promise((resolve, reject) => {
|
|
|
- reader.addEventListener("load", () => resolve(reader.result), false);
|
|
|
- reader.addEventListener("error", reject, false);
|
|
|
- });
|
|
|
- } else {
|
|
|
- resource.content = "data:text/plain,";
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return { docContent, origDocContent, resources, url };
|
|
|
+
|
|
|
+ async function getDataURI(textContent, mimeType) {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ reader.addEventListener("load", () => resolve(reader.result), false);
|
|
|
+ reader.addEventListener("error", reject, false);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|