Skip to content

Commit 48b0d50

Browse files
author
Andre Medeiros
committed
chore: migrate ipfs-api to ipfs-http-client
1 parent 3c9ed41 commit 48b0d50

File tree

15 files changed

+468
-256
lines changed

15 files changed

+468
-256
lines changed

dapps/templates/boilerplate/embark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"versions": {
1212
"web3": "1.0.0-beta",
1313
"solc": "0.5.0",
14-
"ipfs-api": "17.2.4"
14+
"ipfs-http-client": "32.0.1"
1515
},
1616
"plugins": {
1717
"embarkjs-connector-web3": {}

dapps/templates/demo/app/components/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Storage extends React.Component {
161161
!this.props.enabled ?
162162
<React.Fragment>
163163
<Alert bsStyle="warning">The node you are using does not support IPFS. Please ensure <a
164-
href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS
164+
href="https://github.com/ipfs/js-ipfs-http-client#cors" target="_blank">CORS</a> is setup for the IPFS
165165
node.</Alert>
166166
</React.Fragment> : ''
167167
}

dapps/templates/demo/embark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"versions": {
1212
"web3": "1.0.0-beta",
1313
"solc": "0.5.0",
14-
"ipfs-api": "17.2.4"
14+
"ipfs-http-client": "32.0.1"
1515
},
1616
"plugins": {
1717
"embarkjs-connector-web3": {}

dapps/tests/app/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h3> 3. Contract Calls </h3>
4242
</div>
4343
</div>
4444
<div role="tabpanel" class="tab-pane" id="storage">
45-
<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>
45+
<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>
4646
<div id="storage-controls">
4747

4848
<h3>Save text to IPFS</h3>

dapps/tests/app/embark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"versions": {
1818
"solc": "0.4.25",
1919
"web3": "1.0.0-beta",
20-
"ipfs-api": "17.2.7"
20+
"ipfs-http-client": "32.0.1"
2121
},
2222
"plugins": {
2323
"embark-dapp-test-service": {},

packages/embark-code-runner/src/vm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class VM {
4040
"eth-ens-namehash",
4141
"swarm-api",
4242
"embarkjs-whisper",
43-
"ipfs-api",
43+
"ipfs-http-client",
4444
"embarkjs-ipfs",
4545
"embarkjs-swarm",
4646
"rxjs",

packages/embark-library-manager/src/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { __ } from 'embark-i18n';
22
import { dappPath, embarkPath } from 'embark-utils';
33
var Npm = require('./npm.js');
44

5+
const DEPRECATIONS = {
6+
'ipfs-api': 'ipfs-http-client'
7+
};
8+
59
class LibraryManager {
610

711
constructor(embark, {useDashboard}) {
812
this.embark = embark;
13+
this.logger = embark.logger;
914
this.config = embark.config;
1015
this.contractsConfig = this.config.contractsConfig;
1116
this.storageConfig = this.config.storageConfig;
@@ -24,11 +29,11 @@ class LibraryManager {
2429

2530
let solcVersionInConfig = this.contractsConfig.versions.solc;
2631
let web3VersionInConfig = this.contractsConfig.versions["web3"];
27-
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"];
32+
let ipfsHttpClient = this.storageConfig.versions["ipfs-http-client"];
2833

2934
this.versions['solc'] = solcVersionInConfig;
3035
this.versions['web3'] = web3VersionInConfig;
31-
this.versions['ipfs-api'] = ipfsApiVersion;
36+
this.versions['ipfs-http-client'] = ipfsHttpClient;
3237

3338
Object.keys(this.versions).forEach(versionKey => {
3439
const newVersion = this.versions[versionKey].trim();
@@ -78,6 +83,14 @@ class LibraryManager {
7883
cb(lib);
7984
});
8085
}
86+
87+
for(let oldLib in DEPRECATIONS) {
88+
let replacement = DEPRECATIONS[oldLib];
89+
this.embark.events.setCommandHandler('version:get:' + oldLib, (cb) => {
90+
self.logger.warn(`${oldLib} has been deprecated in favor of ${replacement}. This will be used instead.`);
91+
self.embark.events.request(`version:get:${replacement}`, cb);
92+
});
93+
}
8194
}
8295

8396
downloadIfNeeded(packageName, cb) {
@@ -95,14 +108,27 @@ class LibraryManager {
95108
}
96109

97110
listenToCommandsToGetLibrary() {
111+
const self = this;
98112
let npm = new Npm({logger: this.embark.logger, useDashboard: this.useDashboard});
99113
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
114+
if(DEPRECATIONS[libName]) {
115+
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
116+
libName = DEPRECATIONS[libName];
117+
}
100118
npm.getPackageVersion(libName, version, cb);
101119
});
102120
this.embark.events.setCommandHandler('version:downloadIfNeeded', (libName, cb) => {
121+
if(DEPRECATIONS[libName]) {
122+
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
123+
libName = DEPRECATIONS[libName];
124+
}
103125
this.downloadIfNeeded(libName, cb);
104126
});
105127
this.embark.events.setCommandHandler('version:getPackagePath', (libName, version, cb) => {
128+
if(DEPRECATIONS[libName]) {
129+
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
130+
libName = DEPRECATIONS[libName];
131+
}
106132
cb(null, Npm.getPackagePath(libName, version));
107133
});
108134
}

packages/embark/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"hosted-git-info": "2.7.1",
150150
"http-proxy": "1.17.0",
151151
"http-shutdown": "1.2.0",
152-
"ipfs-api": "17.2.4",
152+
"ipfs-http-client": "32.0.1",
153153
"istanbul": "0.4.5",
154154
"json-parse-better-errors": "1.0.2",
155155
"live-plugin-manager-git-fix": "0.12.1",

packages/embark/src/lib/core/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ Config.prototype.loadExternalContractsFiles = function() {
435435
};
436436

437437
Config.prototype.loadStorageConfigFile = function() {
438-
var versions = recursiveMerge({"ipfs-api": "17.2.4"}, this.embarkConfig.versions || {});
438+
var versions = recursiveMerge({ "ipfs-http-client": "32.0.1" }, this.embarkConfig.versions || {});
439439

440440
var configObject = {
441441
"default": {

packages/embark/src/lib/modules/ipfs/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { __ } from 'embark-i18n';
22
const UploadIPFS = require('./upload.js');
33
const utils = require('../../utils/utils.js');
4-
const IpfsApi = require('ipfs-api');
4+
const IPFSHTTPClient = require('ipfs-http-client');
55
// TODO: not great, breaks module isolation
66
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
77
const constants = require('embark-core/constants');
@@ -64,15 +64,15 @@ class IPFS {
6464
});
6565
}
6666

67-
downloadIpfsApi(cb) {
68-
this.events.request("version:get:ipfs-api", (ipfsApiVersion) => {
69-
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"];
70-
if (ipfsApiVersion === currentIpfsApiVersion) {
67+
downloadIPFSHTTPClient(cb) {
68+
this.events.request("version:get:ipfs-http-client", (ipfsApiVersion) => {
69+
let currentIPFSHTTPClientVersion = require('../../../../package.json').dependencies["ipfs-http-client"];
70+
if (ipfsApiVersion === currentIPFSHTTPClientVersion) {
7171
const nodePath = embarkPath('node_modules');
72-
const ipfsPath = require.resolve("ipfs-api", {paths: [nodePath]});
72+
const ipfsPath = require.resolve("ipfs-http-client", {paths: [nodePath]});
7373
return cb(null, ipfsPath);
7474
}
75-
this.events.request("version:getPackageLocation", "ipfs-api", ipfsApiVersion, (err, location) => {
75+
this.events.request("version:getPackageLocation", "ipfs-http-client", ipfsApiVersion, (err, location) => {
7676
cb(err, dappPath(location));
7777
});
7878
});
@@ -131,19 +131,19 @@ class IPFS {
131131
addStorageProviderToEmbarkJS() {
132132
if(this.addedToEmbarkJs) return;
133133
this.addedToEmbarkJs = true;
134-
this.events.request('version:downloadIfNeeded', 'ipfs-api', (err, location) => {
134+
this.events.request('version:downloadIfNeeded', 'ipfs-http-client', (err, location) => {
135135
if (err) {
136136
this.logger.error(__('Error downloading IPFS API'));
137137
return this.logger.error(err.message || err);
138138
}
139139
this.events.request('code-generator:ready', () => {
140-
this.events.request('code-generator:symlink:generate', location, 'ipfs-api', (err, _symlinkDest) => {
140+
this.events.request('code-generator:symlink:generate', location, 'ipfs-http-client', (err, _symlinkDest) => {
141141
if (err) {
142142
this.logger.error(__('Error creating a symlink to IPFS API'));
143143
return this.logger.error(err.message || err);
144144
}
145145

146-
this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => {
146+
this.events.emit('runcode:register', 'IPFSHTTPClient', require('ipfs-http-client'), () => {
147147
let code = "";
148148
code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
149149
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
@@ -161,7 +161,7 @@ class IPFS {
161161
this.addedToConsole = true;
162162

163163
const {host, port} = this._getNodeUrlConfig();
164-
let ipfs = IpfsApi(host, port);
164+
let ipfs = IPFSHTTPClient(host, port);
165165
this.events.emit("runcode:register", "ipfs", ipfs);
166166
}
167167

packages/embarkjs-ipfs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"dependencies": {
5353
"@babel/runtime-corejs2": "7.3.1",
54-
"ipfs-api": "17.2.4"
54+
"ipfs-http-client": "32.0.1"
5555
},
5656
"devDependencies": {
5757
"@babel/cli": "7.2.3",

packages/embarkjs-ipfs/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const IpfsApi = require('ipfs-api');
1+
const IPFSHTTPClient = require('ipfs-http-client');
22

33
const __embarkIPFS = {};
44

@@ -10,7 +10,7 @@ __embarkIPFS.setProvider = function (options) {
1010
try {
1111
if (!options) {
1212
self._config = options;
13-
self._ipfsConnection = IpfsApi('localhost', '5001');
13+
self._ipfsConnection = IPFSHTTPClient('localhost', '5001');
1414
self._getUrl = "http://localhost:8080/ipfs/";
1515
} else {
1616
const ipfsOptions = {host: options.host || options.server, protocol: 'http'};
@@ -20,7 +20,7 @@ __embarkIPFS.setProvider = function (options) {
2020
if (options.port && options.port !== 'false') {
2121
ipfsOptions.port = options.port;
2222
}
23-
self._ipfsConnection = IpfsApi(ipfsOptions);
23+
self._ipfsConnection = IPFSHTTPClient(ipfsOptions);
2424
self._getUrl = options.getUrl || "http://localhost:8080/ipfs/";
2525
}
2626
resolve(self);
@@ -54,7 +54,7 @@ __embarkIPFS.saveText = function (text) {
5454
if (!self._ipfsConnection) {
5555
return reject(new Error(NoConnectionError));
5656
}
57-
self._ipfsConnection.add(self._ipfsConnection.Buffer.from(text), function (err, result) {
57+
self._ipfsConnection.add(IPFSHTTPClient.Buffer.from(text), function (err, result) {
5858
if (err) {
5959
return reject(err);
6060
}
@@ -96,7 +96,7 @@ __embarkIPFS.uploadFile = function (inputSelector) {
9696
}
9797
const reader = new FileReader();
9898
reader.onloadend = function () {
99-
const buffer = self._ipfsConnection.Buffer.from(reader.result);
99+
const buffer = IPFSHTTPClient.Buffer.from(reader.result);
100100
self._ipfsConnection.add(buffer, function (err, result) {
101101
if (err) {
102102
return reject(err);

site/source/docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Every application [created with Embark](create_project.html) comes with an `emba
2424
"versions": {
2525
"web3": "1.0.0-beta",
2626
"solc": "0.4.25",
27-
"ipfs-api": "17.2.4"
27+
"ipfs-http-client": "32.0.1"
2828
},
2929
"plugins": {
3030
},

site/source/docs/storage_configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
{"provider": "ipfs", "host": "localhost", "port": 5001, "getUrl": "http://localhost:8080/ipfs/"}
2828
],
2929
"versions": {
30-
"ipfs-api": "17.2.4"
30+
"ipfs-http-client": "32.0.1"
3131
}
3232
},
3333
"development": {
@@ -41,8 +41,8 @@ module.exports = {
4141

4242
The available options are:
4343

44-
Option | Type: `default` | Value
45-
--- | --- | ---
44+
Option | Type: `default` | Value
45+
--- | --- | ---
4646
`enabled` | boolean: `true` | Enables or completely disables storage support
4747
`ipfs_bin` | string: `ipfs` | Name or desired path to the ipfs binary
4848
`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
5353
`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`
5454
`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.
5555
`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.
56-
`dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage.
56+
`dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage.
5757
`dappConnection.protocol` | string: `http` | Storage provider protocol used in the dapp, i.e. `http` or `https`
5858
`dappConnection.host` | string | Host value used to interact with the storage provider in the dapp, i.e. `localhost` or `swarm-gateways.net`
5959
`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`).

0 commit comments

Comments
 (0)