Skip to content

Commit e084b41

Browse files
authored
misc fixes: (#176)
- 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
1 parent 879018d commit e084b41

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

dist/sw.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/collection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Collection {
123123
<body style="font-family: sans-serif">
124124
<h2>Archived Page Not Found</h2>
125125
<p>Sorry, this page was not found in this archive:</p>
126-
<p><code style="word-break: break-all; font-size: larger">${requestURL}</code></p>
126+
<p><code id="url" style="word-break: break-all; font-size: larger"></code></p>
127127
${this.liveRedirectOnNotFound && request.mode === "navigate" ? `
128128
<p>Redirecting to live page now... (If this URL is a file download, the download should have started).</p>
129129
<script>
@@ -138,6 +138,7 @@ class Collection {
138138
</p>
139139
140140
<script>
141+
document.querySelector("#url").innerText = "${requestURL}";
141142
let isTop = true;
142143
try {
143144
if (window.parent._WB_wombat_location) {

src/wacz/ziprangereader.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,39 @@ export class HashingAsyncIterReader extends AsyncIterReader
2121
{
2222
constructor(source, compressed = "gzip", dechunk = false) {
2323
super(source, compressed, dechunk);
24+
this.hasher = null;
25+
this.hashInited = false;
26+
this.hash = "";
2427
}
2528

2629
async initHasher() {
27-
this.hasher = await createSHA256();
30+
try {
31+
this.hasher = await createSHA256();
32+
} catch (e) {
33+
console.warn("Hasher init failed, not hashing", e);
34+
} finally {
35+
this.hashInited = true;
36+
}
2837
}
2938

3039
async _loadNext() {
3140
const value = await super._loadNext();
3241
if (value) {
33-
this.hasher.update(value);
42+
if (!this.hashInited) {
43+
await this.initHasher();
44+
}
45+
if (this.hasher) {
46+
this.hasher.update(value);
47+
}
48+
} else if (this.hasher) {
49+
this.hash = "sha256:" + this.hasher.digest("hex");
50+
this.hasher = null;
3451
}
3552
return value;
3653
}
3754

3855
getHash() {
39-
return "sha256:" + this.hasher.digest("hex");
56+
return this.hash;
4057
}
4158
}
4259

@@ -288,10 +305,6 @@ export class ZipRangeReader
288305
reader = wrapHasher(reader);
289306
}
290307

291-
if (hasher) {
292-
await hasher.initHasher();
293-
}
294-
295308
return {reader, hasher};
296309
}
297310

0 commit comments

Comments
 (0)