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

Commit

Permalink
wip: pin.remote.add|ls|rm
Browse files Browse the repository at this point in the history
This adds basic boilerplate for supporting remote pinning commands
introduced in ipfs/kubo#7661

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Sep 18, 2020
1 parent 3ff833d commit caf935f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/core-api/PIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
- [Options](#options-4)
- [Returns](#returns-4)
- [Example](#example-4)
- TODO `ipfs.pin.remote.add(ipfsPath, [options])`
- TODO `ipfs.pin.remote.ls([options])`
- TODO `ipfs.pin.remote.rm(requestid)`
- TODO `ipfs.pin.remote.~TBD~replace(requestid, ipfsPath, [options])`

## `ipfs.pin.add(ipfsPath, [options])`

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/pin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = config => ({
addAll: require('./add-all')(config),
ls: require('./ls')(config),
rm: require('./rm')(config),
rmAll: require('./rm-all')(config)
rmAll: require('./rm-all')(config),
remote: require('./remote')(config)
})
20 changes: 20 additions & 0 deletions packages/ipfs-http-client/src/pin/remote/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const toCamel = require('../../lib/object-to-camel')

module.exports = configure(api => {
return async (path, options = {}) => {
const res = await api.post('pin/remote/add', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
...options
}),
headers: options.headers
})
return toCamel(await res.json())
}
})
7 changes: 7 additions & 0 deletions packages/ipfs-http-client/src/pin/remote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = config => ({
add: require('./add')(config),
ls: require('./ls')(config),
rm: require('./rm')(config)
})
21 changes: 21 additions & 0 deletions packages/ipfs-http-client/src/pin/remote/ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const toCamel = require('../../lib/object-to-camel')

module.exports = configure(api => {
return async (path, options = {}) => {
const res = await api.post('pin/remote/ls', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
...options
}),
headers: options.headers
})
const pins = await res.json()
return pins.map(toCamel)
}
})
20 changes: 20 additions & 0 deletions packages/ipfs-http-client/src/pin/remote/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
const toCamel = require('../../lib/object-to-camel')

module.exports = configure(api => {
return async (path, options = {}) => {
const res = await api.post('pin/remote/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
...options
}),
headers: options.headers
})
return toCamel(await res.json())
}
})

0 comments on commit caf935f

Please sign in to comment.