@@ -33,6 +33,13 @@ import { CollectionLoader } from "@webrecorder/wabac/swlib";
3333
3434document . adoptedStyleSheets . push ( typescaleStyles . styleSheet ! ) ;
3535
36+ const WS_TRACKERS = [
37+ "wss://tracker.openwebtorrent.com" ,
38+ "wss://tracker.btorrent.xyz" ,
39+ "wss://tracker.fastcast.nz" ,
40+ "wss://tracker.clear.netty.link" ,
41+ ] ;
42+
3643const collLoader = new CollectionLoader ( ) ;
3744class ArgoViewer extends LitElement {
3845 static styles : CSSResultGroup = [
@@ -378,6 +385,40 @@ class ArgoViewer extends LitElement {
378385 await this . onShare ( [ currentPage ] ) ;
379386 }
380387
388+ private async reseedAll ( ) {
389+ const shared : SharedArchive [ ] = await getSharedArchives ( ) ;
390+ if ( ! shared . length ) return ;
391+
392+ const opfsRoot = await navigator . storage . getDirectory ( ) ;
393+ console . log ( `♻️ reseedAll: found ${ shared . length } archives` ) ;
394+
395+ for ( const record of shared ) {
396+ try {
397+ // Skip if already seeding
398+ if ( client . get ( record . magnetURI ) ) continue ;
399+
400+ // Get file handle and file from OPFS
401+ const handle = await opfsRoot . getFileHandle ( record . filename , {
402+ create : false ,
403+ } ) ;
404+ const file = await handle . getFile ( ) ;
405+
406+ client . seed (
407+ file ,
408+ WS_TRACKERS . length
409+ ? { announce : WS_TRACKERS , name : record . filename }
410+ : undefined ,
411+ ( torrent ) => {
412+ console . log ( `♻️ Re-seeding ${ record . filename } :` , torrent . infoHash ) ;
413+ console . log ( "Magnet:" , torrent . magnetURI ) ;
414+ } ,
415+ ) ;
416+ } catch ( err ) {
417+ console . warn ( `⚠️ Could not reseed ${ record . filename } :` , err ) ;
418+ }
419+ }
420+ }
421+
381422 // @ts -expect-error - TS7006 - Parameter 'pages' implicitly has an 'any' type.
382423 private async onShare ( pages ) {
383424 const defaultCollId = ( await getLocalOption ( "defaultCollId" ) ) || "" ;
@@ -446,6 +487,7 @@ class ArgoViewer extends LitElement {
446487 id : Date . now ( ) . toString ( ) ,
447488 pages,
448489 magnetURI,
490+ filename,
449491 seededAt : Date . now ( ) ,
450492 } ;
451493 const updated = [ record , ...existing ] ;
@@ -464,7 +506,7 @@ class ArgoViewer extends LitElement {
464506 } ) ;
465507 }
466508
467- firstUpdated ( ) {
509+ async firstUpdated ( ) {
468510 this . archiveList = this . shadowRoot ! . getElementById (
469511 "archive-list" ,
470512 ) as ArgoArchiveList ;
@@ -478,6 +520,10 @@ class ArgoViewer extends LitElement {
478520 // @ts -expect-error
479521 console . log ( "Shared archives:" , this . sharedArchives ) ;
480522 } ) ;
523+
524+ await this . reseedAll ( ) ;
525+
526+ console . log ( "Currently seeding (firstUpdated) torrents:" , client . torrents ) ;
481527 }
482528
483529 updateTabInfo ( ) {
0 commit comments