mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +08:00
21 lines
608 B
JavaScript
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,
|
|
};
|