nftstorage.link
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,2 +0,2 @@ | ||
class t{constructor(t){t=t||{},this._apiURL=t.apiURL||"https://api.nftstoragestatus.com",this._gatewayURL=new URL(t.gatewayURL||"https://nftstorage.link"),this._maxAge=t.maxAge||6e4,this._fetch=t.fetch||globalThis.fetch,this._lastCheck=0,this._request=null}get gatewayURL(){return this._gatewayURL}ok(){const t=Date.now();return(!this._request||t-this._lastCheck>this._maxAge)&&(this._request=(async()=>{this._lastCheck=t;try{const t=await this._fetch(this._apiURL.toString());return"ok"===(await t.json()).status}catch{return!1}})()),this._request}}const s=new t;async function e(t,e){const a=(e=e||{}).statusChecker||s,i=e.fallbackGatewayURL||"https://dweb.link",h=await a.ok();let{protocol:n,hostname:c,pathname:r,search:o,hash:l}=new URL(t,a.gatewayURL);if("ipfs:"===n||"ipns:"===n)r=c?`/${c}${r}`:r.slice(1),r=`/${n.slice(0,-1)}${r}`;else if(!r.startsWith("/ipfs")&&!r.startsWith("/ipns")){const t=c.split(".");r="ipfs"===t[1]||"ipns"===t[1]?`/${t[1]}/${t[0]}${"/"===r?"":r}`:`/ipfs${r}`}const p=h?a.gatewayURL:i;return new URL(`${r}${o}${l}`,p)}export{t as GatewayStatusChecker,e as getGatewayURL}; | ||
class t{constructor(t){t=t||{},this._apiURL=t.apiURL||"https://api.nftstoragestatus.com",this._gatewayURL=new URL(t.gatewayURL||"https://nftstorage.link"),this._maxAge=t.maxAge||6e4,this._fetch=t.fetch,!this._fetch&&globalThis.fetch&&(this._fetch=globalThis.fetch.bind(globalThis)),this._lastCheck=0,this._request=null}get gatewayURL(){return this._gatewayURL}ok(){const t=Date.now();return(!this._request||t-this._lastCheck>this._maxAge)&&(this._request=(async()=>{this._lastCheck=t;try{const t=this._fetch;if(!t)throw new Error("missing fetch implementation");const s=await t(this._apiURL.toString());return"ok"===(await s.json()).status}catch(t){return console.warn("Failed to fetch gateway status:",t),!1}})()),this._request}}const s=new t;async function e(t,e){const a=(e=e||{}).statusChecker||s,i=e.fallbackGatewayURL||"https://dweb.link",h=await a.ok();let{protocol:n,hostname:c,pathname:o,search:r,hash:l}=new URL(t,a.gatewayURL);if("ipfs:"===n||"ipns:"===n)o=c?`/${c}${o}`:o.slice(1),o=`/${n.slice(0,-1)}${o}`;else if(!o.startsWith("/ipfs")&&!o.startsWith("/ipns")){const t=c.split(".");o="ipfs"===t[1]||"ipns"===t[1]?`/${t[1]}/${t[0]}${"/"===o?"":o}`:`/ipfs${o}`}const f=h?a.gatewayURL:i;return new URL(`${o}${r}${l}`,f)}export{t as GatewayStatusChecker,e as getGatewayURL}; | ||
//# sourceMappingURL=bundle.esm.min.js.map |
{ | ||
"name": "nftstorage.link", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Utilities for working with the NFT.Storage IPFS Edge Gateway", | ||
@@ -59,2 +59,3 @@ "type": "module", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@types/assert": "^1.5.6", | ||
"@types/mocha": "^9.0.0", | ||
@@ -61,0 +62,0 @@ "assert": "^2.0.0", |
@@ -33,3 +33,7 @@ const API_URL = 'https://api.nftstoragestatus.com' | ||
/** @private */ | ||
this._fetch = config.fetch || globalThis.fetch | ||
this._fetch = config.fetch | ||
/* c8 ignore next 3 */ | ||
if (!this._fetch && globalThis.fetch) { | ||
this._fetch = globalThis.fetch.bind(globalThis) | ||
} | ||
/** @private */ | ||
@@ -57,6 +61,10 @@ this._lastCheck = 0 | ||
try { | ||
const res = await this._fetch(this._apiURL.toString()) | ||
const fetch = this._fetch | ||
/* c8 ignore next 1 */ | ||
if (!fetch) throw new Error('missing fetch implementation') | ||
const res = await fetch(this._apiURL.toString()) | ||
const data = await res.json() | ||
return data.status === 'ok' | ||
} catch { | ||
} catch (err) { | ||
console.warn('Failed to fetch gateway status:', err) | ||
return false | ||
@@ -63,0 +71,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34223
312
16
4