fix channel updating
This commit is contained in:
@@ -5,12 +5,19 @@ const router = express.Router();
|
||||
// Get all voice channels
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const response = await fetch(`${req.app.locals.botUrl}/channels`);
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const response = await fetch(`${req.app.locals.botUrl}/channels`, {
|
||||
signal: controller.signal
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
|
||||
const result = await response.json();
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
req.app.locals.logger.error(`Error getting channels: ${error.message}`);
|
||||
res.status(500).json({ error: 'Failed to get channels' });
|
||||
res.status(500).json({ error: 'Failed to get channels', channels: [] });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,11 +25,17 @@ router.get('/', async (req, res) => {
|
||||
router.post('/join', async (req, res) => {
|
||||
try {
|
||||
const { channelId } = req.body;
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const response = await fetch(`${req.app.locals.botUrl}/join`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ channelId })
|
||||
body: JSON.stringify({ channelId }),
|
||||
signal: controller.signal
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -39,9 +52,15 @@ router.post('/join', async (req, res) => {
|
||||
// Disconnect from voice channel
|
||||
router.post('/disconnect', async (req, res) => {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const response = await fetch(`${req.app.locals.botUrl}/disconnect`, {
|
||||
method: 'POST'
|
||||
method: 'POST',
|
||||
signal: controller.signal
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user