Skip to content

Commit

Permalink
misc fixes:
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 9c1f6f0 commit 0bfb2d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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
28 changes: 20 additions & 8 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 All @@ -48,7 +65,6 @@ export class ZipRangeReader
this.entries = entries;
this.entriesUpdated = false;

// todo: make configurable
this.enableHashing = true;
}

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

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

return {reader, hasher};
}

Expand Down

0 comments on commit 0bfb2d1

Please sign in to comment.