Client for interacting with the perma-cache layer of the NFT.Storage IPFS Edge Gateway.
The perma-cache
eases the interaction with nftstorage.link HTTP API and improves developer experience. Particularly when you:
- rely on typescript during development.
- want to perma-cache multiple URLs as a batch, like an NFT drop.
- want to have the client taking care of rate limiting prevention.
You can import and use this client like:
import { PermaCache } from 'nftstorage.link'
const cache = new PermaCache({ token: 'YOUR_NFT_STORAGE_TOKEN' })
const urls = [
'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link'
]
// Perma-cache given URLs
const permaCacheEntries = await cache.put(urls)
// Delete perma-cache URLs
await cache.delete(urls)
Put URL(s) into the nftstorage.link perma-cache.
put(urls: string[]): Promise<CacheResult[]>
Example:
import { PermaCache } from 'nftstorage.link'
const cache = new PermaCache({ token: 'YOUR_NFT_STORAGE_TOKEN' })
const permaCacheEntries = await cache.put([
'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link',
'https://bafybeih74zqc6kamjpruyra4e4pblnwdpickrvk4hvturisbtveghflovq.ipfs.nftstorage.link/path',
'https://nftstorage.link/ipfs/bafkreiem4twkqzsq2aj4shbycd4yvoj2cx72vezicletlhi7dijjciqpui'
])
console.log(permaCacheEntries)
// [
// {
// url: 'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link',
// size: 1000,
// insertedAt: "2022-05-30T11:37:27.878372".
// },
// {
// url: 'https://bafybeih74zqc6kamjpruyra4e4pblnwdpickrvk4hvturisbtveghflovq.ipfs.nftstorage.link/path',
// size: 2000,
// insertedAt: "2022-05-30T11:37:29.878372"
// },
// {
// url: 'https://nftstorage.link/ipfs/bafkreiem4twkqzsq2aj4shbycd4yvoj2cx72vezicletlhi7dijjciqpui',
// size: 3200,
// insertedAt: "2022-05-30T11:37:30.878372"
// }
// ]
Delete URL(s) from the nftstorage.link perma-cache.
delete(urls: string[]): Promise<CacheDeleteResult[]>
Example:
import { PermaCache } from 'nftstorage.link'
const cache = new PermaCache({ token: 'YOUR_NFT_STORAGE_TOKEN' })
const permaCacheDeletedEntries = await cache.delete([
'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link',
'https://bafybeih74zqc6kamjpruyra4e4pblnwdpickrvk4hvturisbtveghflovq.ipfs.nftstorage.link/path'
])
console.log(permaCacheDeletedEntries)
// [
// {
// url: 'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link',
// },
// {
// url: 'https://bafybeih74zqc6kamjpruyra4e4pblnwdpickrvk4hvturisbtveghflovq.ipfs.nftstorage.link/path',
// }
// ]
List account nftstorage.link perma-cache URLs
list(options: ListOptions): AsyncIterable<CacheEntry>
import { PermaCache } from 'nftstorage.link'
const cache = new PermaCache({ token: 'YOUR_NFT_STORAGE_TOKEN' })
const permaCacheEntries = []
for await (const entry of cache.list()) {
permaCacheEntries.push(entry)
}
console.log(permaCacheEntries)
// [
// {
// url: 'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link',
// size: 1000,
// insertedAt: "2022-05-30T11:37:27.878372"
// },
// {
// url: 'https://bafybeih74zqc6kamjpruyra4e4pblnwdpickrvk4hvturisbtveghflovq.ipfs.nftstorage.link/path',
// size: 2000,
// insertedAt: "2022-05-30T11:37:29.878372"
// }
// ]
Get perma-cache account info
accountInfo(): Promise<AccountInfo>
import { PermaCache } from 'nftstorage.link'
const cache = new PermaCache({ token: 'YOUR_NFT_STORAGE_TOKEN' })
const accountInfo = await cache.accountInfo()
console.log(accountInfo)
// {
// usedStorage: 3000
// }