Skip to content

Commit

Permalink
misc fixes: (#176)
Browse files Browse the repository at this point in the history
- escape URL on not found page, partial fix for webrecorder/replayweb.page#323
- hashiterator: more efficient use of createSHA256(), init on first use, unreference when done, catch error on init
  • Loading branch information
ikreymer committed Jun 9, 2024
1 parent 879018d commit e084b41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/sw.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Collection {
<body style="font-family: sans-serif">
<h2>Archived Page Not Found</h2>
<p>Sorry, this page was not found in this archive:</p>
<p><code style="word-break: break-all; font-size: larger">${requestURL}</code></p>
<p><code id="url" style="word-break: break-all; font-size: larger"></code></p>
${this.liveRedirectOnNotFound && request.mode === "navigate" ? `
<p>Redirecting to live page now... (If this URL is a file download, the download should have started).</p>
<script>
Expand All @@ -138,6 +138,7 @@ class Collection {
</p>
<script>
document.querySelector("#url").innerText = "${requestURL}";
let isTop = true;
try {
if (window.parent._WB_wombat_location) {
Expand Down
27 changes: 20 additions & 7 deletions src/wacz/ziprangereader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,39 @@ export class HashingAsyncIterReader extends AsyncIterReader
{
constructor(source, compressed = "gzip", dechunk = false) {
super(source, compressed, dechunk);
this.hasher = null;
this.hashInited = false;
this.hash = "";
}

async initHasher() {
this.hasher = await createSHA256();
try {
this.hasher = await createSHA256();
} catch (e) {
console.warn("Hasher init failed, not hashing", e);
} finally {
this.hashInited = true;
}
}

async _loadNext() {
const value = await super._loadNext();
if (value) {
this.hasher.update(value);
if (!this.hashInited) {
await this.initHasher();
}
if (this.hasher) {
this.hasher.update(value);
}
} else if (this.hasher) {
this.hash = "sha256:" + this.hasher.digest("hex");
this.hasher = null;
}
return value;
}

getHash() {
return "sha256:" + this.hasher.digest("hex");
return this.hash;
}
}

Expand Down Expand Up @@ -288,10 +305,6 @@ export class ZipRangeReader
reader = wrapHasher(reader);
}

if (hasher) {
await hasher.initHasher();
}

return {reader, hasher};
}

Expand Down

0 comments on commit e084b41

Please sign in to comment.