Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
update deprecated ipfs-api package
Browse files Browse the repository at this point in the history
  • Loading branch information
Alaan Rahim committed Apr 25, 2019
1 parent 35c3c5c commit 10e471a
Show file tree
Hide file tree
Showing 11 changed files with 1,028 additions and 1,173 deletions.
4 changes: 2 additions & 2 deletions api/core/ipfs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ipfsAPI = require('ipfs-api')
const defaultIpfs = ipfsAPI(process.env.IPFS_HOST || '127.0.0.1')
const ipfsClient = require('ipfs-http-client')
const defaultIpfs = ipfsClient(process.env.IPFS_HOST || '127.0.0.1')

const add = async (data, ipfs = defaultIpfs) => {
const [ storedData ] = await ipfs.add(Buffer.from(data))
Expand Down
1,171 changes: 563 additions & 608 deletions api/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@appliedblockchain/b-privacy": "^1.2.0",
"@koa/cors": "^2.2.2",
"abi-decoder": "^1.2.0",
"ipfs-api": "^24.0.1",
"ipfs-http-client": "^30.1.3",
"koa": "^2.5.3",
"koa-compress": "^3.0.0",
"koa-joi-router": "^5.1.0",
Expand Down
6 changes: 3 additions & 3 deletions api/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function _createRouter(middleware, routes) {
/**
* Creates a new joi-router using the ipfs decorateCtx middleware and routes
* @func module:mantle/api/router.ipfs#createRouter
* @param {String|Object} ipfsApiOptions Passed to {@link module:mantle/api/router/routes/ipfs#decorateCtx}
* @param {String|Object} ipfsClientOptions Passed to {@link module:mantle/api/router/routes/ipfs#decorateCtx}
* @return {Object} joi-router instance
* @see module:mantle/api/router~_createRouter
* @see module:mantle/api/router/routes/ipfs#decorateCtx
* @see module:mantle/api/router/routes/ipfs#routes
*/
const createIpfsRouter = ipfsApiOptions =>
_createRouter(ipfs.decorateCtx(ipfsApiOptions), ipfs.routes)
const createIpfsRouter = ipfsClientOptions =>
_createRouter(ipfs.decorateCtx(ipfsClientOptions), ipfs.routes)

/**
* Creates a new joi-router using the parityProxy decorateCtx middleware and routes
Expand Down
12 changes: 6 additions & 6 deletions api/router/routes/ipfs/decorateCtx.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Creates a koa middleware function that adds an instance of ipfs-api to the context
* Creates a koa middleware function that adds an instance of ipfs-http-client to the context
* @func module:mantle/api/router/routes/ipfs#decorateCtx
* @param {Object|String} ipfsApiOptions This will be used to instantiate a new instance of ipfs-api
* @param {Object|String} ipfsClientOptions This will be used to instantiate a new instance of ipfs-http-client
* @return {Function} Koa middleware
* @see https://koajs.com/
* @see https://www.npmjs.com/package/ipfs-api
* @see https://www.npmjs.com/package/ipfs-http-client
*/
const decorateCtx = (ipfsApiOptions = '127.0.0.1') => {
const ipfsAPI = require('ipfs-api')
const decorateCtx = (ipfsClientOptions = '127.0.0.1') => {
const ipfsClient = require('ipfs-http-client')

return async (ctx, next) => {
ctx.ipfs = ipfsAPI(ipfsApiOptions)
ctx.ipfs = ipfsClient(ipfsClientOptions)
await next()
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/router/routes/ipfs/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const pin = async ctx => {

const get = async ctx => {
const { hash } = ctx.request.params
const retrieved = await ctx.ipfs.files.cat(hash)
const retrieved = await ctx.ipfs.cat(hash)
ctx.body = retrieved
}

Expand Down
6 changes: 3 additions & 3 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Creates and starts a koa server that uses the ipfs and transactions routers; Their endpoints will be prefixed with '/api/ipfs' and '/api' respectively.
* @alias module:mantle/api/server#createServer
* @param {Object} [options]
* @param {Object|String} [options.ipfsApiOptions] Will be passed to {@link module:mantle/api/router/routes/ipfs#decorateCtx}. Can also be specified using the IPFS_HOST environment variable.
* @param {Object|String} [options.ipfsClientOptions] Will be passed to {@link module:mantle/api/router/routes/ipfs#decorateCtx}. Can also be specified using the IPFS_HOST environment variable.
* @param {Object|String} [options.web3Options] Will be passed to {@link module:mantle/api/router/routes/transactions#decorateCtx}. Can also be specified using the PARITY_HOST environment variable.
* @param {Integer|String} [options.port=3000] Port that the server will listen on. Can also be specified using the PORT environment variable.
* @return {Object} The created koa instance
* @see module:mantle/api/router.ipfs#createRouter
* @see module:mantle/api/router.transactions#createRouter
*/
module.exports = ({ ipfsApiOptions = process.env.IPFS_HOST, web3Options = process.env.PARITY_HOST, port = process.env.PORT || 3000 } = {}) => {
module.exports = ({ ipfsClientOptions = process.env.IPFS_HOST, web3Options = process.env.PARITY_HOST, port = process.env.PORT || 3000 } = {}) => {
const Koa = require('koa')
const cors = require('@koa/cors')
const compress = require('koa-compress')
Expand All @@ -26,7 +26,7 @@ module.exports = ({ ipfsApiOptions = process.env.IPFS_HOST, web3Options = proces
.use(respond())
.use(cors())
.use(
ipfs.createRouter(ipfsApiOptions)
ipfs.createRouter(ipfsClientOptions)
.prefix('/api/ipfs')
.middleware()
)
Expand Down
6 changes: 3 additions & 3 deletions api/test/ipfs-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ipfsAPI = require('ipfs-api')
const ipfsApiOptions = '127.0.0.1'
const ipfsClient = require('ipfs-http-client')
const ipfsClientOptions = '127.0.0.1'

const ipfs = ipfsAPI(ipfsApiOptions)
const ipfs = ipfsClient(ipfsClientOptions)
const { randomBytes } = require('crypto')

const generateHash = async () => {
Expand Down
Loading

0 comments on commit 10e471a

Please sign in to comment.