From 2bf91b6d9a161d6fa279cb28cfbf6f36147f94ab Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 23 Jul 2017 08:15:40 -0400 Subject: [PATCH] make storage getUrl configurable --- js/embark.js | 5 ++++- lib/contracts/abi.js | 3 ++- lib/core/config.js | 3 ++- test_app/config/storage.json | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/js/embark.js b/js/embark.js index 6b378cd3..cd12d9e2 100644 --- a/js/embark.js +++ b/js/embark.js @@ -208,8 +208,10 @@ EmbarkJS.Storage.setProvider = function(provider, options) { try { if (options === undefined) { self.ipfsConnection = IpfsApi('localhost', '5001'); + self.getUrl = "http://localhost:8080/ipfs/"; } else { self.ipfsConnection = IpfsApi(options.server, options.port); + self.getUrl = options.getUrl || "http://localhost:8080/ipfs/"; } resolve(self); } catch (err) { @@ -301,7 +303,8 @@ EmbarkJS.Storage.IPFS.uploadFile = function(inputSelector) { EmbarkJS.Storage.IPFS.getUrl = function(hash) { //var ipfsHash = web3.toAscii(hash); - return 'http://localhost:8080/ipfs/' + hash; + //return 'http://localhost:8080/ipfs/' + hash; + return (self.getUrl || "http://localhost:8080/ipfs/") + hash; }; //========================================================= diff --git a/lib/contracts/abi.js b/lib/contracts/abi.js index 7ec51da3..015e0164 100644 --- a/lib/contracts/abi.js +++ b/lib/contracts/abi.js @@ -158,7 +158,8 @@ class ABIGenerator { if (!useEmbarkJS || self.storageConfig === {}) return ""; if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) { - result += "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});"; + // TODO: make this more readable + result += "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});"; } return result; diff --git a/lib/core/config.js b/lib/core/config.js index b27ce0bf..2a9703bc 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -119,7 +119,8 @@ Config.prototype.loadStorageConfigFile = function() { "ipfs_bin": "ipfs", "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" }, "development": { } diff --git a/test_app/config/storage.json b/test_app/config/storage.json index 9d686457..6faf0e1a 100644 --- a/test_app/config/storage.json +++ b/test_app/config/storage.json @@ -11,6 +11,7 @@ "enabled": true, "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" } }