You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/hydro/handler/fs.js

21 lines
608 B
JavaScript

const file = require('../model/file');
const { Route, Handler } = require('../service/server');
class FileDownloadHandler extends Handler {
async get({ id, secret, name }) {
if (name) name = Buffer.from(name, 'base64').toString();
this.response.attachment(name || id);
this.response.body = await file.get(id, secret);
}
}
async function apply() {
Route('/fs/:id/:secret', module.exports.FileDownloadHandler);
Route('/fs/:id/:name/:secret', module.exports.FileDownloadHandler);
}
global.Hydro.handler.file = module.exports = {
FileDownloadHandler,
apply,
};