From 803c51c18eda5e3b1103306c059f36080ce74f4e Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 19 May 2020 15:14:12 -0700 Subject: [PATCH 1/3] feat(buckets): add bucket.links Signed-off-by: andrew --- src/buckets.spec.ts | 9 +++++++++ src/buckets.ts | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/buckets.spec.ts b/src/buckets.spec.ts index c95b85196..92a519c67 100644 --- a/src/buckets.spec.ts +++ b/src/buckets.spec.ts @@ -135,6 +135,15 @@ describe('Buckets...', () => { expect(rep.item?.isdir).to.be.false }) + it('should list bucket links', async () => { + const rootKey = buck.root?.key || '' + + const rep = await client.links(rootKey) + expect(rep.url).to.not.equal('') + expect(rep.www).to.not.equal('') + expect(rep.ipns).to.not.equal('') + }) + it('should pull files by path and write to file on node', async function () { if (isBrowser) return this.skip() // Bucket path diff --git a/src/buckets.ts b/src/buckets.ts index 04c90c537..749861a51 100644 --- a/src/buckets.ts +++ b/src/buckets.ts @@ -61,6 +61,19 @@ export class Buckets { return res.toObject().rootsList } + /** + * Returns a list of bucket links. + * @param key Unique (IPNS compatible) identifier key for a bucket. + * @param ctx Context object containing web-gRPC headers and settings. + */ + async links(key: string, ctx?: Context) { + logger.debug('link request') + const req = new pb.LinksRequest() + req.setKey(key) + const res: pb.LinksReply = await this.unary(API.Links, req, ctx) + return res.toObject() + } + /** * Returns information about a bucket path. * @param key Unique (IPNS compatible) identifier key for a bucket. From c19268e0ed5ad096634ef62a1d912f348962ec5f Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 19 May 2020 15:28:58 -0700 Subject: [PATCH 2/3] fix(tests): no www string in tests Signed-off-by: andrew --- src/buckets.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/buckets.spec.ts b/src/buckets.spec.ts index 92a519c67..f86985db8 100644 --- a/src/buckets.spec.ts +++ b/src/buckets.spec.ts @@ -140,7 +140,6 @@ describe('Buckets...', () => { const rep = await client.links(rootKey) expect(rep.url).to.not.equal('') - expect(rep.www).to.not.equal('') expect(rep.ipns).to.not.equal('') }) From e354b47e374983ea8d3eaac9f144fb2cb29a3f63 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 19 May 2020 15:35:52 -0700 Subject: [PATCH 3/3] fix(tests): check links right before delete Signed-off-by: andrew --- src/buckets.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/buckets.spec.ts b/src/buckets.spec.ts index f86985db8..75492ba61 100644 --- a/src/buckets.spec.ts +++ b/src/buckets.spec.ts @@ -135,14 +135,6 @@ describe('Buckets...', () => { expect(rep.item?.isdir).to.be.false }) - it('should list bucket links', async () => { - const rootKey = buck.root?.key || '' - - const rep = await client.links(rootKey) - expect(rep.url).to.not.equal('') - expect(rep.ipns).to.not.equal('') - }) - it('should pull files by path and write to file on node', async function () { if (isBrowser) return this.skip() // Bucket path @@ -188,6 +180,14 @@ describe('Buckets...', () => { expect(list.item?.itemsList).to.have.length(1) }) + it('should list bucket links', async () => { + const rootKey = buck.root?.key || '' + + const rep = await client.links(rootKey) + expect(rep.url).to.not.equal('') + expect(rep.ipns).to.not.equal('') + }) + it('should remove an entire bucket', async () => { const rootKey = buck.root?.key || '' const rep = await client.listPath(rootKey, 'dir1/file1.jpg')