@@ -796,21 +796,26 @@ export default class Compiler {
796796 }
797797
798798 async _uploadToIPFS ( file : { path : string ; content : Buffer } ) {
799- try {
800- const files = this . ipfs . addAll ( [ file ] ) ;
801-
802- // We get back async iterable
803- const filesIterator = files [ Symbol . asyncIterator ] ( ) ;
804- // We only care about the first item, since that is the file, rest could be directories
805- const { value } = await filesIterator . next ( ) ;
806-
807- // we grab the file and pin it
808- const uploadedFile = value as Awaited < ReturnType < typeof this . ipfs . add > > ;
809- await this . ipfs . pin . add ( uploadedFile . cid ) ;
810-
811- return uploadedFile . cid . toString ( ) ;
812- } catch ( e ) {
813- throw Error ( `Failed to upload file to IPFS: ${ e . message } ` ) ;
799+ while ( 1 ) {
800+ try {
801+ const files = this . ipfs . addAll ( [ file ] ) ;
802+
803+ // We get back async iterable
804+ const filesIterator = files [ Symbol . asyncIterator ] ( ) ;
805+ // We only care about the first item, since that is the file, rest could be directories
806+ const { value } = await filesIterator . next ( ) ;
807+
808+ // we grab the file and pin it
809+ const uploadedFile = value as Awaited < ReturnType < typeof this . ipfs . add > > ;
810+
811+ await this . ipfs . pin . add ( uploadedFile . cid ) ;
812+
813+ return uploadedFile . cid . toString ( ) ;
814+ } catch ( e ) {
815+ console . log ( 'Failed to upload file to IPFS: ' , [ ( e as any ) . message ] ) ;
816+ console . log ( 'Retrying in 4 seconds...' ) ;
817+ await new Promise ( resolve => setTimeout ( resolve , 4_000 ) ) ;
818+ }
814819 }
815820 }
816821}
0 commit comments