This commit is contained in:
120
server/routes/recordings.js
Normal file
120
server/routes/recordings.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import { Router } from 'express';
|
||||
import { authenticateToken } from '../middleware/auth.js';
|
||||
import { getDb } from '../config/database.js';
|
||||
import {
|
||||
getRecordings,
|
||||
deleteRecording,
|
||||
publishRecording,
|
||||
} from '../config/bbb.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /api/recordings - Get recordings for a room (by meetingID/uid)
|
||||
router.get('/', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { meetingID } = req.query;
|
||||
const recordings = await getRecordings(meetingID || undefined);
|
||||
|
||||
// Format recordings
|
||||
const formatted = recordings.map(rec => {
|
||||
const playback = rec.playback?.format;
|
||||
let formats = [];
|
||||
if (playback) {
|
||||
formats = Array.isArray(playback) ? playback : [playback];
|
||||
}
|
||||
|
||||
return {
|
||||
recordID: rec.recordID,
|
||||
meetingID: rec.meetingID,
|
||||
name: rec.name || 'Aufnahme',
|
||||
state: rec.state,
|
||||
published: rec.published === 'true',
|
||||
startTime: rec.startTime,
|
||||
endTime: rec.endTime,
|
||||
participants: rec.participants,
|
||||
size: rec.size,
|
||||
formats: formats.map(f => ({
|
||||
type: f.type,
|
||||
url: f.url,
|
||||
length: f.length,
|
||||
size: f.size,
|
||||
})),
|
||||
metadata: rec.metadata || {},
|
||||
};
|
||||
});
|
||||
|
||||
res.json({ recordings: formatted });
|
||||
} catch (err) {
|
||||
console.error('Get recordings error:', err);
|
||||
res.status(500).json({ error: 'Aufnahmen konnten nicht geladen werden', recordings: [] });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/recordings/room/:uid - Get recordings for a specific room
|
||||
router.get('/room/:uid', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const db = getDb();
|
||||
const room = await db.get('SELECT * FROM rooms WHERE uid = ?', [req.params.uid]);
|
||||
|
||||
if (!room) {
|
||||
return res.status(404).json({ error: 'Raum nicht gefunden' });
|
||||
}
|
||||
|
||||
const recordings = await getRecordings(room.uid);
|
||||
const formatted = recordings.map(rec => {
|
||||
const playback = rec.playback?.format;
|
||||
let formats = [];
|
||||
if (playback) {
|
||||
formats = Array.isArray(playback) ? playback : [playback];
|
||||
}
|
||||
|
||||
return {
|
||||
recordID: rec.recordID,
|
||||
meetingID: rec.meetingID,
|
||||
name: rec.name || room.name,
|
||||
state: rec.state,
|
||||
published: rec.published === 'true',
|
||||
startTime: rec.startTime,
|
||||
endTime: rec.endTime,
|
||||
participants: rec.participants,
|
||||
size: rec.size,
|
||||
formats: formats.map(f => ({
|
||||
type: f.type,
|
||||
url: f.url,
|
||||
length: f.length,
|
||||
size: f.size,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
res.json({ recordings: formatted });
|
||||
} catch (err) {
|
||||
console.error('Get room recordings error:', err);
|
||||
res.status(500).json({ error: 'Aufnahmen konnten nicht geladen werden', recordings: [] });
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/recordings/:recordID
|
||||
router.delete('/:recordID', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
await deleteRecording(req.params.recordID);
|
||||
res.json({ message: 'Aufnahme gelöscht' });
|
||||
} catch (err) {
|
||||
console.error('Delete recording error:', err);
|
||||
res.status(500).json({ error: 'Aufnahme konnte nicht gelöscht werden' });
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/recordings/:recordID/publish
|
||||
router.put('/:recordID/publish', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { publish } = req.body;
|
||||
await publishRecording(req.params.recordID, publish);
|
||||
res.json({ message: publish ? 'Aufnahme veröffentlicht' : 'Aufnahme nicht mehr öffentlich' });
|
||||
} catch (err) {
|
||||
console.error('Publish recording error:', err);
|
||||
res.status(500).json({ error: 'Aufnahme konnte nicht aktualisiert werden' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user