@@ -62,6 +62,7 @@ const stop = () => {
62
62
63
63
const connectPeer = ( e ) => {
64
64
e . target . disabled = true
65
+ // Connect directly to a peer via it's multiaddr
65
66
ipfs . swarm . connect ( $connectPeer . value , ( err ) => {
66
67
console . log ( err )
67
68
if ( err ) return onError ( err )
@@ -77,13 +78,16 @@ const catFile = () => {
77
78
$multihashInput . value = ''
78
79
$errors . className = 'hidden'
79
80
if ( multihash ) {
81
+ // Get a file or many files
80
82
ipfs . files . get ( multihash , ( err , stream ) => {
81
83
if ( err ) onError ( err )
82
84
console . log ( stream )
85
+ // .get gives us a stream of files
83
86
stream . on ( 'data' , ( file ) => {
84
87
console . log ( file )
85
88
const buf = [ ]
86
89
if ( file . content ) {
90
+ // once we get a file, we also want to read the data for that file
87
91
file . content . on ( 'data' , ( data ) => {
88
92
console . log ( 'file got data' )
89
93
buf . push ( data )
@@ -100,6 +104,7 @@ const catFile = () => {
100
104
link . setAttribute ( 'href' , downloadLink )
101
105
link . setAttribute ( 'download' , multihash )
102
106
const date = ( new Date ( ) ) . toLocaleTimeString ( )
107
+
103
108
link . innerText = date + ' - ' + multihash + ' - Size: ' + file . size
104
109
const fileList = document . querySelector ( '.file-list' )
105
110
@@ -180,6 +185,8 @@ const onDrop = (event) => {
180
185
// Get peers from IPFS and display them
181
186
let numberOfPeersLastTime = 0
182
187
const updatePeers = ( ) => {
188
+ // Once in a while, we need to refresh our list of peers in the UI
189
+ // .swarm.peers returns an array with all our currently connected peer
183
190
ipfs . swarm . peers ( ( err , res ) => {
184
191
if ( err ) onError ( err )
185
192
if ( numberOfPeersLastTime !== res . length ) {
@@ -206,10 +213,6 @@ function setupEventListeners () {
206
213
$stopButton . addEventListener ( 'click' , stop )
207
214
$catButton . addEventListener ( 'click' , catFile )
208
215
$connectPeerButton . addEventListener ( 'click' , connectPeer )
209
-
210
- // TODO temporary default values, remove before merging
211
- $connectPeer . value = '/ip4/0.0.0.0/tcp/9999/ws/ipfs/QmSGmyZtL3BPLxkF9yyaitLsotvratuqeWq1UR8V9BDXcV'
212
- $multihashInput . value = 'QmXxyxhxbt9TU4pJFdpAnqAsTraCMvCNsWsyfe2ZZUjJUn'
213
216
}
214
217
215
218
const states = {
0 commit comments