arbitrary file sharing
This commit is contained in:
parent
c4630633b8
commit
46ecdd5c38
1
server/.gitignore
vendored
1
server/.gitignore
vendored
@ -2,6 +2,7 @@ node_modules
|
||||
logs
|
||||
media
|
||||
thumbnails
|
||||
files
|
||||
|
||||
clipIndex.json
|
||||
.env
|
38
server/src/client/endpoints/api/Files.js
Normal file
38
server/src/client/endpoints/api/Files.js
Normal file
@ -0,0 +1,38 @@
|
||||
// Endpoint for hosting arbitrary files
|
||||
const { APIEndpoint } = require('../../interfaces');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class FilesEndpoint extends APIEndpoint {
|
||||
|
||||
constructor(client, opts) {
|
||||
super(client, {
|
||||
name: 'files',
|
||||
path: '/files/:filename',
|
||||
...opts
|
||||
});
|
||||
|
||||
this.methods = [
|
||||
['get', this.get.bind(this)]
|
||||
];
|
||||
|
||||
this.init();
|
||||
|
||||
}
|
||||
|
||||
async get(req, res) {
|
||||
|
||||
const { filename } = req.params;
|
||||
const _path = path.join(process.cwd(), 'files');
|
||||
if (!fs.existsSync(_path)) return res.status(500).send('File serving not set up');
|
||||
|
||||
const files = fs.readdirSync(_path);
|
||||
if (!filename || !files.includes(filename)) return res.status(404).end();
|
||||
|
||||
res.sendFile(`${filename}`, { root: _path });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = FilesEndpoint;
|
Loading…
Reference in New Issue
Block a user