@@ -7,7 +7,7 @@ import fasHelp from "@fortawesome/fontawesome-free/svgs/solid/question-circle.sv
77import fasPlus from "@fortawesome/fontawesome-free/svgs/solid/plus.svg" ;
88
99import fasUpload from "@fortawesome/fontawesome-free/svgs/solid/upload.svg" ;
10- // import fasCog from "@fortawesome/fontawesome-free/svgs/solid/cog.svg";
10+ import fasCog from "@fortawesome/fontawesome-free/svgs/solid/cog.svg" ;
1111
1212import "./coll" ;
1313import "./coll-info" ;
@@ -25,6 +25,8 @@ import { getLocalOption, setLocalOption } from "../localstorage";
2525// eslint-disable-next-line no-undef
2626const VERSION = __AWP_VERSION__ ;
2727
28+ const DEFAULT_GATEWAY_URL = "https://w3s.link/ipfs/" ;
29+
2830
2931//============================================================================
3032class ArchiveWebApp extends ReplayWebApp
@@ -36,6 +38,15 @@ class ArchiveWebApp extends ReplayWebApp
3638 this . showCollDrop = false ;
3739 this . colls = [ ] ;
3840 this . autorun = false ;
41+
42+ try {
43+ const res = localStorage . getItem ( "ipfsOpts" ) ;
44+ this . ipfsOpts = JSON . parse ( res ) ;
45+ } catch ( e ) {
46+ }
47+
48+ this . ipfsOpts = this . ipfsOpts || { daemonUrl : "" , message : "" , useCustom : false , gatewayUrl : DEFAULT_GATEWAY_URL } ;
49+
3950 getLocalOption ( "autorunBehaviors" ) . then ( ( res ) => this . autorun = res === "1" ) ;
4051
4152 if ( window . archivewebpage ) {
@@ -68,7 +79,9 @@ class ArchiveWebApp extends ReplayWebApp
6879 showDownloadProgress : { type : Boolean } ,
6980 download : { type : Object } ,
7081
71- ipfsDaemonUrl : { type : String }
82+ ipfsOpts : { type : Object } ,
83+
84+ showSettings : { type : Boolean }
7285 } ;
7386 }
7487
@@ -85,7 +98,9 @@ class ArchiveWebApp extends ReplayWebApp
8598 this . sourceUrl = pageParams . get ( "source" ) || "" ;
8699 }
87100
88- this . checkIPFS ( ) ;
101+ if ( ! this . embed ) {
102+ this . checkIPFS ( ) ;
103+ }
89104 }
90105
91106 handleMessages ( ) {
@@ -217,8 +232,13 @@ class ArchiveWebApp extends ReplayWebApp
217232 }
218233
219234 .infomsg {
220- margin-left: auto;
221235 max-width: 300px;
236+ padding-right: 8px;
237+ }
238+
239+ .rightbar {
240+ margin-left: auto;
241+ display: flex;
222242 }
223243
224244 .dl-progress {
@@ -287,7 +307,12 @@ class ArchiveWebApp extends ReplayWebApp
287307 </ span >
288308 < span class ="is-hidden-mobile "> Start Recording...</ span >
289309 </ button >
290- < div class ="infomsg is-hidden-mobile "> The ArchiveWeb.page ${ IS_APP ? "App" : "Extension" } allows you to create web archives directly in your browser!</ div >
310+ < div class ="rightbar ">
311+ < div class ="infomsg is-hidden-mobile "> The ArchiveWeb.page ${ IS_APP ? "App" : "Extension" } allows you to create web archives directly in your browser!</ div >
312+ < button class ="button is-small " @click ="${ ( ) => this . showSettings = true } ">
313+ < fa-icon .svg =${ fasCog } > </ fa-icon >
314+ </ button >
315+ </ div >
291316 </ div >
292317 </ div >
293318 </ div >
@@ -296,8 +321,7 @@ class ArchiveWebApp extends ReplayWebApp
296321 < wr-rec-coll-index
297322 dateName ="Date Created "
298323 headerName ="Current Web Archives "
299- .ipfsDaemonUrl =${ this . ipfsDaemonUrl }
300- .ipfsMessage =${ this . ipfsMessage }
324+ .ipfsOpts =${ this . ipfsOpts }
301325 @show-start =${ this . onShowStart }
302326 @show-import=${ this . onShowImport }
303327 @colls-updated=${ this . onCollsLoaded }
@@ -313,6 +337,7 @@ class ArchiveWebApp extends ReplayWebApp
313337 ${ this . showNew ? this . renderNewCollModal ( ) : "" }
314338 ${ this . showImport ? this . renderImportModal ( ) : "" }
315339 ${ this . showDownloadProgress && this . download ? this . renderDownloadModal ( ) : "" }
340+ ${ this . showSettings ? this . renderSettingsModal ( ) : "" }
316341 ${ super . render ( ) } ` ;
317342 }
318343
@@ -325,8 +350,7 @@ class ArchiveWebApp extends ReplayWebApp
325350 .loadInfo ="${ this . getLoadInfo ( this . sourceUrl ) } "
326351 .appLogo ="${ this . mainLogo } "
327352 .autoUpdateInterval =${ this . embed || this . showDownloadProgress ? 0 : 10 }
328- .ipfsDaemonUrl =${ this . ipfsDaemonUrl }
329- .ipfsMessage=${ this . ipfsMessage }
353+ .ipfsOpts =${ this . ipfsOpts }
330354 embed="${ this . embed } "
331355 sourceUrl="${ this . sourceUrl } "
332356 appName="${ this . appName } "
@@ -562,6 +586,35 @@ class ArchiveWebApp extends ReplayWebApp
562586 </ div > ` ;
563587 }
564588
589+ renderSettingsModal ( ) {
590+ return html `
591+ < wr-modal @modal-closed ="${ ( ) => this . showSettings = false } " title ="Settings ">
592+ < form class ="is-flex is-flex-direction-column " @submit ="${ this . onSaveSettings } ">
593+ < div class ="field has-addons ">
594+ < p class ="control is-expanded ">
595+ IPFS Daemon URL (leave blank to auto-detect IPFS):
596+ < input class ="input " type ="url "
597+ name ="ipfsDaemonUrl " id ="ipfsDaemonUrl " value ="${ this . ipfsOpts . daemonUrl } "
598+ placeholder ="Set IPFS Daemon URL or set blank to auto-detect IPFS ">
599+ </ p >
600+ </ div >
601+ < div class ="field has-addons ">
602+ < p class ="control is-expanded ">
603+ IPFS Gateway URL:
604+ < input class ="input " type ="url "
605+ name ="ipfsGatewayUrl " id ="ipfsGatewayUrl " value ="${ this . ipfsOpts . gatewayUrl } "
606+ placeholder ="${ DEFAULT_GATEWAY_URL } ">
607+ </ p >
608+ </ div >
609+ < div class ="has-text-centered ">
610+ < button class ="button is-primary " type ="submit "> Save</ button >
611+ < button class ="button " type ="button " @click ="${ ( ) => this . showSettings = false } "> Close</ button >
612+ </ div >
613+ </ form >
614+ </ wr-modal >
615+ ` ;
616+ }
617+
565618 async onNewColl ( event ) {
566619 this . showNew = "loading" ;
567620 event . preventDefault ( ) ;
@@ -675,43 +728,72 @@ class ArchiveWebApp extends ReplayWebApp
675728 }
676729 }
677730
731+ async onSaveSettings ( event ) {
732+ event . preventDefault ( ) ;
733+ this . showSettings = false ;
734+
735+ const daemonUrlText = this . renderRoot . querySelector ( "#ipfsDaemonUrl" ) ;
736+ const gatewayUrlText = this . renderRoot . querySelector ( "#ipfsGatewayUrl" ) ;
737+
738+ if ( ! daemonUrlText || ! gatewayUrlText ) {
739+ return ;
740+ }
741+
742+ const daemonUrl = daemonUrlText . value ;
743+ const gatewayUrl = gatewayUrlText . value ;
744+
745+ //const method = "POST";
746+
747+ //const body = JSON.stringify({daemonUrl});
748+
749+ //const resp = await fetch(`${apiPrefix}/ipfs/daemonUrl`, {method, body});
750+
751+ this . ipfsOpts = {
752+ daemonUrl, useCustom : ! ! daemonUrl , gatewayUrl
753+ } ;
754+
755+ await this . checkIPFS ( ) ;
756+
757+ localStorage . setItem ( "ipfsOpts" , JSON . stringify ( this . ipfsOpts ) ) ;
758+
759+ return false ;
760+ }
761+
678762 async checkIPFS ( ) {
763+ const ipfsOpts = this . ipfsOpts ;
764+
679765 // use auto-js-ipfs to get possible local daemon url (eg. for Brave)
680766 // if so, send it to the service worker
767+ if ( ipfsOpts . useCustom && ipfsOpts . daemonUrl ) {
768+ ipfsOpts . message = "IPFS Access -- Custom IPFS Daemon" ;
769+ return ;
770+ }
681771
682- let ipfsDaemonUrl = sessionStorage . getItem ( "ipfsDaemonUrl" ) ;
683- let ipfsMessage = sessionStorage . getItem ( "ipfsMessage" ) ;
684-
685- if ( ipfsDaemonUrl === null ) {
772+ if ( ! ipfsOpts . daemonUrl ) {
686773 // eslint-disable-next-line no-undef
687774 const autoipfs = await createAutoIpfs ( { web3StorageToken : __WEB3_STORAGE_TOKEN__ } ) ;
688775
689776 if ( autoipfs instanceof DaemonAPI ) {
690- ipfsDaemonUrl = autoipfs . url ;
777+ ipfsOpts . daemonUrl = autoipfs . url ;
691778 }
692779
780+ ipfsOpts . useCustom = false ;
781+
693782 if ( autoipfs instanceof Web3StorageAPI ) {
694- ipfsMessage = "Sharing via remote web3.storage" ;
695- } else if ( ! ipfsDaemonUrl ) {
696- ipfsMessage = "IPFS Access Unknown - Sharing Not Available" ;
697- } else if ( ipfsDaemonUrl . startsWith ( "http://localhost:45" ) ) {
698- ipfsMessage = "Sharing via Brave IPFS node" ;
699- } else if ( ipfsDaemonUrl . startsWith ( "http://localhost" ) ) {
700- ipfsMessage = "Sharing via local IPFS node" ;
783+ ipfsOpts . message = "Sharing via remote web3.storage" ;
784+ } else if ( ! ipfsOpts . daemonUrl ) {
785+ ipfsOpts . message = "IPFS Access Unknown - Sharing Not Available" ;
786+ } else if ( ipfsOpts . daemonUrl . startsWith ( "http://localhost:45" ) ) {
787+ ipfsOpts . message = "Sharing via Brave IPFS node" ;
788+ } else if ( ipfsOpts . daemonUrl . startsWith ( "http://localhost" ) ) {
789+ ipfsOpts . message = "Sharing via local IPFS node" ;
701790 } else {
702- ipfsMessage = "" ;
791+ ipfsOpts . message = "" ;
703792 }
704-
705- sessionStorage . setItem ( "ipfsDaemonUrl" , ipfsDaemonUrl ) ;
706- sessionStorage . setItem ( "ipfsMessage" , ipfsMessage ) ;
707793 }
708-
709- this . ipfsDaemonUrl = ipfsDaemonUrl ;
710- this . ipfsMessage = ipfsMessage ;
711794 }
712795}
713796
714-
715797customElements . define ( "archive-web-page-app" , ArchiveWebApp ) ;
716798
717799export { ArchiveWebApp , Loader , Embed } ;
0 commit comments