Skip to content
This repository was archived by the owner on Oct 4, 2025. It is now read-only.

Commit 5f39285

Browse files
committed
ipfs: support ipfs unpin/clear (when supported by auto-js-ipfs)
deps: update to auto-js-ipfs 2.0.0
1 parent 2b9eee1 commit 5f39285

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"browser": "dist/sw.js",
44
"main": "index.js",
55
"type": "module",
6-
"version": "0.1.2",
6+
"version": "0.1.3",
77
"license": "AGPL-3.0-or-later",
88
"exports": {
99
".": "./src/index.js"
1010
},
1111
"dependencies": {
1212
"@ipld/car": "^5.0.1",
1313
"@ipld/unixfs": "^2.0.0",
14-
"@webrecorder/wabac": "^2.13.8",
14+
"@webrecorder/wabac": "^2.13.9",
1515
"client-zip": "^2.3.0",
1616
"hash-wasm": "^4.9.0",
1717
"idb": "^7.1.1",

src/ipfsutils.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
2525
downloaderOpts.markers = {ZIP, WARC_PAYLOAD, WARC_GROUP};
2626
}
2727

28-
const dl = new Downloader({...downloaderOpts, coll, filename, gzip: false});
28+
const gzip = replayOpts.gzip !== undefined ? replayOpts.gzip : true;
29+
30+
const dl = new Downloader({...downloaderOpts, coll, filename, gzip});
2931
const dlResponse = await dl.download(progress);
3032

3133
if (!coll.config.metadata.ipfsPins) {
@@ -53,8 +55,16 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
5355
UnixFS.withCapacity(capacity)
5456
);
5557

56-
const swContent = await fetchBuffer("sw.js", replayOpts.replayBaseUrl);
57-
const uiContent = await fetchBuffer("ui.js", replayOpts.replayBaseUrl);
58+
const swContent = await fetchBuffer("sw.js", replayOpts.replayBaseUrl || self.location.href);
59+
const uiContent = await fetchBuffer("ui.js", replayOpts.replayBaseUrl || self.location.href);
60+
61+
let favicon = null;
62+
63+
try {
64+
favicon = await fetchBuffer("https://replayweb.page/build/icon.png");
65+
} catch (e) {
66+
console.warn("Couldn't load favicon");
67+
}
5868

5969
let url, cid;
6070

@@ -74,7 +84,7 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
7484
writable,
7585
dlResponse.filename, dlResponse.body,
7686
swContent, uiContent, replayOpts,
77-
downloaderOpts.markers,
87+
downloaderOpts.markers, favicon,
7888
);
7989

8090
await p;
@@ -90,8 +100,14 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
90100

