30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
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;
|