first attempt at code mostly working
This commit is contained in:
39
api/src/routes/channels.js
Normal file
39
api/src/routes/channels.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import express from 'express';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Get all voice channels
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const response = await fetch(`${req.app.locals.botUrl}/channels`);
|
||||
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' });
|
||||
}
|
||||
});
|
||||
|
||||
// Join a voice channel
|
||||
router.post('/join', async (req, res) => {
|
||||
try {
|
||||
const { channelId } = req.body;
|
||||
const response = await fetch(`${req.app.locals.botUrl}/join`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ channelId })
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
req.app.locals.broadcast('channelChange', { channelId, channelName: result.channelName });
|
||||
}
|
||||
|
||||
res.status(response.status).json(result);
|
||||
} catch (error) {
|
||||
req.app.locals.logger.error(`Error joining channel: ${error.message}`);
|
||||
res.status(500).json({ error: 'Failed to join channel' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user