From 0390f2d956d12168ddb46660ce4afc40b2552238 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 12 Apr 2024 08:30:14 -0700 Subject: [PATCH 1/3] fix(helia-coord): Updating to v1.5.7 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d4328f..910f0f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "datastore-fs": "9.1.6", "glob": "7.1.6", "helia": "2.1.0", - "helia-coord": "1.5.6", + "helia-coord": "1.5.7", "jsonrpc-lite": "2.2.0", "jsonwebtoken": "8.5.1", "jwt-bch-lib": "1.3.0", @@ -11533,9 +11533,9 @@ } }, "node_modules/helia-coord": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/helia-coord/-/helia-coord-1.5.6.tgz", - "integrity": "sha512-sh7rEiw883aPsIMZ4vxbzA6OKQjuhz4vlIRoaNWJruju1mJY4hrn9BFPrtJ96KN054zZ0EwziVdTxD9vPV4bSQ==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/helia-coord/-/helia-coord-1.5.7.tgz", + "integrity": "sha512-S3untLIDr4A15bUw+dUmLHfqSNmJ9wjqENPzdqHjEP9HSUs7w+CtVNrvY3MSXTD+/nwTtUX5V4NiTdMXdWlBAA==", "dependencies": { "@chris.troutner/retry-queue": "1.0.8", "bch-encrypt-lib": "2.1.1", @@ -33949,9 +33949,9 @@ } }, "helia-coord": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/helia-coord/-/helia-coord-1.5.6.tgz", - "integrity": "sha512-sh7rEiw883aPsIMZ4vxbzA6OKQjuhz4vlIRoaNWJruju1mJY4hrn9BFPrtJ96KN054zZ0EwziVdTxD9vPV4bSQ==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/helia-coord/-/helia-coord-1.5.7.tgz", + "integrity": "sha512-S3untLIDr4A15bUw+dUmLHfqSNmJ9wjqENPzdqHjEP9HSUs7w+CtVNrvY3MSXTD+/nwTtUX5V4NiTdMXdWlBAA==", "requires": { "@chris.troutner/retry-queue": "1.0.8", "bch-encrypt-lib": "2.1.1", diff --git a/package.json b/package.json index 55c1215..07e3362 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "datastore-fs": "9.1.6", "glob": "7.1.6", "helia": "2.1.0", - "helia-coord": "1.5.6", + "helia-coord": "1.5.7", "jsonrpc-lite": "2.2.0", "jsonwebtoken": "8.5.1", "jwt-bch-lib": "1.3.0", From e3e928b33df513216c12d8bcef115dba36a5a867 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 12 Apr 2024 08:34:39 -0700 Subject: [PATCH 2/3] Adding getPins endpoint for File Pin Service --- src/adapters/ipfs-files/index.js | 42 +++++++++++++++++++++ src/controllers/rest-api/ipfs/controller.js | 29 ++++++++++++++ src/controllers/rest-api/ipfs/index.js | 1 + 3 files changed, 72 insertions(+) diff --git a/src/adapters/ipfs-files/index.js b/src/adapters/ipfs-files/index.js index bc1e92a..e6d912d 100644 --- a/src/adapters/ipfs-files/index.js +++ b/src/adapters/ipfs-files/index.js @@ -176,6 +176,48 @@ class IpfsFilesAdapter { } } + // Get an array of the latest 20 pinned files. + async getPins (inObj = {}) { + try { + // Throw an error if this IPFS node has not yet made a connection to a + // wallet service provider. + const selectedProvider = + this.ipfs.ipfsCoordAdapter.state.selectedIpfsFileProvider + if (!selectedProvider) { + throw new Error('No IPFS File Pin Service provider available yet.') + } + + const rpcData = { + endpoint: 'getPins' + } + + // Generate a UUID for the call. + const rpcId = this.uid() + + // Generate a JSON RPC command. + const cmd = this.jsonrpc.request(rpcId, 'file-pin', rpcData) + const cmdStr = JSON.stringify(cmd) + // console.log('cmdStr: ', cmdStr) + + // Send the RPC command to selected wallet service. + const thisNode = this.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode + await this.ipfs.ipfsCoordAdapter.ipfsCoord.useCases.peer.sendPrivateMessage( + selectedProvider, + cmdStr, + thisNode + ) + + // Wait for data to come back from the wallet service. + const data = await this.waitForRPCResponse(rpcId) + // console.log('getFileMetadata() data: ', data) + + return data + } catch (err) { + wlogger.error('Error in adapters/files/getPins()') + throw err + } + } + // Returns a promise that resolves to data when the RPC response is recieved. async waitForRPCResponse (rpcId) { try { diff --git a/src/controllers/rest-api/ipfs/controller.js b/src/controllers/rest-api/ipfs/controller.js index 90227c9..af45bb8 100644 --- a/src/controllers/rest-api/ipfs/controller.js +++ b/src/controllers/rest-api/ipfs/controller.js @@ -38,6 +38,7 @@ class IpfsRESTControllerLib { this.viewFile = this.viewFile.bind(this) this.getService = this.getService.bind(this) this.getFileInfo = this.getFileInfo.bind(this) + this.getPins = this.getPins.bind(this) } /** @@ -224,6 +225,34 @@ class IpfsRESTControllerLib { } } + /** + * @api {get} /ipfs/pins Get info on latest 20 pinned files + * @apiPermission public + * @apiName GetPins + * @apiGroup REST IPFS + * @apiDescription Returns an array of the latest 20 pinned files. + * + * @apiExample Example usage: + * curl -H "Content-Type: application/json" -X GET localhost:5015/ipfs/pins + * + */ + async getPins (ctx) { + try { + // const { cid } = ctx.params + + const ipfsFiles = this.adapters.ipfsFiles + + const pinData = await ipfsFiles.getPins() + console.log('getPins() pinData: ', pinData) + + ctx.body = pinData + } catch (err) { + // wlogger.error('Error in ipfs/controller.js/viewFile(): ', err) + console.log('Error in ipfs/controller.js/getPins(): ', err) + this.handleError(ctx, err) + } + } + // DRY error handler handleError (ctx, err) { // If an HTTP status is specified by the buisiness logic, use that. diff --git a/src/controllers/rest-api/ipfs/index.js b/src/controllers/rest-api/ipfs/index.js index 6c602a9..645ffef 100644 --- a/src/controllers/rest-api/ipfs/index.js +++ b/src/controllers/rest-api/ipfs/index.js @@ -59,6 +59,7 @@ class IpfsRouter { this.router.get('/view/:cid', this.ipfsRESTController.viewFile) this.router.get('/service', this.ipfsRESTController.getService) this.router.get('/file-info/:cid', this.ipfsRESTController.getFileInfo) + this.router.get('/pins', this.ipfsRESTController.getPins) // Attach the Controller routes to the Koa app. app.use(this.router.routes()) From 0ca46df43e1e0a9d3c40a3e58b25a6ec9e618bd2 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 12 Apr 2024 10:44:03 -0700 Subject: [PATCH 3/3] fix(getPins): Adding getPins endpoint for File Pin Service --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index e3aeb99..09d5c7a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,5 +1,5 @@ The MIT License (MIT) -Copyright (c) 2021-2023 Permissionless Software Foundation +Copyright (c) 2021-2024 Permissionless Software Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: