Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc fixes: #176

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading