openvidu-recording: Improve filtering recordings by room name and sort them by start date
This commit is contained in:
parent
4f75e00f9d
commit
1b8c20564c
@ -44,14 +44,26 @@ export class RecordingService {
|
||||
|
||||
async listRecordings(roomName, roomId) {
|
||||
const keyStart =
|
||||
RECORDINGS_PATH + RECORDINGS_METADATA_PATH + (roomName ? `${roomName}` + (roomId ? `-${roomId}` : "") : "");
|
||||
RECORDINGS_PATH + RECORDINGS_METADATA_PATH + (roomName ? `${roomName}-` + (roomId ? roomId : "") : "");
|
||||
const keyEnd = ".json";
|
||||
const regex = new RegExp(`^${keyStart}.*${keyEnd}$`);
|
||||
|
||||
// List all egress metadata files in the recordings path that match the regex
|
||||
const metadataKeys = await s3Service.listObjects(RECORDINGS_PATH + RECORDINGS_METADATA_PATH, regex);
|
||||
const recordings = await Promise.all(metadataKeys.map((metadataKey) => s3Service.getObjectAsJson(metadataKey)));
|
||||
return recordings;
|
||||
return this.filterAndSortRecordings(recordings, roomName, roomId);
|
||||
}
|
||||
|
||||
filterAndSortRecordings(recordings, roomName, roomId) {
|
||||
let filteredRecordings = recordings;
|
||||
|
||||
if (roomName || roomId) {
|
||||
filteredRecordings = recordings.filter((recording) => {
|
||||
return (!roomName || recording.roomName === roomName) && (!roomId || recording.roomId === roomId);
|
||||
});
|
||||
}
|
||||
|
||||
return filteredRecordings.sort((a, b) => b.startedAt - a.startedAt);
|
||||
}
|
||||
|
||||
async getActiveRecordingByRoom(roomName) {
|
||||
|
||||
@ -143,14 +143,15 @@ app.get("/recordings", async (req, res) => {
|
||||
const roomId = req.query.roomId?.toString();
|
||||
|
||||
try {
|
||||
const keyStart = RECORDINGS_PATH + (roomName ? `${roomName}` + (roomId ? `-${roomId}` : "") : "");
|
||||
const keyStart = RECORDINGS_PATH + (roomName ? `${roomName}-` + (roomId ? roomId : "") : "");
|
||||
const keyEnd = ".mp4.json";
|
||||
const regex = new RegExp(`^${keyStart}.*${keyEnd}$`);
|
||||
|
||||
// List all egress metadata files in the recordings path that match the regex
|
||||
const payloadKeys = await s3Service.listObjects(RECORDINGS_PATH, regex);
|
||||
const recordings = await Promise.all(payloadKeys.map((payloadKey) => getRecordingInfo(payloadKey)));
|
||||
res.json({ recordings });
|
||||
const sortedRecordings = filterAndSortRecordings(recordings, roomName, roomId);
|
||||
res.json({ recordings: sortedRecordings });
|
||||
} catch (error) {
|
||||
console.error("Error listing recordings.", error);
|
||||
res.status(500).json({ errorMessage: "Error listing recordings" });
|
||||
@ -167,13 +168,28 @@ const getRecordingInfo = async (payloadKey) => {
|
||||
|
||||
const recordingName = recordingKey.split("/").pop();
|
||||
const recording = {
|
||||
id: data.egress_id,
|
||||
name: recordingName,
|
||||
roomName: data.room_name,
|
||||
roomId: data.room_id,
|
||||
startedAt: Number(data.started_at) / 1000000,
|
||||
size: size
|
||||
};
|
||||
return recording;
|
||||
};
|
||||
|
||||
const filterAndSortRecordings = (recordings, roomName, roomId) => {
|
||||
let filteredRecordings = recordings;
|
||||
|
||||
if (roomName || roomId) {
|
||||
filteredRecordings = recordings.filter((recording) => {
|
||||
return (!roomName || recording.roomName === roomName) && (!roomId || recording.roomId === roomId);
|
||||
});
|
||||
}
|
||||
|
||||
return filteredRecordings.sort((a, b) => b.startedAt - a.startedAt);
|
||||
};
|
||||
|
||||
app.get("/recordings/:recordingName", async (req, res) => {
|
||||
const { recordingName } = req.params;
|
||||
const { range } = req.headers;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user