Added cron job, updated webserver, added retry functionality

This commit is contained in:
Myx
2023-10-13 02:42:04 +02:00
parent e3f9dc2899
commit d25d2c8f54
7 changed files with 219 additions and 31 deletions

View File

@@ -30,6 +30,29 @@ app.post('/upload', upload.single('myFile'), async (req, res) => {
res.send('File uploaded successfully.');
});
app.get('/sounds', (_req, res) => {
const fs = require('fs');
const directoryPath = path.join(__dirname, '../sounds');
fs.readdir(directoryPath, function (err: any, files: any[]) {
if (err) {
return console.log(LoggerColors.Red, 'Unable to scan directory: ' + err);
}
res.send(files);
});
});
app.delete('/sounds/:filename', (req, res) => {
const fs = require('fs');
const directoryPath = path.join(__dirname, '../sounds');
const filePath = directoryPath + '/' + req.params.filename;
fs.unlink(filePath, (err: any) => {
if (err) {
return console.log(LoggerColors.Red, 'Unable to delete file: ' + err);
}
res.send('File deleted successfully.');
});
});
app.use(express.static(path.join(__dirname, "web")));
export function startServer() {
@@ -37,4 +60,4 @@ export function startServer() {
app.listen(port, () => {
console.log(LoggerColors.Cyan,`Add sounds at http://localhost:${port}, or drop in the sounds folder.`);
});
}
}