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

Commit e43e384

Browse files
authored
IPFS fail notify (#7)
* return 404 if ipfs share failed clear autoipfs opts if share/unshare fails * bump to 0.3.2
1 parent 9617a70 commit e43e384

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@webrecorder/awp-sw",
33
"browser": "dist/sw.js",
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"main": "index.js",
66
"type": "module",
77
"repository": {

src/api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ class ExtAPI extends API
134134
event.waitUntil(p);
135135
}
136136

137+
try {
138+
await p;
139+
} catch (e) {
140+
return {error: "ipfs_not_available"};
141+
}
142+
137143
return {collId};
138144
}
139145

src/ipfsutils.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
8989

9090
let url, cid;
9191

92+
let reject = null;
93+
94+
const p2 = new Promise((res, rej) => reject = rej);
95+
9296
const p = readable
9397
.pipeThrough(new ShardingStream(shardSize))
94-
.pipeThrough(new ShardStoringStream(autoipfs, concur))
98+
.pipeThrough(new ShardStoringStream(autoipfs, concur, reject))
9599
.pipeTo(
96100
new WritableStream({
97101
write: (res) => {
@@ -113,7 +117,7 @@ export async function ipfsAdd(coll, downloaderOpts = {}, replayOpts = {}, progre
113117
downloaderOpts.markers, favicon,
114118
);
115119

116-
await p;
120+
await Promise.race([p, p2]);
117121

118122
const res = {cid: cid.toString(), url};
119123

@@ -135,7 +139,9 @@ export async function ipfsRemove(coll) {
135139
try {
136140
await autoipfs.clear(url);
137141
} catch (e) {
138-
console.log("Removal from this IPFS backend not yet implemented");
142+
console.log("Failed to unpin");
143+
autoipfsOpts.daemonURL = null;
144+
return false;
139145
}
140146
}
141147

@@ -493,7 +499,7 @@ export class ShardingStream extends TransformStream {
493499
* @extends {TransformStream<import('./types').CARFile, import('./types').CARMetadata>}
494500
*/
495501
export class ShardStoringStream extends TransformStream {
496-
constructor(autoipfs, concurrency) {
502+
constructor(autoipfs, concurrency, reject) {
497503
const queue = new Queue({ concurrency });
498504
const abortController = new AbortController();
499505
super({
@@ -513,6 +519,8 @@ export class ShardStoringStream extends TransformStream {
513519
} catch (err) {
514520
controller.error(err);
515521
abortController.abort(err);
522+
autoipfsOpts.daemonURL = null;
523+
reject(err);
516524
}
517525
},
518526
{ signal: abortController.signal }

0 commit comments

Comments
 (0)