11import axios from 'axios' ;
2+ import https from 'https' ;
23
34const gateways : string [ ] = [
45 'https://ipfs.io/ipfs/{hash}' ,
@@ -11,8 +12,14 @@ const gateways: string[] = [
1112 'https://{hash}.ipfs.cf-ipfs.com' ,
1213 'https://{hash}.ipfs.4everland.io' ,
1314 'https://{hash}.ipfs.gw3.io' ,
15+ 'https://gateway.pinata.cloud/ipfs/{hash}' ,
16+ 'https://ipfs.quicknode.com/ipfs/{hash}' ,
1417] ;
1518
19+ const agent = new https . Agent ( {
20+ rejectUnauthorized : true ,
21+ } ) ;
22+
1623export const getAllGateway = ( ipfsUrl : string ) : string [ ] => {
1724 const finalUrl : string [ ] = [ ] ;
1825 const getHash = ipfsUrl . replace ( 'ipfs://' , '' ) ;
@@ -31,10 +38,10 @@ export const getAllGateway = (ipfsUrl: string): string[] => {
3138 return finalUrl ;
3239} ;
3340
34- export const getLiveGateway = async (
41+ export const getAllLiveGateway = async (
3542 ipfsUrl : string ,
3643 timeout ?: number
37- ) : Promise < string > => {
44+ ) : Promise < string [ ] > => {
3845 const listLoop : unknown [ ] = [ ] ;
3946 const finalUrl : string [ ] = [ ] ;
4047 const getHash = ipfsUrl . replace ( 'ipfs://' , '' ) ;
@@ -48,7 +55,9 @@ export const getLiveGateway = async (
4855 }
4956
5057 finalUrl . push ( url ) ;
51- listLoop . push ( axios . head ( url , { timeout : timeout || 5000 } ) ) ;
58+ listLoop . push (
59+ axios . head ( url , { httpsAgent : agent , timeout : timeout || 3000 } )
60+ ) ;
5261 } ) ;
5362
5463 const result = await Promise . allSettled ( listLoop ) ;
@@ -60,6 +69,17 @@ export const getLiveGateway = async (
6069 }
6170 }
6271
72+ return fullfilled ;
73+ } ;
74+
75+ export const getLiveGateway = async (
76+ ipfsUrl : string ,
77+ timeout ?: number
78+ ) : Promise < string > => {
79+ const finalUrl = getAllGateway ( ipfsUrl ) ;
80+ const rto = timeout || 5000 ;
81+ const fullfilled : string [ ] = await getAllLiveGateway ( ipfsUrl , rto ) ;
82+
6383 if ( fullfilled . length > 0 ) {
6484 return fullfilled [ 0 ] ;
6585 } else {
0 commit comments