Compare commits
2 Commits
c21512fa0b
...
03ee17f00e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03ee17f00e
|
||
|
|
9dffb15f45
|
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user