Prototyping download REST API

This commit is contained in:
Chris Troutner
2024-02-04 20:35:22 -08:00
parent 10c4e7380f
commit c6c8b6418c
2 changed files with 14 additions and 0 deletions
@@ -31,6 +31,7 @@ class IpfsRESTControllerLib {
this.handleError = this.handleError.bind(this)
this.connect = this.connect.bind(this)
this.getThisNode = this.getThisNode.bind(this)
this.downloadFile = this.downloadFile.bind(this)
}
/**
@@ -123,6 +124,18 @@ class IpfsRESTControllerLib {
}
}
async downloadFile(ctx) {
try {
const {cid} = ctx.params
const file = await this.adapters.ipfs.ipfs.blockstore.get(cid)
return file
} catch(err) {
wlogger.error('Error in ipfs/controller.js/downloadFile(): ', err)
this.handleError(ctx, err)
}
}
// DRY error handler
handleError (ctx, err) {
// If an HTTP status is specified by the buisiness logic, use that.
+1
View File
@@ -56,6 +56,7 @@ class IpfsRouter {
this.router.post('/relays', this.ipfsRESTController.getRelays)
this.router.post('/connect', this.ipfsRESTController.connect)
this.router.get('/node', this.ipfsRESTController.getThisNode)
this.router.get('/download/:cid', this.ipfsRESTController.downloadFile)
// Attach the Controller routes to the Koa app.
app.use(this.router.routes())