mirror of https://github.com/embarklabs/embark.git
chore: migrate ipfs-api to ipfs-http-client
This commit is contained in:
parent
3c9ed4183d
commit
e07dc09b53
|
@ -11,7 +11,7 @@
|
|||
"versions": {
|
||||
"web3": "1.0.0-beta",
|
||||
"solc": "0.5.0",
|
||||
"ipfs-api": "17.2.4"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
},
|
||||
"plugins": {
|
||||
"embarkjs-connector-web3": {}
|
||||
|
|
|
@ -161,7 +161,7 @@ class Storage extends React.Component {
|
|||
!this.props.enabled ?
|
||||
<React.Fragment>
|
||||
<Alert bsStyle="warning">The node you are using does not support IPFS. Please ensure <a
|
||||
href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS
|
||||
href="https://github.com/ipfs/js-ipfs-http-client#cors" target="_blank">CORS</a> is setup for the IPFS
|
||||
node.</Alert>
|
||||
</React.Fragment> : ''
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"versions": {
|
||||
"web3": "1.0.0-beta",
|
||||
"solc": "0.5.0",
|
||||
"ipfs-api": "17.2.4"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
},
|
||||
"plugins": {
|
||||
"embarkjs-connector-web3": {}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="storage">
|
||||
<div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS node.</div>
|
||||
<div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-http-client#cors" target="_blank">CORS</a> is setup for the IPFS node.</div>
|
||||
<div id="storage-controls">
|
||||
|
||||
<h3>Save text to IPFS</h3>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
"versions": {
|
||||
"solc": "0.4.25",
|
||||
"web3": "1.0.0-beta",
|
||||
"ipfs-api": "17.2.7"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
},
|
||||
"plugins": {
|
||||
"embark-dapp-test-service": {},
|
||||
|
|
|
@ -40,7 +40,7 @@ class VM {
|
|||
"eth-ens-namehash",
|
||||
"swarm-api",
|
||||
"embarkjs-whisper",
|
||||
"ipfs-api",
|
||||
"ipfs-http-client",
|
||||
"embarkjs-ipfs",
|
||||
"embarkjs-swarm",
|
||||
"rxjs",
|
||||
|
|
|
@ -2,10 +2,15 @@ import { __ } from 'embark-i18n';
|
|||
import { dappPath, embarkPath } from 'embark-utils';
|
||||
var Npm = require('./npm.js');
|
||||
|
||||
const DEPRECATIONS = {
|
||||
'ipfs-api': 'ipfs-http-client'
|
||||
};
|
||||
|
||||
class LibraryManager {
|
||||
|
||||
constructor(embark, {useDashboard}) {
|
||||
this.embark = embark;
|
||||
this.logger = embark.logger;
|
||||
this.config = embark.config;
|
||||
this.contractsConfig = this.config.contractsConfig;
|
||||
this.storageConfig = this.config.storageConfig;
|
||||
|
@ -24,11 +29,11 @@ class LibraryManager {
|
|||
|
||||
let solcVersionInConfig = this.contractsConfig.versions.solc;
|
||||
let web3VersionInConfig = this.contractsConfig.versions["web3"];
|
||||
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"];
|
||||
let ipfsHttpClientVersion = this.storageConfig.versions["ipfs-http-client"];
|
||||
|
||||
this.versions['solc'] = solcVersionInConfig;
|
||||
this.versions['web3'] = web3VersionInConfig;
|
||||
this.versions['ipfs-api'] = ipfsApiVersion;
|
||||
this.versions['ipfs-http-client'] = ipfsHttpClientVersion;
|
||||
|
||||
Object.keys(this.versions).forEach(versionKey => {
|
||||
const newVersion = this.versions[versionKey].trim();
|
||||
|
@ -78,6 +83,14 @@ class LibraryManager {
|
|||
cb(lib);
|
||||
});
|
||||
}
|
||||
|
||||
for(let oldLib in DEPRECATIONS) {
|
||||
let replacement = DEPRECATIONS[oldLib];
|
||||
this.embark.events.setCommandHandler('version:get:' + oldLib, (cb) => {
|
||||
self.logger.warn(`${oldLib} has been deprecated in favor of ${replacement}. This will be used instead.`);
|
||||
self.embark.events.request(`version:get:${replacement}`, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
downloadIfNeeded(packageName, cb) {
|
||||
|
@ -95,14 +108,27 @@ class LibraryManager {
|
|||
}
|
||||
|
||||
listenToCommandsToGetLibrary() {
|
||||
const self = this;
|
||||
let npm = new Npm({logger: this.embark.logger, useDashboard: this.useDashboard});
|
||||
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
|
||||
if(DEPRECATIONS[libName]) {
|
||||
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
|
||||
libName = DEPRECATIONS[libName];
|
||||
}
|
||||
npm.getPackageVersion(libName, version, cb);
|
||||
});
|
||||
this.embark.events.setCommandHandler('version:downloadIfNeeded', (libName, cb) => {
|
||||
if(DEPRECATIONS[libName]) {
|
||||
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
|
||||
libName = DEPRECATIONS[libName];
|
||||
}
|
||||
this.downloadIfNeeded(libName, cb);
|
||||
});
|
||||
this.embark.events.setCommandHandler('version:getPackagePath', (libName, version, cb) => {
|
||||
if(DEPRECATIONS[libName]) {
|
||||
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
|
||||
libName = DEPRECATIONS[libName];
|
||||
}
|
||||
cb(null, Npm.getPackagePath(libName, version));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@
|
|||
"hosted-git-info": "2.7.1",
|
||||
"http-proxy": "1.17.0",
|
||||
"http-shutdown": "1.2.0",
|
||||
"ipfs-api": "17.2.4",
|
||||
"ipfs-http-client": "32.0.1",
|
||||
"istanbul": "0.4.5",
|
||||
"json-parse-better-errors": "1.0.2",
|
||||
"live-plugin-manager-git-fix": "0.12.1",
|
||||
|
|
|
@ -435,7 +435,7 @@ Config.prototype.loadExternalContractsFiles = function() {
|
|||
};
|
||||
|
||||
Config.prototype.loadStorageConfigFile = function() {
|
||||
var versions = recursiveMerge({"ipfs-api": "17.2.4"}, this.embarkConfig.versions || {});
|
||||
var versions = recursiveMerge({ "ipfs-http-client": "32.0.1" }, this.embarkConfig.versions || {});
|
||||
|
||||
var configObject = {
|
||||
"default": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { __ } from 'embark-i18n';
|
||||
const UploadIPFS = require('./upload.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const IpfsApi = require('ipfs-api');
|
||||
const IPFSHTTPClient = require('ipfs-http-client');
|
||||
// TODO: not great, breaks module isolation
|
||||
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
|
||||
const constants = require('embark-core/constants');
|
||||
|
@ -64,15 +64,15 @@ class IPFS {
|
|||
});
|
||||
}
|
||||
|
||||
downloadIpfsApi(cb) {
|
||||
this.events.request("version:get:ipfs-api", (ipfsApiVersion) => {
|
||||
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"];
|
||||
if (ipfsApiVersion === currentIpfsApiVersion) {
|
||||
downloadIPFSHTTPClient(cb) {
|
||||
this.events.request("version:get:ipfs-http-client", (ipfsApiVersion) => {
|
||||
let currentIPFSHTTPClientVersion = require('../../../../package.json').dependencies["ipfs-http-client"];
|
||||
if (ipfsApiVersion === currentIPFSHTTPClientVersion) {
|
||||
const nodePath = embarkPath('node_modules');
|
||||
const ipfsPath = require.resolve("ipfs-api", {paths: [nodePath]});
|
||||
const ipfsPath = require.resolve("ipfs-http-client", {paths: [nodePath]});
|
||||
return cb(null, ipfsPath);
|
||||
}
|
||||
this.events.request("version:getPackageLocation", "ipfs-api", ipfsApiVersion, (err, location) => {
|
||||
this.events.request("version:getPackageLocation", "ipfs-http-client", ipfsApiVersion, (err, location) => {
|
||||
cb(err, dappPath(location));
|
||||
});
|
||||
});
|
||||
|
@ -131,19 +131,19 @@ class IPFS {
|
|||
addStorageProviderToEmbarkJS() {
|
||||
if(this.addedToEmbarkJs) return;
|
||||
this.addedToEmbarkJs = true;
|
||||
this.events.request('version:downloadIfNeeded', 'ipfs-api', (err, location) => {
|
||||
this.events.request('version:downloadIfNeeded', 'ipfs-http-client', (err, location) => {
|
||||
if (err) {
|
||||
this.logger.error(__('Error downloading IPFS API'));
|
||||
return this.logger.error(err.message || err);
|
||||
}
|
||||
this.events.request('code-generator:ready', () => {
|
||||
this.events.request('code-generator:symlink:generate', location, 'ipfs-api', (err, _symlinkDest) => {
|
||||
this.events.request('code-generator:symlink:generate', location, 'ipfs-http-client', (err, _symlinkDest) => {
|
||||
if (err) {
|
||||
this.logger.error(__('Error creating a symlink to IPFS API'));
|
||||
return this.logger.error(err.message || err);
|
||||
}
|
||||
|
||||
this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => {
|
||||
this.events.emit('runcode:register', 'IPFSHTTPClient', require('ipfs-http-client'), () => {
|
||||
let code = "";
|
||||
code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
|
||||
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
|
||||
|
@ -161,7 +161,7 @@ class IPFS {
|
|||
this.addedToConsole = true;
|
||||
|
||||
const {host, port} = this._getNodeUrlConfig();
|
||||
let ipfs = IpfsApi(host, port);
|
||||
let ipfs = IPFSHTTPClient(host, port);
|
||||
this.events.emit("runcode:register", "ipfs", ipfs);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"ipfs-api": "17.2.4"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const IpfsApi = require('ipfs-api');
|
||||
const IPFSHTTPClient = require('ipfs-http-client');
|
||||
|
||||
const __embarkIPFS = {};
|
||||
|
||||
|
@ -10,7 +10,7 @@ __embarkIPFS.setProvider = function (options) {
|
|||
try {
|
||||
if (!options) {
|
||||
self._config = options;
|
||||
self._ipfsConnection = IpfsApi('localhost', '5001');
|
||||
self._ipfsConnection = IPFSHTTPClient('localhost', '5001');
|
||||
self._getUrl = "http://localhost:8080/ipfs/";
|
||||
} else {
|
||||
const ipfsOptions = {host: options.host || options.server, protocol: 'http'};
|
||||
|
@ -20,7 +20,7 @@ __embarkIPFS.setProvider = function (options) {
|
|||
if (options.port && options.port !== 'false') {
|
||||
ipfsOptions.port = options.port;
|
||||
}
|
||||
self._ipfsConnection = IpfsApi(ipfsOptions);
|
||||
self._ipfsConnection = IPFSHTTPClient(ipfsOptions);
|
||||
self._getUrl = options.getUrl || "http://localhost:8080/ipfs/";
|
||||
}
|
||||
resolve(self);
|
||||
|
@ -54,7 +54,7 @@ __embarkIPFS.saveText = function (text) {
|
|||
if (!self._ipfsConnection) {
|
||||
return reject(new Error(NoConnectionError));
|
||||
}
|
||||
self._ipfsConnection.add(self._ipfsConnection.Buffer.from(text), function (err, result) {
|
||||
self._ipfsConnection.add(IPFSHTTPClient.Buffer.from(text), function (err, result) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ __embarkIPFS.uploadFile = function (inputSelector) {
|
|||
}
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = function () {
|
||||
const buffer = self._ipfsConnection.Buffer.from(reader.result);
|
||||
const buffer = IPFSHTTPClient.Buffer.from(reader.result);
|
||||
self._ipfsConnection.add(buffer, function (err, result) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
|
|
|
@ -24,7 +24,7 @@ Every application [created with Embark](create_project.html) comes with an `emba
|
|||
"versions": {
|
||||
"web3": "1.0.0-beta",
|
||||
"solc": "0.4.25",
|
||||
"ipfs-api": "17.2.4"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
},
|
||||
"plugins": {
|
||||
},
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = {
|
|||
{"provider": "ipfs", "host": "localhost", "port": 5001, "getUrl": "http://localhost:8080/ipfs/"}
|
||||
],
|
||||
"versions": {
|
||||
"ipfs-api": "17.2.4"
|
||||
"ipfs-http-client": "32.0.1"
|
||||
}
|
||||
},
|
||||
"development": {
|
||||
|
@ -41,8 +41,8 @@ module.exports = {
|
|||
|
||||
The available options are:
|
||||
|
||||
Option | Type: `default` | Value
|
||||
--- | --- | ---
|
||||
Option | Type: `default` | Value
|
||||
--- | --- | ---
|
||||
`enabled` | boolean: `true` | Enables or completely disables storage support
|
||||
`ipfs_bin` | string: `ipfs` | Name or desired path to the ipfs binary
|
||||
`available_providers` | array: `["ipfs", "swarm"]` | List of storages to be supported on the dapp. This will affect what's available with the EmbarkJS library on the dapp.
|
||||
|
@ -53,7 +53,7 @@ Option | Type: `default` | Value
|
|||
`upload.port` | integer: `5001` | Port value used to interact with the storage provider for upload, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80`
|
||||
`upload.getUrl` | string: `http://localhost:8080/ipfs/` | Only for IPFS. This sets the file/document retrieval URL, which is different than the host/port combination used to interact with the IPFS API.
|
||||
`dappConnection` | | List of storage providers to attempt connection to in the dapp. Each provider process will be launched in a child process. Each connection listed will be tried in order on the dapp, until one is avaialable. Can also specify `$BZZ` to attempt to connect to an injected swarm object.
|
||||
`dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage.
|
||||
`dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage.
|
||||
`dappConnection.protocol` | string: `http` | Storage provider protocol used in the dapp, i.e. `http` or `https`
|
||||
`dappConnection.host` | string | Host value used to interact with the storage provider in the dapp, i.e. `localhost` or `swarm-gateways.net`
|
||||
`dappConnection.port` | integer | Port value used to interact with the storage provider in the dapp, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80`. Can specify `false` if a port should not be included in the connection URL (i.e. for a public gateway like `http://swarm-gateways.net`).
|
||||
|
|
Loading…
Reference in New Issue