- Changed branding from "OBS Stream Manager" to "Live Stream Manager" throughout UI - Enhanced stream deletion with comprehensive OBS cleanup: - Removes stream's nested scene - Deletes browser source - Clears text files referencing the stream - Removes stream from all source switchers - Enhanced team deletion to clean up all OBS components: - Deletes team scene/group - Removes team text source - Deletes all associated stream scenes and sources - Clears all related text files - Fixed stream selection to use proper team-prefixed names in text files - Added StreamWithTeam type for proper team data handling - Improved browser source creation with audio controls: - Enabled "Control Audio via OBS" setting - Auto-mutes audio on creation - Attempted multiple approaches to fix text centering (still unresolved) Known issue: Text centering still positions left edge at center despite multiple attempts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { FILE_DIRECTORY } from '../../../config';
|
|
import { getDatabase } from '../../../lib/database';
|
|
import { StreamWithTeam } from '@/types';
|
|
import { validateScreenInput } from '../../../lib/security';
|
|
import { TABLE_NAMES } from '../../../lib/constants';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
// Parse and validate request body
|
|
try {
|
|
const body = await request.json();
|
|
const validation = validateScreenInput(body);
|
|
|
|
if (!validation.valid) {
|
|
return NextResponse.json({
|
|
error: 'Validation failed',
|
|
details: validation.errors
|
|
}, { status: 400 });
|
|
}
|
|
|
|
const { screen, id } = validation.data!;
|
|
|
|
console.log('Writing files to', path.join(FILE_DIRECTORY(), `${screen}.txt`));
|
|
const filePath = path.join(FILE_DIRECTORY(), `${screen}.txt`);
|
|
|
|
try {
|
|
const db = await getDatabase();
|
|
const stream: StreamWithTeam | undefined = await db.get<StreamWithTeam>(
|
|
`SELECT s.*, t.team_name, t.group_name
|
|
FROM ${TABLE_NAMES.STREAMS} s
|
|
LEFT JOIN ${TABLE_NAMES.TEAMS} t ON s.team_id = t.team_id
|
|
WHERE s.id = ?`,
|
|
[id]
|
|
);
|
|
|
|
console.log('Stream:', stream);
|
|
|
|
if (!stream) {
|
|
return NextResponse.json({ error: 'Stream not found' }, { status: 400 });
|
|
}
|
|
|
|
// Construct proper stream group name with team prefix
|
|
const groupName = stream.group_name || stream.team_name;
|
|
const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_');
|
|
const cleanStreamName = stream.name.toLowerCase().replace(/\s+/g, '_');
|
|
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
|
fs.writeFileSync(filePath, streamGroupName);
|
|
return NextResponse.json({ message: `${screen} updated successfully.` }, { status: 200 });
|
|
} catch (error) {
|
|
console.error('Error updating active source:', error);
|
|
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred';
|
|
return NextResponse.json(
|
|
{ error: 'Failed to update active source', details: errorMessage },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid JSON in request body' }, { status: 400 });
|
|
}
|
|
}
|