-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (30 loc) · 1.26 KB
/
Copy pathapp.js
File metadata and controls
38 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express');
const bodyParser = require('body-parser');
const { exec } = require('child_process');
const app = express();
const PORT = 3001;
// Middleware для разбора JSON запросов
app.use(bodyParser.json());
app.post('/play', (req, res) => {
const { ip, port, username, password, file_path } = req.body;
// Проверка всех необходимых параметров
if (!ip || !port || !username || !password || !file_path) {
return res.status(400).send('Missing required fields');
}
// Формирование команды для запуска sound_player
const command = `./run_sound_player.sh ${ip} ${port} ${username} ${password} ${file_path}`;
// Запуск команды
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error.message}`);
return res.status(500).send('Command execution failed');
}
console.log(`Command output: ${stdout}`);
console.error(`Command error output: ${stderr}`);
res.send({ status: 'playing' });
});
});
// Запуск сервера
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});