Skip to content
Snippets Groups Projects
Commit 4069497b authored by Sebastian's avatar Sebastian
Browse files

restified api calls

parent a46bf4e0
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,11 @@ require('dotenv').config()
```
# `xpub-aws` API
A list of endpoints that help you upload, download and delete S3 files.\
A list of endpoints that help you upload, download and delete S3 files.
## Upload a file [POST]
#### Request
`POST /api/aws-upload`
`POST /api/aws`
#### Request body
```
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ
......@@ -48,11 +48,11 @@ Content-Type: text/plain
"size": 452097
}
```
---
## Retrieve file signed URL [GET]
This endpoint allows you to retrieve a file's signed URL that can be used to download the file.
#### Request
`GET /api/aws-signed-url/{fragmentId}/{fileId}`
`GET /api/aws/{fragmentId}/{fileId}`
| URI Parameter | Requiered | Requirements | Description |
| -------- | -------- | -------- | -------- |
......@@ -66,10 +66,10 @@ HTTP/1.1 200
"signedUrl": "aws-url"
}
```
---
## Delete file [DELETE]
#### Request
`DELETE /api/aws-delete/{fragmentId}/{fileId}`
`DELETE /api/aws/{fragmentId}/{fileId}`
| URI Parameter | Requiered | Requirements | Description |
| -------- | -------- | -------- | -------- |
......
......@@ -45,59 +45,46 @@ const AWSBackend = app => {
return cb(null, true)
},
})
app.post(
'/api/aws-upload',
authBearer,
upload.single('file'),
async (req, res) => {
if (req.fileValidationError !== undefined) {
return res.status(400).json({ error: req.fileValidationError })
}
app.post('/api/aws', authBearer, upload.single('file'), async (req, res) => {
if (req.fileValidationError !== undefined) {
return res.status(400).json({ error: req.fileValidationError })
}
res.status(200).json({
id: req.file.key,
name: req.file.originalname,
size: req.file.size,
})
},
)
app.get(
'/api/aws-signed-url/:fragmentId/:fileId',
authBearer,
async (req, res) => {
const params = {
Bucket: process.env.AWS_BUCKET,
Key: `${req.params.fragmentId}${req.params.fileId}`,
}
res.status(200).json({
id: req.file.key,
name: req.file.originalname,
size: req.file.size,
})
})
app.get('/api/aws/:fragmentId/:fileId', authBearer, async (req, res) => {
const params = {
Bucket: process.env.AWS_BUCKET,
Key: `${req.params.fragmentId}${req.params.fileId}`,
}
s3.getSignedUrl('getObject', params, (err, data) => {
if (err) {
res.status(err.statusCode).json({ error: err.message })
return
}
res.status(200).json({
signedUrl: data,
})
})
},
)
app.delete(
'/api/aws-delete/:fragmentId/:fileId',
authBearer,
async (req, res) => {
const params = {
Bucket: process.env.AWS_BUCKET,
Key: `${req.params.fragmentId}${req.params.fileId}`,
s3.getSignedUrl('getObject', params, (err, data) => {
if (err) {
res.status(err.statusCode).json({ error: err.message })
return
}
s3.deleteObject(params, (err, data) => {
if (err) {
res.status(err.statusCode).json({ error: err.message })
return
}
res.status(204).json()
res.status(200).json({
signedUrl: data,
})
},
)
})
})
app.delete('/api/aws/:fragmentId/:fileId', authBearer, async (req, res) => {
const params = {
Bucket: process.env.AWS_BUCKET,
Key: `${req.params.fragmentId}${req.params.fileId}`,
}
s3.deleteObject(params, (err, data) => {
if (err) {
res.status(err.statusCode).json({ error: err.message })
return
}
res.status(204).json()
})
})
}
module.exports = AWSBackend
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment