Skip to content

Instantly share code, notes, and snippets.

@gregorym
Created July 15, 2022 19:43
Show Gist options
  • Save gregorym/81f93ac73fd0f8a202a10b3e961628cf to your computer and use it in GitHub Desktop.
Save gregorym/81f93ac73fd0f8a202a10b3e961628cf to your computer and use it in GitHub Desktop.
import fetch from 'node-fetch';
const pinata_api_key = '';
const pinata_secret_api_key = '';
(async () => {
const data = await fetch(
'https://api.pinata.cloud/data/pinList?status=pinned&pageLimit=1000',
{
method: 'GET',
headers: { pinata_api_key, pinata_secret_api_key },
}
).then((res) => res.json());
console.log('Total pinned files:', data.count);
for (let i = data.count - 1; i > 0; i--) {
const hash = data.rows[i].ipfs_pin_hash;
const size = +data.rows[i].size / 1000000;
console.log(`Pinning ${hash} with size ${size.toFixed(2)} MB`);
try {
const response = await fetch(
`https://ipfs.infura.io:5001/api/v0/pin/add?recursive=true&arg=${hash}`,
{
method: 'POST',
headers: {
Authorization: 'Basic KEY',
},
}
).catch(console.error);
if (response.status === 200) {
await fetch(`https://api.pinata.cloud/pinning/unpin/${hash}`, {
method: 'DELETE',
headers: { pinata_api_key, pinata_secret_api_key, },
});
}
} catch (error) {
console.error(error);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment