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:
@@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
@@ -7,6 +7,8 @@ import kreditsContracts from 'npm:kredits-contracts';
|
|||||||
|
|
||||||
export default Ember.Service.extend({
|
export default Ember.Service.extend({
|
||||||
|
|
||||||
|
ipfs: Ember.inject.service(),
|
||||||
|
|
||||||
web3Instance: null,
|
web3Instance: null,
|
||||||
web3Provided: false, // Web3 provided (using Mist Browser, Metamask et al.)
|
web3Provided: false, // Web3 provided (using Mist Browser, Metamask et al.)
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -21,8 +21,22 @@ module.exports = function(environment) {
|
|||||||
// when it is created
|
// when it is created
|
||||||
},
|
},
|
||||||
|
|
||||||
|
browserify: {
|
||||||
|
transform: [
|
||||||
|
["babelify", {
|
||||||
|
presets: ["es2015"],
|
||||||
|
global: true
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
web3ProviderUrl: "https://parity.kosmos.org:8545",
|
web3ProviderUrl: "https://parity.kosmos.org:8545",
|
||||||
ethereumChain: "testnet"
|
ethereumChain: "testnet",
|
||||||
|
ipfs: {
|
||||||
|
host: 'localhost',
|
||||||
|
port: '5001',
|
||||||
|
protocol: 'http'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (environment === 'development') {
|
if (environment === 'development') {
|
||||||
|
|||||||
+5
-2
@@ -19,6 +19,8 @@
|
|||||||
"deploy": "npm run build-prod && npm run update-version-file && bash scripts/deploy.sh"
|
"deploy": "npm run build-prod && npm run update-version-file && bash scripts/deploy.sh"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-preset-es2015": "^6.22.0",
|
||||||
|
"babelify": "^7.3.0",
|
||||||
"broccoli-asset-rev": "^2.4.5",
|
"broccoli-asset-rev": "^2.4.5",
|
||||||
"ember-ajax": "^2.4.1",
|
"ember-ajax": "^2.4.1",
|
||||||
"ember-browserify": "^1.1.13",
|
"ember-browserify": "^1.1.13",
|
||||||
@@ -39,9 +41,10 @@
|
|||||||
"ember-export-application-global": "^1.0.5",
|
"ember-export-application-global": "^1.0.5",
|
||||||
"ember-load-initializers": "^0.5.1",
|
"ember-load-initializers": "^0.5.1",
|
||||||
"ember-resolver": "^2.0.3",
|
"ember-resolver": "^2.0.3",
|
||||||
|
"ipfs-api": "^12.1.7",
|
||||||
|
"kredits-contracts": "67P/kredits-contracts",
|
||||||
"loader.js": "^4.0.10",
|
"loader.js": "^4.0.10",
|
||||||
"web3": "^0.18.2",
|
"web3": "^0.18.2"
|
||||||
"kredits-contracts": "67P/kredits-contracts"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.12.0"
|
"node": ">= 0.12.0"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { moduleFor, test } from 'ember-qunit';
|
||||||
|
|
||||||
|
moduleFor('service:ipfs', 'Unit | Service | ipfs', {
|
||||||
|
// Specify the other units that are required for this test.
|
||||||
|
// needs: ['service:foo']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Replace this with your real tests.
|
||||||
|
test('it exists', function(assert) {
|
||||||
|
let service = this.subject();
|
||||||
|
assert.ok(service);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user