|
@@ -5059,93 +5059,99 @@
|
|
|
"wav": "audio/wav",
|
|
"wav": "audio/wav",
|
|
|
"weba": "audio/webm"
|
|
"weba": "audio/webm"
|
|
|
};
|
|
};
|
|
|
|
|
+ const REGEXP_MATCH_STYLESHEET = /stylesheet_[0-9]+\.css/;
|
|
|
|
|
+ const REGEXP_MATCH_SCRIPT = /scripts\/[0-9]+\.js/;
|
|
|
|
|
+ const REGEXP_MATCH_ROOT_INDEX = /^([0-9_]+\/)?index\.html$/;
|
|
|
|
|
+ const REGEXP_MATCH_INDEX = /index\.html$/;
|
|
|
|
|
+ const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
|
|
|
+ const CHARSET_UTF8 = ";charset=utf-8";
|
|
|
if (Array.isArray(content)) {
|
|
if (Array.isArray(content)) {
|
|
|
content = new Blob([new Uint8Array(content)]);
|
|
content = new Blob([new Uint8Array(content)]);
|
|
|
}
|
|
}
|
|
|
zip.configure(zipOptions);
|
|
zip.configure(zipOptions);
|
|
|
const blobReader = new zip.BlobReader(content);
|
|
const blobReader = new zip.BlobReader(content);
|
|
|
- let resources = [];
|
|
|
|
|
const zipReader = new zip.ZipReader(blobReader);
|
|
const zipReader = new zip.ZipReader(blobReader);
|
|
|
const entries = await zipReader.getEntries();
|
|
const entries = await zipReader.getEntries();
|
|
|
const options = { password };
|
|
const options = { password };
|
|
|
|
|
+ let docContent, origDocContent, url, resources = [];
|
|
|
await Promise.all(entries.map(async entry => {
|
|
await Promise.all(entries.map(async entry => {
|
|
|
- let dataWriter, content, textContent, name, blob;
|
|
|
|
|
|
|
+ const { filename } = entry;
|
|
|
|
|
+ let dataWriter, content, textContent, mimeType;
|
|
|
if (!options.password && entry.encrypted) {
|
|
if (!options.password && entry.encrypted) {
|
|
|
options.password = prompt("Please enter the password to view the page");
|
|
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/)) {
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_STYLESHEET) || filename.match(REGEXP_MATCH_SCRIPT)) {
|
|
|
dataWriter = new zip.TextWriter();
|
|
dataWriter = new zip.TextWriter();
|
|
|
textContent = await entry.getData(dataWriter, options);
|
|
textContent = await entry.getData(dataWriter, options);
|
|
|
- if (entry.filename.match(/index\.html$/)) {
|
|
|
|
|
- mimeType = "text/html;charset=utf-8";
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_INDEX)) {
|
|
|
|
|
+ mimeType = "text/html" + CHARSET_UTF8;
|
|
|
} else {
|
|
} else {
|
|
|
- if (entry.filename.match(/stylesheet_[0-9]+\.css/)) {
|
|
|
|
|
- mimeType = "text/css;charset=utf-8";
|
|
|
|
|
- } else if (entry.filename.match(/scripts\/[0-9]+\.js/)) {
|
|
|
|
|
- mimeType = "text/javascript;charset=utf-8";
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_STYLESHEET)) {
|
|
|
|
|
+ mimeType = "text/css" + CHARSET_UTF8;
|
|
|
|
|
+ } else if (filename.match(REGEXP_MATCH_SCRIPT)) {
|
|
|
|
|
+ mimeType = "text/javascript" + CHARSET_UTF8;
|
|
|
}
|
|
}
|
|
|
if (textContent !== undefined) {
|
|
if (textContent !== undefined) {
|
|
|
- content = noBlobURL ? await getDataURI(textContent, mimeType) : URL.createObjectURL(new Blob([textContent], { type: mimeType }));
|
|
|
|
|
|
|
+ content = await getDataURI(textContent, mimeType);
|
|
|
} else {
|
|
} else {
|
|
|
content = "data:text/plain,";
|
|
content = "data:text/plain,";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- const extension = entry.filename.match(/\.([^.]+)/);
|
|
|
|
|
|
|
+ const extension = filename.match(/\.([^.]+)/);
|
|
|
if (extension && extension[1] && KNOWN_MIMETYPES[extension[1]]) {
|
|
if (extension && extension[1] && KNOWN_MIMETYPES[extension[1]]) {
|
|
|
mimeType = KNOWN_MIMETYPES[extension[1]];
|
|
mimeType = KNOWN_MIMETYPES[extension[1]];
|
|
|
} else {
|
|
} else {
|
|
|
mimeType = "application/octet-stream";
|
|
mimeType = "application/octet-stream";
|
|
|
}
|
|
}
|
|
|
- if (entry.filename.match(/frames\//) || noBlobURL) {
|
|
|
|
|
|
|
+ if (filename.match(/frames\//) || noBlobURL) {
|
|
|
content = await entry.getData(new zip.Data64URIWriter(mimeType), options);
|
|
content = await entry.getData(new zip.Data64URIWriter(mimeType), options);
|
|
|
} else {
|
|
} else {
|
|
|
- blob = await entry.getData(new zip.BlobWriter(mimeType), options);
|
|
|
|
|
|
|
+ const blob = await entry.getData(new zip.BlobWriter(mimeType), options);
|
|
|
content = URL.createObjectURL(blob);
|
|
content = URL.createObjectURL(blob);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- resources.push({ filename: entry.filename, name, url: entry.comment, content, mimeType, blob, textContent, parentResources: [] });
|
|
|
|
|
|
|
+ resources.push({ filename: entry.filename, url: entry.comment, content, mimeType, textContent, parentResources: [] });
|
|
|
}));
|
|
}));
|
|
|
await zipReader.close();
|
|
await zipReader.close();
|
|
|
- let docContent, origDocContent, url;
|
|
|
|
|
resources = resources.sort((resourceLeft, resourceRight) => resourceRight.filename.length - resourceLeft.filename.length);
|
|
resources = resources.sort((resourceLeft, resourceRight) => resourceRight.filename.length - resourceLeft.filename.length);
|
|
|
- const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
|
|
|
for (const resource of resources) {
|
|
for (const resource of resources) {
|
|
|
- if (resource.textContent !== undefined) {
|
|
|
|
|
|
|
+ let { textContent, mimeType, filename } = resource;
|
|
|
|
|
+ if (textContent !== undefined) {
|
|
|
let prefixPath = "";
|
|
let prefixPath = "";
|
|
|
- const prefixPathMatch = resource.filename.match(/(.*\/)[^/]+$/);
|
|
|
|
|
|
|
+ const prefixPathMatch = filename.match(/(.*\/)[^/]+$/);
|
|
|
if (prefixPathMatch && prefixPathMatch[1]) {
|
|
if (prefixPathMatch && prefixPathMatch[1]) {
|
|
|
prefixPath = prefixPathMatch[1];
|
|
prefixPath = prefixPathMatch[1];
|
|
|
}
|
|
}
|
|
|
- if (resource.filename.match(/^([0-9_]+\/)?index\.html$/)) {
|
|
|
|
|
- origDocContent = resource.textContent;
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_ROOT_INDEX)) {
|
|
|
|
|
+ origDocContent = textContent;
|
|
|
}
|
|
}
|
|
|
- const isScript = resource.filename.match(/scripts\/[0-9]+\.js/);
|
|
|
|
|
- if (!isScript) {
|
|
|
|
|
|
|
+ if (!filename.match(REGEXP_MATCH_SCRIPT)) {
|
|
|
|
|
+ const resourceFilename = filename;
|
|
|
await Promise.all(resources.map(async 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$/)) {
|
|
|
|
|
- const searchRegExp = new RegExp(filename.replace(REGEXP_ESCAPE, "\\$1"), "g");
|
|
|
|
|
- const position = resource.textContent.search(searchRegExp);
|
|
|
|
|
|
|
+ const { filename, parentResources, content } = innerResource;
|
|
|
|
|
+ if (filename.startsWith(prefixPath) && filename != resourceFilename) {
|
|
|
|
|
+ const relativeFilename = filename.substring(prefixPath.length);
|
|
|
|
|
+ if (!relativeFilename.match(/manifest\.json$/)) {
|
|
|
|
|
+ const searchRegExp = new RegExp(relativeFilename.replace(REGEXP_ESCAPE, "\\$1"), "g");
|
|
|
|
|
+ const position = textContent.search(searchRegExp);
|
|
|
if (position != -1) {
|
|
if (position != -1) {
|
|
|
- innerResource.parentResources.push(resource.filename);
|
|
|
|
|
- resource.textContent = resource.textContent.replace(searchRegExp, innerResource.content);
|
|
|
|
|
|
|
+ parentResources.push(resourceFilename);
|
|
|
|
|
+ textContent = textContent.replace(searchRegExp, content);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}));
|
|
}));
|
|
|
- resource.content = await getDataURI(resource.textContent, resource.mimeType);
|
|
|
|
|
|
|
+ resource.content = await getDataURI(textContent, mimeType);
|
|
|
|
|
+ resource.textContent = textContent;
|
|
|
}
|
|
}
|
|
|
- if (resource.filename.match(/index\.html$/)) {
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_INDEX)) {
|
|
|
if (shadowRootScriptURL) {
|
|
if (shadowRootScriptURL) {
|
|
|
- resource.textContent = resource.textContent.replace(/<script data-template-shadow-root.*<\/script>/g, "<script data-template-shadow-root src=" + shadowRootScriptURL + "></" + "script>");
|
|
|
|
|
|
|
+ resource.textContent = textContent.replace(/<script data-template-shadow-root.*<\/script>/g, "<script data-template-shadow-root src=" + shadowRootScriptURL + "></" + "script>");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (resource.filename.match(/^([0-9_]+\/)?index\.html$/)) {
|
|
|
|
|
- docContent = resource.textContent;
|
|
|
|
|
|
|
+ if (filename.match(REGEXP_MATCH_ROOT_INDEX)) {
|
|
|
|
|
+ docContent = textContent;
|
|
|
url = resource.url;
|
|
url = resource.url;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -5156,8 +5162,8 @@
|
|
|
const reader = new FileReader();
|
|
const reader = new FileReader();
|
|
|
reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
|
|
reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
- reader.addEventListener("load", () => resolve(reader.result), false);
|
|
|
|
|
- reader.addEventListener("error", reject, false);
|
|
|
|
|
|
|
+ reader.onload = () => resolve(reader.result);
|
|
|
|
|
+ reader.onerror = reject;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|