mirror of https://github.com/embarklabs/embark.git
Merge pull request #249 from nogueian/develop
Fixes to EmbarkJS and updating demo app
This commit is contained in:
commit
799fa2456b
|
@ -51,16 +51,26 @@ $(document).ready(function() {
|
|||
EmbarkJS.Storage.saveText(value).then(function(hash) {
|
||||
$("span.textHash").html(hash);
|
||||
$("input.textHash").val(hash);
|
||||
});
|
||||
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS saveText Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.loadIpfsHash").click(function() {
|
||||
var value = $("#storage input.textHash").val();
|
||||
EmbarkJS.Storage.get(value).then(function(content) {
|
||||
$("span.ipfsText").html(content);
|
||||
});
|
||||
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS get Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.uploadFile").click(function() {
|
||||
|
@ -68,8 +78,13 @@ $(document).ready(function() {
|
|||
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
|
||||
$("span.fileIpfsHash").html(hash);
|
||||
$("input.fileIpfsHash").val(hash);
|
||||
});
|
||||
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS uploadFile Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.loadIpfsFile").click(function() {
|
||||
|
|
|
@ -13,13 +13,25 @@ The current available storage is IPFS. it can be initialized as
|
|||
|
||||
.. code:: javascript
|
||||
|
||||
EmbarkJS.Storage.saveText("hello world").then(function(hash) {});
|
||||
EmbarkJS.Storage.saveText("hello world")
|
||||
.then(function(hash) {})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS saveText Error => " + err.message);
|
||||
}
|
||||
});
|
||||
|
||||
**Retrieving Data/Text**
|
||||
|
||||
.. code:: javascript
|
||||
|
||||
EmbarkJS.Storage.get(hash).then(function(content) {});
|
||||
EmbarkJS.Storage.get(hash)
|
||||
.then(function(content) {})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS get Error => " + err.message);
|
||||
}
|
||||
});
|
||||
|
||||
**Uploading a file**
|
||||
|
||||
|
@ -30,7 +42,13 @@ The current available storage is IPFS. it can be initialized as
|
|||
.. code:: javascript
|
||||
|
||||
var input = $("input[type=file"]);
|
||||
EmbarkJS.Storage.uploadFile(input).then(function(hash) {});
|
||||
EmbarkJS.Storage.uploadFile(input)
|
||||
.then(function(hash) {})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS uploadFile Error => " + err.message);
|
||||
}
|
||||
});
|
||||
|
||||
**Generate URL to file**
|
||||
|
||||
|
|
|
@ -2,56 +2,82 @@ var EmbarkJS =
|
|||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId])
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
|
||||
/******/
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ exports: {},
|
||||
/******/ id: moduleId,
|
||||
/******/ loaded: false
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.loaded = true;
|
||||
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
|
||||
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
|
||||
/******/
|
||||
/******/ // identity function for calling harmony imports with the correct context
|
||||
/******/ __webpack_require__.i = function(value) { return value; };
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ function(module, exports) {
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
/*jshint esversion: 6 */
|
||||
//var Ipfs = require('./ipfs.js');
|
||||
/*jshint esversion: 6 */
|
||||
//var Ipfs = require('./ipfs.js');
|
||||
|
||||
var EmbarkJS = {
|
||||
};
|
||||
var EmbarkJS = {
|
||||
};
|
||||
|
||||
EmbarkJS.Contract = function(options) {
|
||||
EmbarkJS.Contract = function(options) {
|
||||
var self = this;
|
||||
var i, abiElement;
|
||||
|
||||
|
@ -148,9 +174,9 @@ var EmbarkJS =
|
|||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
||||
EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
||||
var self = this;
|
||||
var contractParams;
|
||||
var options = _options || {};
|
||||
|
@ -182,15 +208,17 @@ var EmbarkJS =
|
|||
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.IPFS = 'ipfs';
|
||||
EmbarkJS.Storage = {
|
||||
IPFS : 'ipfs'
|
||||
};
|
||||
|
||||
EmbarkJS.Storage = {
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||
if (provider === 'ipfs') {
|
||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||
if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
|
||||
//I don't think currentStorage is used anywhere, this might not be needed
|
||||
//for now until additional storage providers are supported. But keeping it
|
||||
//anyways
|
||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||
if (options === undefined) {
|
||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
||||
|
@ -198,11 +226,11 @@ var EmbarkJS =
|
|||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
||||
}
|
||||
} else {
|
||||
throw Error('unknown provider');
|
||||
throw Error('Unknown storage provider');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.saveText = function(text) {
|
||||
EmbarkJS.Storage.saveText = function(text) {
|
||||
var self = this;
|
||||
if (!this.ipfsConnection) {
|
||||
this.setProvider('ipfs');
|
||||
|
@ -218,9 +246,9 @@ var EmbarkJS =
|
|||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
||||
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
||||
var self = this;
|
||||
var file = inputSelector[0].files[0];
|
||||
|
||||
|
@ -249,9 +277,9 @@ var EmbarkJS =
|
|||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.get = function(hash) {
|
||||
EmbarkJS.Storage.get = function(hash) {
|
||||
var self = this;
|
||||
// TODO: detect type, then convert if needed
|
||||
//var ipfsHash = web3.toAscii(hash);
|
||||
|
@ -262,22 +290,24 @@ var EmbarkJS =
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
||||
resolve(node.data);
|
||||
}).catch(function (err){
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.getUrl = function(hash) {
|
||||
EmbarkJS.Storage.getUrl = function(hash) {
|
||||
//var ipfsHash = web3.toAscii(hash);
|
||||
|
||||
return 'http://localhost:8080/ipfs/' + hash;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages = {
|
||||
};
|
||||
EmbarkJS.Messages = {
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||
var self = this;
|
||||
var ipfs;
|
||||
if (provider === 'whisper') {
|
||||
|
@ -308,20 +338,20 @@ var EmbarkJS =
|
|||
} else {
|
||||
throw Error('unknown provider');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.sendMessage = function(options) {
|
||||
EmbarkJS.Messages.sendMessage = function(options) {
|
||||
return this.currentMessages.sendMessage(options);
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.listenTo = function(options) {
|
||||
EmbarkJS.Messages.listenTo = function(options) {
|
||||
return this.currentMessages.listenTo(options);
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Whisper = {
|
||||
};
|
||||
EmbarkJS.Messages.Whisper = {
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
||||
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
||||
var topics = options.topic || options.topics;
|
||||
var data = options.data || options.payload;
|
||||
var identity = options.identity || this.identity || web3.shh.newIdentity();
|
||||
|
@ -359,9 +389,9 @@ var EmbarkJS =
|
|||
};
|
||||
|
||||
return web3.shh.post(message, function() {});
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Whisper.listenTo = function(options) {
|
||||
EmbarkJS.Messages.Whisper.listenTo = function(options) {
|
||||
var topics = options.topic || options.topics;
|
||||
var _topics = [];
|
||||
|
||||
|
@ -416,12 +446,12 @@ var EmbarkJS =
|
|||
promise.filter = filter;
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Orbit = {
|
||||
};
|
||||
EmbarkJS.Messages.Orbit = {
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||
var topics = options.topic || options.topics;
|
||||
var data = options.data || options.payload;
|
||||
|
||||
|
@ -445,9 +475,9 @@ var EmbarkJS =
|
|||
var payload = JSON.stringify(data);
|
||||
|
||||
this.orbit.send(topics, data);
|
||||
};
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.Orbit.listenTo = function(options) {
|
||||
EmbarkJS.Messages.Orbit.listenTo = function(options) {
|
||||
var self = this;
|
||||
var topics = options.topic || options.topics;
|
||||
|
||||
|
@ -488,10 +518,10 @@ var EmbarkJS =
|
|||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = EmbarkJS;
|
||||
module.exports = EmbarkJS;
|
||||
|
||||
|
||||
/***/ }
|
||||
/***/ })
|
||||
/******/ ]);
|
12
js/embark.js
12
js/embark.js
|
@ -137,13 +137,15 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||
return promise;
|
||||
};
|
||||
|
||||
EmbarkJS.IPFS = 'ipfs';
|
||||
|
||||
EmbarkJS.Storage = {
|
||||
IPFS : 'ipfs'
|
||||
};
|
||||
|
||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||
if (provider === 'ipfs') {
|
||||
if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
|
||||
//I don't think currentStorage is used anywhere, this might not be needed
|
||||
//for now until additional storage providers are supported. But keeping it
|
||||
//anyways
|
||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||
if (options === undefined) {
|
||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
||||
|
@ -151,7 +153,7 @@ EmbarkJS.Storage.setProvider = function(provider, options) {
|
|||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
||||
}
|
||||
} else {
|
||||
throw Error('unknown provider');
|
||||
throw Error('Unknown storage provider');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -215,6 +217,8 @@ EmbarkJS.Storage.get = function(hash) {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
||||
resolve(node.data);
|
||||
}).catch(function (err){
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue