refactor(backend): split stream routes into focused modules
This commit is contained in:
29
Backend/routes/streams/shared.ts
Normal file
29
Backend/routes/streams/shared.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Request, Response } from 'express';
|
||||
import { and, eq } from 'drizzle-orm';
|
||||
|
||||
import { db } from '../../db/client';
|
||||
import { streamSessions } from '../../db/schema';
|
||||
import { mediaMode, streamRecordingEnabled } from '../../media/config';
|
||||
|
||||
export const ensureStreamDeviceAuth = (req: Request, res: Response) => {
|
||||
const deviceAuth = req.deviceAuth;
|
||||
|
||||
if (!deviceAuth) {
|
||||
res.status(401).json({ message: 'Unauthorized' });
|
||||
return null;
|
||||
}
|
||||
|
||||
return deviceAuth;
|
||||
};
|
||||
|
||||
export const getOwnedStreamSession = async (streamSessionId: string, ownerUserId: string) =>
|
||||
await db.query.streamSessions.findFirst({
|
||||
where: and(eq(streamSessions.id, streamSessionId), eq(streamSessions.ownerUserId, ownerUserId)),
|
||||
});
|
||||
|
||||
export const isStreamParticipant = (
|
||||
session: { requesterDeviceId: string; cameraDeviceId: string },
|
||||
deviceId: string,
|
||||
): boolean => session.requesterDeviceId === deviceId || session.cameraDeviceId === deviceId;
|
||||
|
||||
export const shouldCreateRecordingPlaceholder = (): boolean => mediaMode === 'legacy' || streamRecordingEnabled;
|
||||
Reference in New Issue
Block a user