Skip to content

fix: change from deprecated ipfs-api to ipfs-http-client #1535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dapps/templates/boilerplate/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"versions": {
"web3": "1.0.0-beta",
"solc": "0.5.0",
"ipfs-api": "17.2.4"
"ipfs-http-client": "30.1.3"
},
"plugins": {
"embarkjs-connector-web3": {}
Expand Down
2 changes: 1 addition & 1 deletion dapps/templates/demo/app/components/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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> : ''
}
Expand Down
2 changes: 1 addition & 1 deletion dapps/templates/demo/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"versions": {
"web3": "1.0.0-beta",
"solc": "0.5.0",
"ipfs-api": "17.2.4"
"ipfs-http-client": "30.1.3"
},
"plugins": {
"embarkjs-connector-web3": {}
Expand Down
2 changes: 1 addition & 1 deletion dapps/tests/app/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3> 3. Contract Calls </h3>
</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>
Expand Down
2 changes: 1 addition & 1 deletion dapps/tests/app/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"versions": {
"solc": "0.4.25",
"web3": "1.0.0-beta",
"ipfs-api": "17.2.7"
"ipfs-http-client": "30.1.3"
},
"plugins": {
"embark-dapp-test-service": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"http-proxy": "1.17.0",
"http-shutdown": "1.2.0",
"i18n": "0.8.3",
"ipfs-api": "17.2.4",
"ipfs-http-client": "30.1.3",
"istanbul": "0.4.5",
"json-parse-better-errors": "1.0.2",
"live-plugin-manager-git-fix": "0.12.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/src/lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,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": "30.1.3"}, this.embarkConfig.versions || {});

var configObject = {
"default": {
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/src/lib/modules/codeRunner/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VM {
"eth-ens-namehash",
"swarm-api",
"embarkjs-whisper",
"ipfs-api",
"ipfs-http-client",
"embarkjs-ipfs",
"embarkjs-swarm",
"rxjs",
Expand Down
22 changes: 11 additions & 11 deletions packages/embark/src/lib/modules/ipfs/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js');
const IpfsApi = require('ipfs-api');
const IPFSClient = require('ipfs-http-client');
// TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
const constants = require('../../constants.json');
Expand Down Expand Up @@ -35,15 +35,15 @@ class IPFS {
});
}

downloadIpfsApi(cb) {
this.events.request("version:get:ipfs-api", (ipfsApiVersion) => {
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"];
if (ipfsApiVersion === currentIpfsApiVersion) {
downloadIPFSClient(cb) {
this.events.request("version:get:ipfs-http-client", (ipfsClientVersion) => {
let currentIPFSClientVersion = require('../../../../package.json').dependencies["ipfs-http-client"];
if (ipfsClientVersion === currentIPFSClientVersion) {
const nodePath = this.fs.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", ipfsClientVersion, (err, location) => {
cb(err, this.fs.dappPath(location));
});
});
Expand Down Expand Up @@ -98,19 +98,19 @@ class IPFS {
}

addStorageProviderToEmbarkJS() {
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', 'IPFS', require('ipfs-http-client'), () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks embarkjs-ipfs which relies on the variable IpfsAPI

let code = "";
code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
Expand All @@ -125,7 +125,7 @@ class IPFS {

addObjectToConsole() {
const {host, port} = this._getNodeUrlConfig();
let ipfs = IpfsApi(host, port);
let ipfs = IPFSClient(host, port);
this.events.emit("runcode:register", "ipfs", ipfs);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/embark/src/lib/modules/library_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class LibraryManager {

let solcVersionInConfig = this.contractsConfig.versions.solc;
let web3VersionInConfig = this.contractsConfig.versions["web3"];
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"];
let ipfsClientVersion = this.storageConfig.versions["ipfs-http-client"];

this.versions['solc'] = solcVersionInConfig;
this.versions['web3'] = web3VersionInConfig;
this.versions['ipfs-api'] = ipfsApiVersion;
this.versions['ipfs-http-client'] = ipfsClientVersion;

Object.keys(this.versions).forEach(versionKey => {
const newVersion = this.versions[versionKey].trim();
Expand Down
2 changes: 1 addition & 1 deletion packages/embarkjs-ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"ipfs-api": "17.2.4"
"ipfs-http-client": "30.1.3"
},
"devDependencies": {
"@babel/cli": "7.2.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/embarkjs-ipfs/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IpfsApi = require('ipfs-api');
const IPFS = require('ipfs-http-client');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small thing, not really a PR blocker. Usually in .js and .ts all caps is used for constants, so it might be a little confusing to have a "library variable" that looks like a constant later on in the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using all constants because IPFS is an acronym, like HTTP and TCP. This is also, technically, a constant 😉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with Michael here. I'd even rename it ipfsClient so it's clear what it is.


const __embarkIPFS = {};

Expand All @@ -10,7 +10,7 @@ __embarkIPFS.setProvider = function (options) {
try {
if (!options) {
self._config = options;
self._ipfsConnection = IpfsApi('localhost', '5001');
self._ipfsConnection = IPFS('localhost', '5001');
self._getUrl = "http://localhost:8080/ipfs/";
} else {
const ipfsOptions = {host: options.host || options.server, protocol: 'http'};
Expand All @@ -20,7 +20,7 @@ __embarkIPFS.setProvider = function (options) {
if (options.port && options.port !== 'false') {
ipfsOptions.port = options.port;
}
self._ipfsConnection = IpfsApi(ipfsOptions);
self._ipfsConnection = IPFS(ipfsOptions);
self._getUrl = options.getUrl || "http://localhost:8080/ipfs/";
}
resolve(self);
Expand Down
Loading