added web sound upload

This commit is contained in:
Myx
2023-10-05 21:37:47 +02:00
parent a991164148
commit 8818de5f43
7 changed files with 1014 additions and 47 deletions

40
client/webserver.ts Normal file
View 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.`);
});
}