Clean up logs, add debug option
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
const debug = require('debug')('ipfs-pinner');
|
||||
|
||||
class IpfsPinner {
|
||||
constructor (kredits, ipfsApi) {
|
||||
this.kredits = kredits;
|
||||
this.ipfsApi = ipfsApi || this.kredits.ipfs;
|
||||
}
|
||||
|
||||
pinAll () {
|
||||
return Promise.all([
|
||||
this._pinAllFromContract(this.kredits.Contributor),
|
||||
this._pinAllFromContract(this.kredits.Contribution),
|
||||
this._pinAllFromContract(this.kredits.Proposal)
|
||||
]);
|
||||
async pinAll () {
|
||||
const contributorHashes = await this._pinAllFromContract(this.kredits.Contributor);
|
||||
const contributionHashes = await this._pinAllFromContract(this.kredits.Contribution);
|
||||
const proposalHashes = await this._pinAllFromContract(this.kredits.Proposal);
|
||||
|
||||
return contributorHashes.concat(contributionHashes)
|
||||
.concat(proposalHashes);
|
||||
}
|
||||
|
||||
monitor (callback) {
|
||||
@@ -31,13 +34,13 @@ class IpfsPinner {
|
||||
}
|
||||
|
||||
_pinAllFromContract (contract) {
|
||||
console.log(`Pinning data from ${contract.constructor.name}...`);
|
||||
debug(`Pinning data from ${contract.constructor.name}...`);
|
||||
return contract.count.then(count => {
|
||||
let promises = [...Array(count).keys()].map(i => {
|
||||
let id = i + 1; // 0 => 1 - ids start with 1 and not with 0
|
||||
console.log(`Loading ${contract.constructor.name} #${id}`);
|
||||
debug(`Loading ${contract.constructor.name} #${id}`);
|
||||
return contract.getData(id).then(data => {
|
||||
console.log(`Pinning ${contract.constructor.name} #${id}`);
|
||||
debug(`Pinning ${contract.constructor.name} #${id}`);
|
||||
return this.ipfsApi.pin(data);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user