This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support remote pinning services in ipfs-http-client (#3293)
Implement [remote pinning service API](https://github.com/ipfs/pinning-services-api-spec) in ipfs-http-client.
- Loading branch information
Showing
25 changed files
with
2,214 additions
and
22 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { fixtures, clearRemotePins, clearServices } = require('../utils') | ||
const { getDescribe, getIt, expect } = require('../../utils/mocha') | ||
const testTimeout = require('../../utils/test-timeout') | ||
const CID = require('cids') | ||
|
||
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ | ||
/** | ||
* @param {Factory} common | ||
* @param {Object} options | ||
*/ | ||
module.exports = (common, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
|
||
const ENDPOINT = new URL(process.env.PINNING_SERVICE_ENDPOINT || '') | ||
const KEY = process.env.PINNING_SERVIEC_KEY | ||
const SERVICE = 'pinbot' | ||
|
||
describe('.pin.remote.add', function () { | ||
this.timeout(50 * 1000) | ||
|
||
let ipfs | ||
before(async () => { | ||
ipfs = (await common.spawn()).api | ||
await ipfs.pin.remote.service.add(SERVICE, { | ||
endpoint: ENDPOINT, | ||
key: KEY | ||
}) | ||
}) | ||
after(async () => { | ||
await clearServices(ipfs) | ||
await common.clean() | ||
}) | ||
|
||
beforeEach(async () => { | ||
await clearRemotePins(ipfs) | ||
}) | ||
|
||
it('should add a CID and return the added CID', async () => { | ||
const pin = await ipfs.pin.remote.add(fixtures.files[0].cid, { | ||
name: 'fixtures-files-0', | ||
background: true, | ||
service: SERVICE | ||
}) | ||
|
||
expect(pin).to.deep.equal({ | ||
status: 'queued', | ||
cid: fixtures.files[0].cid, | ||
name: 'fixtures-files-0' | ||
}) | ||
}) | ||
|
||
it('should fail if service is not provided', async () => { | ||
const result = ipfs.pin.remote.add(fixtures.files[0].cid, { | ||
name: 'fixtures-files-0', | ||
background: true | ||
}) | ||
|
||
await expect(result).to.eventually.be.rejectedWith(/service name must be passed/) | ||
}) | ||
|
||
it('if name is not provided defaults to ""', async () => { | ||
const pin = await ipfs.pin.remote.add(fixtures.files[0].cid, { | ||
background: true, | ||
service: SERVICE | ||
}) | ||
|
||
expect(pin).to.deep.equal({ | ||
cid: fixtures.files[0].cid, | ||
name: '', | ||
status: 'queued' | ||
}) | ||
}) | ||
|
||
it('should default to blocking pin', async () => { | ||
const { cid } = fixtures.files[0] | ||
const result = ipfs.pin.remote.add(cid, { | ||
service: SERVICE | ||
}) | ||
|
||
const timeout = {} | ||
|
||
const winner = await Promise.race([ | ||
result, | ||
new Promise(resolve => setTimeout(resolve, 100, timeout)) | ||
]) | ||
|
||
expect(winner).to.equal(timeout) | ||
|
||
// trigger status change on the mock service | ||
ipfs.pin.remote.add(cid, { | ||
service: SERVICE, | ||
name: 'pinned-block' | ||
}) | ||
|
||
expect(await result).to.deep.equal({ | ||
cid, | ||
status: 'pinned', | ||
name: '' | ||
}) | ||
}) | ||
it('should pin dag-cbor', async () => { | ||
const cid = await ipfs.dag.put({}, { | ||
format: 'dag-cbor', | ||
hashAlg: 'sha2-256' | ||
}) | ||
|
||
const pin = await ipfs.pin.remote.add(cid, { | ||
service: SERVICE, | ||
name: 'cbor-pin', | ||
background: true | ||
}) | ||
|
||
expect(pin).to.deep.equal({ | ||
cid, | ||
name: 'cbor-pin', | ||
status: 'queued' | ||
}) | ||
}) | ||
|
||
it('should pin raw', async () => { | ||
const cid = await ipfs.dag.put(new Uint8Array(0), { | ||
format: 'raw', | ||
hashAlg: 'sha2-256' | ||
}) | ||
|
||
const pin = await ipfs.pin.remote.add(cid, { | ||
service: SERVICE, | ||
background: true | ||
}) | ||
|
||
expect(pin).to.deep.equal({ | ||
cid, | ||
status: 'queued', | ||
name: '' | ||
}) | ||
}) | ||
|
||
it('should respect timeout option when pinning a block', () => { | ||
return testTimeout(() => ipfs.pin.remote.add(new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ'), { | ||
timeout: 1, | ||
service: SERVICE | ||
})) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
const { createSuite } = require('../../utils/suite') | ||
|
||
const tests = { | ||
service: require('./service'), | ||
add: require('./add'), | ||
ls: require('./ls'), | ||
rm: require('./rm'), | ||
rmAll: require('./rm-all') | ||
} | ||
|
||
module.exports = createSuite(tests) |
Oops, something went wrong.