Compare commits
9 Commits
c21512fa0b
...
v2.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45c0aed4a5
|
||
|
|
f25fcaa1b2
|
||
|
|
7c8f0814b9
|
||
|
|
b566a432a9
|
||
| b7a7214f08 | |||
| 6829a13a57 | |||
|
|
328905814d
|
||
|
|
03ee17f00e
|
||
|
|
9dffb15f45
|
@@ -1,3 +1,5 @@
|
||||
[](https://www.npmjs.com/package/@kredits/ipfs-pinner)
|
||||
|
||||
# Kredits IPFS Pinner
|
||||
|
||||
This tool pins the IPFS documents of a Kredits organization on any IPFS node.
|
||||
|
||||
77
index.js
77
index.js
@@ -39,44 +39,45 @@ const ipfsConfig = {
|
||||
debug(`IPFS node:`, ipfsConfig);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const kredits = await Kredits.for(
|
||||
{ rpcUrl: argv.rpcUrl },
|
||||
{ ipfsConfig: ipfsConfig }
|
||||
).init();
|
||||
|
||||
// Check the connection to the IPFS client
|
||||
// TODO redesign IPFS wrapper API and do not use an internal attribute
|
||||
const ipfsApi = kredits.ipfs._ipfsAPI;
|
||||
|
||||
await ipfsApi.id();
|
||||
|
||||
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||
|
||||
const ipfsPinner = new IpfsPinner(kredits, {
|
||||
progress: argv.progress
|
||||
});
|
||||
|
||||
await ipfsPinner.pinAll().then(cids => {
|
||||
console.log(`\nSuccessfully pinned ${cids.length} documents`)
|
||||
});
|
||||
|
||||
if (argv.watch) {
|
||||
console.log('\nWatching contract events for new documents...');
|
||||
|
||||
ipfsPinner.watch(pin => {
|
||||
console.log('Pinned a new document:', pin[0]["hash"]);
|
||||
});
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// TODO Add new deployment/DAO/org ID or all contract proxy addresses
|
||||
// console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
|
||||
} catch(e) {
|
||||
console.log('Failed to start');
|
||||
console.log(e);
|
||||
const kredits = await Kredits.for(
|
||||
{ rpcUrl: argv.rpcUrl },
|
||||
{ ipfsConfig: ipfsConfig }
|
||||
).init().catch(e => {
|
||||
console.log('Failed to initialize Kredits:');
|
||||
console.log(e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// TODO redesign IPFS wrapper API and do not use an internal attribute
|
||||
const ipfsApi = kredits.ipfs._ipfsAPI;
|
||||
|
||||
await ipfsApi.id().catch(e => {
|
||||
console.log('Failed to initialize IPFS:');
|
||||
console.log(e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||
|
||||
const ipfsPinner = new IpfsPinner(kredits, {
|
||||
progress: argv.progress
|
||||
});
|
||||
|
||||
await ipfsPinner.pinAll().then(cids => {
|
||||
console.log(`\nSuccessfully pinned ${cids.length} documents`)
|
||||
});
|
||||
|
||||
if (argv.watch) {
|
||||
console.log('\nWatching contract events for new documents...');
|
||||
|
||||
ipfsPinner.watch(pin => {
|
||||
console.log('Pinned a new document:', pin[0]["hash"]);
|
||||
});
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// TODO Add new deployment/DAO/org ID or all contract proxy addresses
|
||||
// console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
|
||||
})();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
const debug = require('debug')('ipfs-pinner');
|
||||
const cliProgress = require('cli-progress');
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
class IpfsPinner {
|
||||
constructor (kredits, options={}) {
|
||||
this.kredits = kredits;
|
||||
@@ -46,6 +50,9 @@ class IpfsPinner {
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
// Avoid console output race condition with progress bars finishing update
|
||||
if (this.progressBars) await sleep(1000);
|
||||
|
||||
return cids;
|
||||
}
|
||||
|
||||
|
||||
21
package-lock.json
generated
21
package-lock.json
generated
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "@kosmos/kredits-ipfs-pinner",
|
||||
"version": "1.2.0",
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@kosmos/kredits-ipfs-pinner",
|
||||
"version": "1.2.0",
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kredits/contracts": "git+https://gitea.kosmos.org/kredits/contracts#6e0ec87",
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"cli-progress": "^3.11.2",
|
||||
"debug": "^4.3.4",
|
||||
"yargs": "^17.6.0"
|
||||
@@ -721,9 +721,9 @@
|
||||
"integrity": "sha512-yOTK5WiXFDNAitPByMabE365aEEzFHgSUSgAssbJWt7BZ80HQSVu8XWrQiTbFbCkoIBmXwPP/RoxgXJQVgZTFQ=="
|
||||
},
|
||||
"node_modules/@kredits/contracts": {
|
||||
"version": "7.0.0-beta.0",
|
||||
"resolved": "git+https://gitea.kosmos.org/kredits/contracts#6e0ec8741e61b51fb5c9c636da4e8d3610d090ac",
|
||||
"license": "MIT",
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.0.0.tgz",
|
||||
"integrity": "sha512-UITEkP3njFNI2WS7v5ivGE3ruFwdWPWuJZrhBXBEAZbtmr1t/p1K7jkmmjyLDUeKXJ/udMlH6oQMCgh7P/aHNg==",
|
||||
"dependencies": {
|
||||
"@kosmos/schemas": "^3.1.0",
|
||||
"ethers": "^5.4.7",
|
||||
@@ -2245,8 +2245,9 @@
|
||||
"integrity": "sha512-yOTK5WiXFDNAitPByMabE365aEEzFHgSUSgAssbJWt7BZ80HQSVu8XWrQiTbFbCkoIBmXwPP/RoxgXJQVgZTFQ=="
|
||||
},
|
||||
"@kredits/contracts": {
|
||||
"version": "git+https://gitea.kosmos.org/kredits/contracts#6e0ec8741e61b51fb5c9c636da4e8d3610d090ac",
|
||||
"from": "@kredits/contracts@git+https://gitea.kosmos.org/kredits/contracts#6e0ec87",
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.0.0.tgz",
|
||||
"integrity": "sha512-UITEkP3njFNI2WS7v5ivGE3ruFwdWPWuJZrhBXBEAZbtmr1t/p1K7jkmmjyLDUeKXJ/udMlH6oQMCgh7P/aHNg==",
|
||||
"requires": {
|
||||
"@kosmos/schemas": "^3.1.0",
|
||||
"ethers": "^5.4.7",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kosmos/kredits-ipfs-pinner",
|
||||
"version": "1.2.0",
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.1",
|
||||
"description": "Pins IPFS data of a Kredits organization on an IPFS node",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -20,7 +20,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kredits/contracts": "git+https://gitea.kosmos.org/kredits/contracts#6e0ec87",
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"cli-progress": "^3.11.2",
|
||||
"debug": "^4.3.4",
|
||||
"yargs": "^17.6.0"
|
||||
|
||||
Reference in New Issue
Block a user