Fix linter errors
# Conflicts: # lib/contracts/contribution.js # lib/contracts/contributor.js # lib/contracts/proposal.js # lib/kredits.js # lib/utils/pagination.js
This commit is contained in:
@@ -2,8 +2,7 @@ const ipfsClient = require('ipfs-http-client');
|
||||
const multihashes = require('multihashes');
|
||||
|
||||
class IPFS {
|
||||
|
||||
constructor(config) {
|
||||
constructor (config) {
|
||||
if (!config) {
|
||||
config = { host: 'localhost', port: '5001', protocol: 'http' };
|
||||
}
|
||||
@@ -11,7 +10,7 @@ class IPFS {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
catAndMerge(data, deserialize) {
|
||||
catAndMerge (data, deserialize) {
|
||||
// if no hash details are found simply return the data; nothing to merge
|
||||
if (!data.hashSize || data.hashSize === 0) {
|
||||
return data;
|
||||
@@ -26,7 +25,7 @@ class IPFS {
|
||||
});
|
||||
}
|
||||
|
||||
add(data) {
|
||||
add (data) {
|
||||
return this._ipfsAPI
|
||||
.add(ipfsClient.Buffer.from(data))
|
||||
.then((res) => {
|
||||
@@ -34,7 +33,7 @@ class IPFS {
|
||||
});
|
||||
}
|
||||
|
||||
cat(hashData) {
|
||||
cat (hashData) {
|
||||
let ipfsHash = hashData; // default - if it is a string
|
||||
if (hashData.hasOwnProperty('hashSize')) {
|
||||
ipfsHash = this.encodeHash(hashData);
|
||||
@@ -42,21 +41,20 @@ class IPFS {
|
||||
return this._ipfsAPI.cat(ipfsHash);
|
||||
}
|
||||
|
||||
decodeHash(ipfsHash) {
|
||||
decodeHash (ipfsHash) {
|
||||
let multihash = multihashes.decode(multihashes.fromB58String(ipfsHash));
|
||||
return {
|
||||
hashDigest: '0x' + multihashes.toHexString(multihash.digest),
|
||||
hashSize: multihash.length,
|
||||
hashFunction: multihash.code,
|
||||
ipfsHash: ipfsHash
|
||||
ipfsHash: ipfsHash,
|
||||
};
|
||||
}
|
||||
|
||||
encodeHash(hashData) {
|
||||
encodeHash (hashData) {
|
||||
let digest = ipfsClient.Buffer.from(hashData.hashDigest.slice(2), 'hex');
|
||||
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = IPFS;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class Preflight {
|
||||
constructor(kredits) {
|
||||
constructor (kredits) {
|
||||
this.kredits = kredits;
|
||||
}
|
||||
|
||||
check() {
|
||||
check () {
|
||||
return this.kredits.ipfs._ipfsAPI.id()
|
||||
.catch((error) => {
|
||||
throw new Error(`IPFS node not available; config: ${JSON.stringify(this.kredits.ipfs.config)} - ${error.message}`);
|
||||
|
||||
@@ -4,12 +4,12 @@ const validator = tv4.freshApi();
|
||||
validator.addFormat({
|
||||
'date': function(value) {
|
||||
const dateRegexp = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/;
|
||||
return dateRegexp.test(value) ? null : "A valid ISO 8601 full-date string is expected";
|
||||
return dateRegexp.test(value) ? null : 'A valid ISO 8601 full-date string is expected';
|
||||
},
|
||||
'time': function(value) {
|
||||
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
||||
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
|
||||
}
|
||||
})
|
||||
return timeRegexp.test(value) ? null : 'A valid ISO 8601 full-time string is expected';
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = validator;
|
||||
|
||||
Reference in New Issue
Block a user