mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
25 lines
700 B
JavaScript
25 lines
700 B
JavaScript
import mimetypes from "mime-types"
|
|
|
|
export default {
|
|
useContext: ["storage"],
|
|
fn: async (req, res) => {
|
|
const streamPath = req.path.replace(req.route.pattern.replace("*", ""), "/")
|
|
|
|
this.default.contexts.storage.getObject(process.env.S3_BUCKET, streamPath, (err, dataStream) => {
|
|
if (err) {
|
|
return res.status(404).end()
|
|
}
|
|
|
|
const extname = mimetypes.lookup(streamPath)
|
|
|
|
// send chunked response
|
|
res.status(200)
|
|
|
|
// set headers
|
|
res.setHeader("Content-Type", extname)
|
|
res.setHeader("Accept-Ranges", "bytes")
|
|
|
|
return dataStream.pipe(res)
|
|
})
|
|
}
|
|
} |