nftstorage.link
Version:
Utilities for working with the NFT.Storage IPFS Edge Gateway
74 lines • 2.55 kB
TypeScript
/**
* Get a gateway URL, given a CID, CID+path, IPFS path or an IPFS gateway URL.
* If the status of the nftstorage.link gateway is known to be good (according
* to the status checker) then return a URL that uses nftstorage.link, otherwise
* return an URL that uses dweb.link (or the optional passed fallback gateway
* URL).
*
* @param {string|URL} cidPath
* @param {Object} [options]
* @param {IGatewayStatusChecker} [options.statusChecker]
* @param {string|URL} [options.fallbackGatewayURL]
*/
export function getGatewayURL(cidPath: string | URL, options?: {
statusChecker?: IGatewayStatusChecker | undefined;
fallbackGatewayURL?: string | URL | undefined;
} | undefined): Promise<URL>;
/**
* @typedef {Object} IGatewayStatusChecker Checks the status of an IPFS gateway.
* @property {URL} gatewayURL Base URL of the IPFS gateway status is being checked for.
* @property {() => Promise<boolean>} ok Determines if the status of the gateway is OK or not.
*/
/**
* Check the status of a gateway and cache the result for a period of time.
* @implements {IGatewayStatusChecker}
*/
export class GatewayStatusChecker implements IGatewayStatusChecker {
/**
* @param {Object} [config]
* @param {string|URL} [config.apiURL] Gateway status API URL.
* @param {string|URL} [config.gatewayURL] Base URL of the IPFS gateway status is being checked for.
* @param {number} [config.maxAge] Time in ms after which a status value is stale.
* @param {globalThis.fetch} [config.fetch] Custom fetch API implementation.
*/
constructor(config?: {
apiURL?: string | URL | undefined;
gatewayURL?: string | URL | undefined;
maxAge?: number | undefined;
fetch?: typeof fetch | undefined;
} | undefined);
/** @private */
private _apiURL;
/** @private */
private _gatewayURL;
/** @private */
private _maxAge;
/** @private */
private _fetch;
/** @private */
private _lastCheck;
/**
* @type {Promise<boolean>|null}
* @private
*/
private _request;
get gatewayURL(): URL;
/**
* Determine if the status of the gateway is OK or not.
*/
ok(): Promise<boolean>;
}
/**
* Checks the status of an IPFS gateway.
*/
export type IGatewayStatusChecker = {
/**
* Base URL of the IPFS gateway status is being checked for.
*/
gatewayURL: URL;
/**
* Determines if the status of the gateway is OK or not.
*/
ok: () => Promise<boolean>;
};
//# sourceMappingURL=gateway.d.ts.map