- 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>
149 lines
No EOL
5.5 KiB
TypeScript
149 lines
No EOL
5.5 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getDatabase } from '@/lib/database';
|
|
import { TABLE_NAMES } from '@/lib/constants';
|
|
import { deleteTeamComponents, deleteStreamComponents, clearTextFilesForStream } from '@/lib/obsClient';
|
|
|
|
export async function PUT(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ teamId: string }> }
|
|
) {
|
|
try {
|
|
const { teamId: teamIdParam } = await params;
|
|
const teamId = parseInt(teamIdParam);
|
|
const body = await request.json();
|
|
const { team_name, group_name, group_uuid } = body;
|
|
|
|
// Allow updating any combination of fields
|
|
if (!team_name && group_name === undefined && group_uuid === undefined) {
|
|
return NextResponse.json({ error: 'At least one field (team_name, group_name, or group_uuid) must be provided' }, { status: 400 });
|
|
}
|
|
|
|
const db = await getDatabase();
|
|
|
|
// Build dynamic query based on what fields are being updated
|
|
const updates: string[] = [];
|
|
const values: (string | number | null)[] = [];
|
|
|
|
if (team_name) {
|
|
updates.push('team_name = ?');
|
|
values.push(team_name);
|
|
}
|
|
|
|
if (group_name !== undefined) {
|
|
updates.push('group_name = ?');
|
|
values.push(group_name);
|
|
}
|
|
|
|
if (group_uuid !== undefined) {
|
|
updates.push('group_uuid = ?');
|
|
values.push(group_uuid);
|
|
}
|
|
|
|
values.push(teamId);
|
|
|
|
const result = await db.run(
|
|
`UPDATE ${TABLE_NAMES.TEAMS} SET ${updates.join(', ')} WHERE team_id = ?`,
|
|
values
|
|
);
|
|
|
|
if (result.changes === 0) {
|
|
return NextResponse.json({ error: 'Team not found' }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({ message: 'Team updated successfully' });
|
|
} catch (error) {
|
|
console.error('Error updating team:', error);
|
|
return NextResponse.json({ error: 'Failed to update team' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ teamId: string }> }
|
|
) {
|
|
try {
|
|
const { teamId: teamIdParam } = await params;
|
|
const teamId = parseInt(teamIdParam);
|
|
const db = await getDatabase();
|
|
|
|
// First get the team and stream information before deletion
|
|
const team = await db.get(
|
|
`SELECT * FROM ${TABLE_NAMES.TEAMS} WHERE team_id = ?`,
|
|
[teamId]
|
|
);
|
|
|
|
if (!team) {
|
|
return NextResponse.json({ error: 'Team not found' }, { status: 404 });
|
|
}
|
|
|
|
// Get all streams for this team
|
|
const streams = await db.all(
|
|
`SELECT * FROM ${TABLE_NAMES.STREAMS} WHERE team_id = ?`,
|
|
[teamId]
|
|
);
|
|
|
|
console.log(`Deleting team "${team.team_name}" with ${streams.length} streams`);
|
|
|
|
// Try to clean up OBS components first
|
|
let obsCleanupResults = null;
|
|
try {
|
|
// Delete each stream's OBS components
|
|
for (const stream of streams) {
|
|
try {
|
|
const groupName = team.group_name || team.team_name;
|
|
console.log(`Deleting OBS components for stream "${stream.name}"`);
|
|
|
|
// Delete stream components
|
|
await deleteStreamComponents(stream.name, team.team_name, groupName);
|
|
|
|
// Clear any text files that reference this stream
|
|
const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_');
|
|
const cleanStreamName = stream.name.toLowerCase().replace(/\s+/g, '_');
|
|
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
|
await clearTextFilesForStream(streamGroupName);
|
|
} catch (streamError) {
|
|
console.error(`Error deleting stream "${stream.name}" OBS components:`, streamError);
|
|
}
|
|
}
|
|
|
|
// Delete team-level OBS components
|
|
obsCleanupResults = await deleteTeamComponents(team.team_name, team.group_name);
|
|
console.log('Team OBS cleanup results:', obsCleanupResults);
|
|
|
|
} catch (obsError) {
|
|
console.error('Error during OBS cleanup:', obsError);
|
|
// Continue with database deletion even if OBS cleanup fails
|
|
}
|
|
|
|
// Now delete from database
|
|
await db.run('BEGIN TRANSACTION');
|
|
|
|
try {
|
|
// Delete all streams for this team
|
|
await db.run(
|
|
`DELETE FROM ${TABLE_NAMES.STREAMS} WHERE team_id = ?`,
|
|
[teamId]
|
|
);
|
|
|
|
// Delete the team
|
|
const result = await db.run(
|
|
`DELETE FROM ${TABLE_NAMES.TEAMS} WHERE team_id = ?`,
|
|
[teamId]
|
|
);
|
|
|
|
await db.run('COMMIT');
|
|
|
|
return NextResponse.json({
|
|
message: 'Team and all associated components deleted successfully',
|
|
deletedStreams: streams.length,
|
|
obsCleanup: obsCleanupResults || 'OBS cleanup was not performed'
|
|
});
|
|
} catch (error) {
|
|
await db.run('ROLLBACK');
|
|
throw error;
|
|
}
|
|
} catch (error) {
|
|
console.error('Error deleting team:', error);
|
|
return NextResponse.json({ error: 'Failed to delete team' }, { status: 500 });
|
|
}
|
|
} |