1
- import { type Collection } from "@webrecorder/wabac/swlib" ;
1
+ import { type CollMetadata , type Collection } from "@webrecorder/wabac/swlib" ;
2
2
import { Downloader , type DownloaderOpts , type Markers } from "./downloader" ;
3
3
4
4
// @ts -expect-error no types
@@ -31,6 +31,10 @@ type ReplayOpts = {
31
31
loading ?: boolean ;
32
32
} ;
33
33
34
+ type MetadataWithIPFS = CollMetadata & {
35
+ ipfsPins ?: { url : string , cid : string } [ ] | null ;
36
+ }
37
+
34
38
export async function setAutoIPFSUrl ( url : string ) {
35
39
if ( autoipfsOpts . daemonURL !== url ) {
36
40
autoipfs = null ;
@@ -66,8 +70,10 @@ export async function ipfsAdd(
66
70
throw new Error ( dlResponse . error ) ;
67
71
}
68
72
69
- if ( ! coll . config . metadata . ipfsPins ) {
70
- coll . config . metadata . ipfsPins = [ ] ;
73
+ const metadata : MetadataWithIPFS = coll . config . metadata || { } ;
74
+
75
+ if ( ! metadata . ipfsPins ) {
76
+ metadata . ipfsPins = [ ] ;
71
77
}
72
78
73
79
let concur ;
@@ -120,8 +126,8 @@ export async function ipfsAdd(
120
126
121
127
progress ( 0 , totalSize ) ;
122
128
123
- let url ,
124
- cid = "" ;
129
+ let url = "" ;
130
+ let cid = "" ;
125
131
126
132
let reject : ( ( reason ?: string ) => void ) | null = null ;
127
133
@@ -132,7 +138,7 @@ export async function ipfsAdd(
132
138
. pipeThrough ( new ShardStoringStream ( autoipfs , concur , reject ! ) )
133
139
. pipeTo (
134
140
new WritableStream ( {
135
- write : ( res ) => {
141
+ write : ( res : { url : string , cid : string , size : number } ) => {
136
142
if ( res . url && res . cid ) {
137
143
url = res . url ;
138
144
cid = res . cid ;
@@ -160,7 +166,7 @@ export async function ipfsAdd(
160
166
161
167
const res = { cid : cid . toString ( ) , url } ;
162
168
163
- coll . config . metadata . ipfsPins . push ( res ) ;
169
+ metadata . ipfsPins . push ( res ) ;
164
170
165
171
console . log ( "ipfs cid added " + url ) ;
166
172
@@ -172,8 +178,10 @@ export async function ipfsRemove(coll: Collection) {
172
178
autoipfs = await createAutoIPFS ( autoipfsOpts ) ;
173
179
}
174
180
175
- if ( coll . config . metadata . ipfsPins ) {
176
- for ( const { url } of coll . config . metadata . ipfsPins ) {
181
+ const metadata : MetadataWithIPFS = coll . config . metadata || { } ;
182
+
183
+ if ( metadata . ipfsPins ) {
184
+ for ( const { url } of metadata . ipfsPins ) {
177
185
try {
178
186
await autoipfs . clear ( url ) ;
179
187
} catch ( _e ) {
@@ -183,7 +191,7 @@ export async function ipfsRemove(coll: Collection) {
183
191
}
184
192
}
185
193
186
- coll . config . metadata . ipfsPins = null ;
194
+ metadata . ipfsPins = null ;
187
195
return true ;
188
196
}
189
197
@@ -205,6 +213,7 @@ async function ipfsWriteBuff(
205
213
const file = UnixFS . createFileWriter ( writer ) ;
206
214
if ( content instanceof Uint8Array ) {
207
215
await file . write ( content ) ;
216
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
208
217
} else if ( content [ Symbol . asyncIterator ] ) {
209
218
for await ( const chunk of content ) {
210
219
await file . write ( chunk ) ;
@@ -223,7 +232,7 @@ export async function ipfsGenerateCar(
223
232
uiContent : Uint8Array ,
224
233
htmlContent : string ,
225
234
replayOpts : ReplayOpts ,
226
- markers : Markers ,
235
+ markers : Markers | null ,
227
236
favicon : Uint8Array | null ,
228
237
// eslint-disable-next-line @typescript-eslint/no-explicit-any
229
238
) : Promise < any > {
@@ -268,7 +277,7 @@ export async function ipfsGenerateCar(
268
277
269
278
const { cid } = await rootDir . close ( ) ;
270
279
271
- writer . close ( ) ;
280
+ await writer . close ( ) ;
272
281
273
282
return cid ;
274
283
}
@@ -338,6 +347,7 @@ async function splitByWarcRecordGroup(
338
347
links = [ ] ;
339
348
}
340
349
350
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
341
351
fileLinks . push ( link ) ;
342
352
343
353
const [ dirName , filename ] = getDirAndName ( currName ) ;
@@ -354,6 +364,7 @@ async function splitByWarcRecordGroup(
354
364
dir = dirs [ dirName ] ;
355
365
}
356
366
367
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
357
368
dir . set ( filename , link ) ;
358
369
359
370
inZipFile = false ;
@@ -368,6 +379,7 @@ async function splitByWarcRecordGroup(
368
379
file = UnixFS . createFileWriter ( writer ) ;
369
380
370
381
if ( chunk === WARC_GROUP ) {
382
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
371
383
secondaryLinks . push ( await concat ( writer , links ) ) ;
372
384
links = [ ] ;
373
385
}
@@ -376,7 +388,7 @@ async function splitByWarcRecordGroup(
376
388
if ( ! inZipFile ) {
377
389
lastChunk = chunk ;
378
390
}
379
- file . write ( chunk ) ;
391
+ await file . write ( chunk ) ;
380
392
count ++ ;
381
393
}
382
394
}
@@ -404,6 +416,7 @@ async function splitByWarcRecordGroup(
404
416
405
417
rootDir . set ( "webarchive" , await waczDir . close ( ) ) ;
406
418
419
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
407
420
rootDir . set ( waczPath , await concat ( writer , fileLinks ) ) ;
408
421
}
409
422
@@ -416,6 +429,7 @@ async function concat(
416
429
const { fileEncoder, hasher, linker } = writer . settings ;
417
430
// eslint-disable-next-line @typescript-eslint/no-explicit-any
418
431
const advanced = ( fileEncoder as any ) . createAdvancedFile ( links ) ;
432
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
419
433
const bytes = fileEncoder . encode ( advanced ) ;
420
434
const hash = await hasher . digest ( bytes ) ;
421
435
const cid = linker . createLink ( fileEncoder . code , hash ) ;
@@ -435,6 +449,7 @@ async function concat(
435
449
436
450
export const iterate = async function * ( stream : ReadableStream < Uint8Array > ) {
437
451
const reader = stream . getReader ( ) ;
452
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
438
453
while ( true ) {
439
454
const next = await reader . read ( ) ;
440
455
if ( next . done ) {
@@ -447,6 +462,7 @@ export const iterate = async function* (stream: ReadableStream<Uint8Array>) {
447
462
448
463
// eslint-disable-next-line @typescript-eslint/no-explicit-any
449
464
export async function encodeBlocks ( blocks : UnixFS . Block [ ] , root ?: any ) {
465
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
450
466
const { writer, out } = CarWriter . create ( root ) ;
451
467
/** @type {Error? } */
452
468
let error ;
@@ -464,6 +480,7 @@ export async function encodeBlocks(blocks: UnixFS.Block[], root?: any) {
464
480
} ) ( ) ;
465
481
const chunks = [ ] ;
466
482
for await ( const chunk of out ) chunks . push ( chunk ) ;
483
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
467
484
if ( error != null ) throw error ;
468
485
const roots = root != null ? [ root ] : [ ] ;
469
486
console . log ( "chunks" , chunks . length ) ;
@@ -537,6 +554,7 @@ export class ShardingStream extends TransformStream {
537
554
shard = [ ] ;
538
555
currSize = 0 ;
539
556
}
557
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
540
558
shard . push ( block ) ;
541
559
currSize += block . bytes . length ;
542
560
} ,
0 commit comments