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 is contained in:
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
window.ipfs = 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 }, (err, res) => {
|
||||
return res.toString();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -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.)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user