Add IPFS service (#4)

Add IPFS service

Add the `ipfs-api` JS library and a service using the browserified
version of it. The service has functions for storing and reading file
contests.
This commit was merged in pull request #4.
This commit is contained in:
2017-02-18 09:48:26 +00:00
committed by GitHub
parent 2a9f9a50c4
commit 26cebc11c6
5 changed files with 65 additions and 3 deletions
+31
View File
@@ -0,0 +1,31 @@
import Ember from 'ember';
import ipfsAPI from 'npm:ipfs-api';
import config from 'kredits-web/config/environment';
export default Ember.Service.extend({
ipfsInstance: null,
ipfs: function() {
if (this.get('ipfsInstance')) {
return this.get('ipfsInstance');
}
let ipfs = ipfsAPI(config.ipfs);
this.set('ipfsInstance', ipfs);
return ipfs;
}.property('ipfsInstance'),
storeFile(content) {
let ipfs = this.get('ipfs');
return ipfs.add(new ipfs.Buffer(content)).then(res => {
return res[0].hash;
});
},
getFile(hash) {
return this.get('ipfs').cat(hash, { buffer: true }).then(res => {
return res.toString();
});
}
});
+2
View File
@@ -7,6 +7,8 @@ import kreditsContracts from 'npm:kredits-contracts';
export default Ember.Service.extend({
ipfs: Ember.inject.service(),
web3Instance: null,
web3Provided: false, // Web3 provided (using Mist Browser, Metamask et al.)