91101
export async function ipfsRemove(coll) {
92102
if (coll.config.metadata.ipfsPins) {
93-
//TODO: need remove support in auto-js-ipfs
94-
//await ipfsUnpinAll(this, coll.config.metadata.ipfsPins);
103+
104+
for (const {url} of coll.config.metadata.ipfsPins) {
105+
try {
106+
await autoipfs.clear(url);
107+
} catch (e) {
108+
console.log("Removal from this IPFS backend not yet implemented");
109+
}
110+
}
95111

96112
coll.config.metadata.ipfsPins = null;
97113
return true;
@@ -100,7 +116,7 @@ export async function ipfsRemove(coll) {
100116
return false;
101117
}
102118

103-
async function fetchBuffer(filename, replayBaseUrl = self.location.href) {
119+
async function fetchBuffer(filename, replayBaseUrl) {
104120
const resp = await fetch(new URL(filename, replayBaseUrl).href);
105121

106122
return new Uint8Array(await resp.arrayBuffer());
@@ -121,7 +137,7 @@ async function ipfsWriteBuff(writer, name, content, dir) {
121137

122138
// ===========================================================================
123139
export async function ipfsGenerateCar(writable, waczPath,
124-
waczContent, swContent, uiContent, replayOpts, markers) {
140+
waczContent, swContent, uiContent, replayOpts, markers, favicon) {
125141

126142
const writer = UnixFS.createWriter({ writable });
127143

@@ -141,6 +157,10 @@ export async function ipfsGenerateCar(writable, waczPath,
141157
await ipfsWriteBuff(writer, "sw.js", swContent, rootDir);
142158
}
143159

160+
if (favicon) {
161+
await ipfsWriteBuff(writer, "favicon.ico", favicon, rootDir);
162+
}
163+
144164
await ipfsWriteBuff(writer, "index.html", encoder.encode(htmlContent), rootDir);
145165

146166
if (!markers) {
@@ -354,7 +374,7 @@ export async function encodeBlocks(blocks, root) {
354374
}
355375

356376
function getReplayHtml(waczPath, replayOpts = {}) {
357-
const { showEmbed, pageUrl, pageTitle } = replayOpts;
377+
const { showEmbed, pageUrl, pageTitle, deepLink } = replayOpts;
358378

359379
return `
360380
<!doctype html>
@@ -375,7 +395,7 @@ function getReplayHtml(waczPath, replayOpts = {}) {
375395
</style>
376396
</head>
377397
<body>${showEmbed ? `
378-
<replay-web-page deepLink="true" url="${pageUrl}" embed="replay-with-info" src="${waczPath}"></replay-web-page>` : `
398+
<replay-web-page ${deepLink ? `deepLink="true" ` : ""}url="${pageUrl}" embed="replay-with-info" src="${waczPath}"></replay-web-page>` : `
379399
<replay-app-main source="${waczPath}"></replay-app-main>`
380400
}
381401
</body>

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,16 @@
495495
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.0.tgz#f08ea194e01ed45379383a8886e8c85a65a5f26a"
496496
integrity sha512-Rumq5mHvGXamnOh3O8yLk1sjx8dB30qF1OeR6VC00DIR6SLJ4bwwUGKC4pE7qBFoQyyh0H9sAg3fikYgAqVR0w==
497497

498-
"@webrecorder/wabac@^2.13.8":
499-
version "2.13.8"
500-
resolved "https://registry.yarnpkg.com/@webrecorder/wabac/-/wabac-2.13.8.tgz#e77a17d1423829273e3c1a0cf8ac75e0a67ce708"
501-
integrity sha512-42WfTZbzU7uALHuMUWED5QvKQbXb9DpooXaRjjo00eU9MkxIGXnbavKgmgucFBIr9Rl854YxUa055F2D95xNVg==
498+
"@webrecorder/wabac@^2.13.9":
499+
version "2.13.9"
500+
resolved "https://registry.yarnpkg.com/@webrecorder/wabac/-/wabac-2.13.9.tgz#7c01777231386c714a984fadfd55340848bfbfca"
501+
integrity sha512-ozaO4fs4XwgbueQkwS+8ghHjhpp/iP3R7dCZJ09BWgowI5hMwjJY0KAKjWbFVDH1RQ4cPkh8KPQWAdI+x2wR2g==
502502
dependencies:
503503
"@peculiar/asn1-ecc" "^2.3.0"
504504
"@peculiar/asn1-schema" "^2.3.0"
505505
"@peculiar/x509" "^1.8.3"
506506
"@webrecorder/wombat" "^3.3.11"
507-
auto-js-ipfs "^1.5.1"
507+
auto-js-ipfs "^2.0.0"
508508
base64-js "^1.5.1"
509509
brotli "^1.3.3"
510510
buffer "^6.0.3"
@@ -602,10 +602,10 @@ asn1js@^3.0.5:
602602
pvutils "^1.1.3"
603603
tslib "^2.4.0"
604604

605-
auto-js-ipfs@^1.5.1:
606-
version "1.5.1"
607-
resolved "https://registry.yarnpkg.com/auto-js-ipfs/-/auto-js-ipfs-1.5.1.tgz#22693c76d678ea12bd296186b8920d1333e8afe6"
608-
integrity sha512-KMLYrxJA9FJBdmPTSouddPmlF+aZV4hP1E9ZBxbQWQZFMmK8lDjQOxHbuT1z4I8hhQmin3Y1RQNN5/s+om3E9Q==
605+
auto-js-ipfs@^2.0.0:
606+
version "2.0.0"
607+
resolved "https://registry.yarnpkg.com/auto-js-ipfs/-/auto-js-ipfs-2.0.0.tgz#299787949d22abc3d4ae27bdd7b47b71a44df9db"
608+
integrity sha512-52BHpc0uZPdetBjFuQJRG2V8DPIpQ/1LdteGXrnU7BSxKCgdaPpxils4M8YJ+jL/Kc2iPMA6xcJ1AvGM3klfjw==
609609

610610
balanced-match@^1.0.0:
611611
version "1.0.2"

0 commit comments

Comments
 (0)