mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-07-09 06:25:08 +00:00
added web sound upload
This commit is contained in:
40
client/webserver.ts
Normal file
40
client/webserver.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import express from 'express';
|
||||
import multer, { diskStorage } from 'multer';
|
||||
import path from 'path';
|
||||
import { LoggerColors } from '../bot';
|
||||
|
||||
const app = express();
|
||||
const storage = diskStorage({
|
||||
destination: 'sounds/',
|
||||
filename: function (_req, file, cb) {
|
||||
cb(null, Date.now() + '-' + file.originalname);
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
limits: { fileSize: 1 * 1024 * 1024 },
|
||||
fileFilter: function (_req, file, cb) {
|
||||
if (path.extname(file.originalname) !== '.mp3') {
|
||||
return cb(new Error('Only .mp3 files are allowed'));
|
||||
}
|
||||
cb(null, true);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/', (_req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'web/index.html'));
|
||||
});
|
||||
|
||||
app.post('/upload', upload.single('myFile'), async (req, res) => {
|
||||
res.send('File uploaded successfully.');
|
||||
});
|
||||
|
||||
app.use(express.static(path.join(__dirname, "web")));
|
||||
|
||||
export function startServer() {
|
||||
const port = 8080;
|
||||
app.listen(port, () => {
|
||||
console.log(LoggerColors.Cyan,`Add sounds at http://localhost:${port}, or drop in the sounds folder.`);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user