send/server/routes/download.js
2020-07-29 11:02:22 -07:00

15 lines
358 B
JavaScript

const storage = require('../storage');
module.exports = async function(req, res) {
const id = req.params.id;
try {
const { length, stream } = await storage.get(id);
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': length
});
stream.pipe(res);
} catch (e) {
res.sendStatus(404);
}
};