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) {
|
EmbarkJS.Storage.saveText(value).then(function(hash) {
|
||||||
$("span.textHash").html(hash);
|
$("span.textHash").html(hash);
|
||||||
$("input.textHash").val(hash);
|
$("input.textHash").val(hash);
|
||||||
});
|
|
||||||
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(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() {
|
$("#storage button.loadIpfsHash").click(function() {
|
||||||
var value = $("#storage input.textHash").val();
|
var value = $("#storage input.textHash").val();
|
||||||
EmbarkJS.Storage.get(value).then(function(content) {
|
EmbarkJS.Storage.get(value).then(function(content) {
|
||||||
$("span.ipfsText").html(content);
|
$("span.ipfsText").html(content);
|
||||||
});
|
|
||||||
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(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() {
|
$("#storage button.uploadFile").click(function() {
|
||||||
|
@ -68,8 +78,13 @@ $(document).ready(function() {
|
||||||
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
|
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
|
||||||
$("span.fileIpfsHash").html(hash);
|
$("span.fileIpfsHash").html(hash);
|
||||||
$("input.fileIpfsHash").val(hash);
|
$("input.fileIpfsHash").val(hash);
|
||||||
});
|
|
||||||
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(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() {
|
$("#storage button.loadIpfsFile").click(function() {
|
||||||
|
|
|
@ -13,13 +13,25 @@ The current available storage is IPFS. it can be initialized as
|
||||||
|
|
||||||
.. code:: javascript
|
.. 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**
|
**Retrieving Data/Text**
|
||||||
|
|
||||||
.. code:: javascript
|
.. 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**
|
**Uploading a file**
|
||||||
|
|
||||||
|
@ -30,7 +42,13 @@ The current available storage is IPFS. it can be initialized as
|
||||||
.. code:: javascript
|
.. code:: javascript
|
||||||
|
|
||||||
var input = $("input[type=file"]);
|
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**
|
**Generate URL to file**
|
||||||
|
|
||||||
|
|
|
@ -2,48 +2,74 @@ var EmbarkJS =
|
||||||
/******/ (function(modules) { // webpackBootstrap
|
/******/ (function(modules) { // webpackBootstrap
|
||||||
/******/ // The module cache
|
/******/ // The module cache
|
||||||
/******/ var installedModules = {};
|
/******/ var installedModules = {};
|
||||||
|
/******/
|
||||||
/******/ // The require function
|
/******/ // The require function
|
||||||
/******/ function __webpack_require__(moduleId) {
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/
|
||||||
/******/ // Check if module is in cache
|
/******/ // Check if module is in cache
|
||||||
/******/ if(installedModules[moduleId])
|
/******/ if(installedModules[moduleId])
|
||||||
/******/ return installedModules[moduleId].exports;
|
/******/ return installedModules[moduleId].exports;
|
||||||
|
/******/
|
||||||
/******/ // Create a new module (and put it into the cache)
|
/******/ // Create a new module (and put it into the cache)
|
||||||
/******/ var module = installedModules[moduleId] = {
|
/******/ var module = installedModules[moduleId] = {
|
||||||
/******/ exports: {},
|
/******/ i: moduleId,
|
||||||
/******/ id: moduleId,
|
/******/ l: false,
|
||||||
/******/ loaded: false
|
/******/ exports: {}
|
||||||
/******/ };
|
/******/ };
|
||||||
|
/******/
|
||||||
/******/ // Execute the module function
|
/******/ // Execute the module function
|
||||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
/******/ // Flag the module as loaded
|
/******/ // Flag the module as loaded
|
||||||
/******/ module.loaded = true;
|
/******/ module.l = true;
|
||||||
|
/******/
|
||||||
/******/ // Return the exports of the module
|
/******/ // Return the exports of the module
|
||||||
/******/ return module.exports;
|
/******/ return module.exports;
|
||||||
/******/ }
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
/******/ // expose the modules object (__webpack_modules__)
|
/******/ // expose the modules object (__webpack_modules__)
|
||||||
/******/ __webpack_require__.m = modules;
|
/******/ __webpack_require__.m = modules;
|
||||||
|
/******/
|
||||||
/******/ // expose the module cache
|
/******/ // expose the module cache
|
||||||
/******/ __webpack_require__.c = installedModules;
|
/******/ __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_public_path__
|
||||||
/******/ __webpack_require__.p = "";
|
/******/ __webpack_require__.p = "";
|
||||||
|
/******/
|
||||||
/******/ // Load entry module and return exports
|
/******/ // Load entry module and return exports
|
||||||
/******/ return __webpack_require__(0);
|
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||||
/******/ })
|
/******/ })
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/******/ ([
|
/******/ ([
|
||||||
/* 0 */
|
/* 0 */
|
||||||
/***/ function(module, exports) {
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
//var Ipfs = require('./ipfs.js');
|
//var Ipfs = require('./ipfs.js');
|
||||||
|
@ -184,13 +210,15 @@ var EmbarkJS =
|
||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.IPFS = 'ipfs';
|
|
||||||
|
|
||||||
EmbarkJS.Storage = {
|
EmbarkJS.Storage = {
|
||||||
|
IPFS : 'ipfs'
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
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;
|
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
this.ipfsConnection = IpfsApi('localhost', '5001');
|
||||||
|
@ -198,7 +226,7 @@ var EmbarkJS =
|
||||||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
this.ipfsConnection = IpfsApi(options.server, options.port);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Error('unknown provider');
|
throw Error('Unknown storage provider');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -262,6 +290,8 @@ var EmbarkJS =
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
self.ipfsConnection.object.get([hash]).then(function(node) {
|
||||||
resolve(node.data);
|
resolve(node.data);
|
||||||
|
}).catch(function (err){
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -493,5 +523,5 @@ var EmbarkJS =
|
||||||
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;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.IPFS = 'ipfs';
|
|
||||||
|
|
||||||
EmbarkJS.Storage = {
|
EmbarkJS.Storage = {
|
||||||
|
IPFS : 'ipfs'
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
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;
|
this.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
this.ipfsConnection = IpfsApi('localhost', '5001');
|
||||||
|
@ -151,7 +153,7 @@ EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
this.ipfsConnection = IpfsApi(options.server, options.port);
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
self.ipfsConnection.object.get([hash]).then(function(node) {
|
||||||
resolve(node.data);
|
resolve(node.data);
|
||||||
|
}).catch(function (err){
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue