text-background-color-source #8
5 changed files with 66 additions and 70 deletions
|
@ -4,7 +4,7 @@ import { connectToOBS, getOBSClient, disconnectFromOBS, addSourceToSwitcher, cre
|
||||||
import { open } from 'sqlite';
|
import { open } from 'sqlite';
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { getTableName, BASE_TABLE_NAMES } from '../../../lib/constants';
|
import { getTableName, BASE_TABLE_NAMES, SOURCE_SWITCHER_NAMES } from '../../../lib/constants';
|
||||||
|
|
||||||
interface OBSClient {
|
interface OBSClient {
|
||||||
call: (method: string, params?: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
call: (method: string, params?: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
||||||
|
@ -18,15 +18,7 @@ inputName: string;
|
||||||
interface GetInputListResponse {
|
interface GetInputListResponse {
|
||||||
inputs: OBSInput[];
|
inputs: OBSInput[];
|
||||||
}
|
}
|
||||||
const screens = [
|
const screens = SOURCE_SWITCHER_NAMES;
|
||||||
'ss_large',
|
|
||||||
'ss_left',
|
|
||||||
'ss_right',
|
|
||||||
'ss_top_left',
|
|
||||||
'ss_top_right',
|
|
||||||
'ss_bottom_left',
|
|
||||||
'ss_bottom_right',
|
|
||||||
];
|
|
||||||
|
|
||||||
async function fetchTeamInfo(teamId: number) {
|
async function fetchTeamInfo(teamId: number) {
|
||||||
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files');
|
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files');
|
||||||
|
|
|
@ -1,38 +1,32 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import { getDatabase } from '../../../lib/database';
|
import { getDatabase } from '../../../lib/database';
|
||||||
|
import { TABLE_NAMES } from '../../../lib/constants';
|
||||||
|
import { createErrorResponse, createSuccessResponse, createDatabaseError, withErrorHandling } from '../../../lib/apiHelpers';
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
async function getTeamNameHandler(request: NextRequest) {
|
||||||
try {
|
|
||||||
// Extract the team_id from the query string
|
// Extract the team_id from the query string
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const teamId = searchParams.get('team_id');
|
const teamId = searchParams.get('team_id');
|
||||||
|
|
||||||
if (!teamId) {
|
if (!teamId) {
|
||||||
return NextResponse.json(
|
return createErrorResponse('Missing team_id', 400, 'team_id parameter is required');
|
||||||
{ error: 'Missing team_id' },
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const db = await getDatabase();
|
const db = await getDatabase();
|
||||||
const team = await db.get(
|
const team = await db.get(
|
||||||
'SELECT team_name FROM teams_2025_spring_adr WHERE team_id = ?',
|
`SELECT team_name FROM ${TABLE_NAMES.TEAMS} WHERE team_id = ?`,
|
||||||
[teamId]
|
[teamId]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!team) {
|
if (!team) {
|
||||||
return NextResponse.json(
|
return createErrorResponse('Team not found', 404, `No team found with ID: ${teamId}`);
|
||||||
{ error: 'Team not found' },
|
|
||||||
{ status: 404 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ team_name: team.team_name });
|
return createSuccessResponse({ team_name: team.team_name });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching team name:', error instanceof Error ? error.message : String(error));
|
return createDatabaseError('fetch team name', error);
|
||||||
return NextResponse.json(
|
|
||||||
{ error: 'Failed to fetch team name' },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const GET = withErrorHandling(getTeamNameHandler);
|
||||||
|
|
|
@ -2,17 +2,16 @@ import { NextResponse } from 'next/server';
|
||||||
import { getDatabase } from '../../../lib/database';
|
import { getDatabase } from '../../../lib/database';
|
||||||
import { Stream } from '@/types';
|
import { Stream } from '@/types';
|
||||||
import { TABLE_NAMES } from '../../../lib/constants';
|
import { TABLE_NAMES } from '../../../lib/constants';
|
||||||
|
import { createSuccessResponse, createDatabaseError, withErrorHandling } from '../../../lib/apiHelpers';
|
||||||
|
|
||||||
export async function GET() {
|
async function getStreamsHandler() {
|
||||||
try {
|
try {
|
||||||
const db = await getDatabase();
|
const db = await getDatabase();
|
||||||
const streams: Stream[] = await db.all(`SELECT * FROM ${TABLE_NAMES.STREAMS}`);
|
const streams: Stream[] = await db.all(`SELECT * FROM ${TABLE_NAMES.STREAMS}`);
|
||||||
return NextResponse.json(streams);
|
return createSuccessResponse(streams);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching streams:', error);
|
return createDatabaseError('fetch streams', error);
|
||||||
return NextResponse.json(
|
}
|
||||||
{ error: 'Failed to fetch streams' },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const GET = withErrorHandling(getStreamsHandler);
|
||||||
|
|
|
@ -40,3 +40,29 @@ export const TABLE_NAMES = {
|
||||||
TEAMS: getTableName(BASE_TABLE_NAMES.TEAMS),
|
TEAMS: getTableName(BASE_TABLE_NAMES.TEAMS),
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
// Screen position constants
|
||||||
|
export const SCREEN_POSITIONS = [
|
||||||
|
'large',
|
||||||
|
'left',
|
||||||
|
'right',
|
||||||
|
'topLeft',
|
||||||
|
'topRight',
|
||||||
|
'bottomLeft',
|
||||||
|
'bottomRight'
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const SOURCE_SWITCHER_NAMES = [
|
||||||
|
'ss_large',
|
||||||
|
'ss_left',
|
||||||
|
'ss_right',
|
||||||
|
'ss_top_left',
|
||||||
|
'ss_top_right',
|
||||||
|
'ss_bottom_left',
|
||||||
|
'ss_bottom_right'
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
// OBS utility functions
|
||||||
|
export function cleanObsName(name: string): string {
|
||||||
|
return name.toLowerCase().replace(/\s+/g, '_');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const { OBSWebSocket } = require('obs-websocket-js');
|
const { OBSWebSocket } = require('obs-websocket-js');
|
||||||
|
const { cleanObsName, SOURCE_SWITCHER_NAMES, SCREEN_POSITIONS } = require('./constants');
|
||||||
|
|
||||||
let obs = null;
|
let obs = null;
|
||||||
let isConnecting = false;
|
let isConnecting = false;
|
||||||
|
@ -383,11 +384,11 @@ async function createStreamGroup(groupName, streamName, teamName, url) {
|
||||||
// Ensure team scene exists
|
// Ensure team scene exists
|
||||||
await createGroupIfNotExists(groupName);
|
await createGroupIfNotExists(groupName);
|
||||||
|
|
||||||
const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_');
|
const cleanGroupName = cleanObsName(groupName);
|
||||||
const cleanStreamName = streamName.toLowerCase().replace(/\s+/g, '_');
|
const cleanStreamName = cleanObsName(streamName);
|
||||||
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
||||||
const sourceName = `${cleanGroupName}_${cleanStreamName}`;
|
const sourceName = `${cleanGroupName}_${cleanStreamName}`;
|
||||||
const textSourceName = teamName.toLowerCase().replace(/\s+/g, '_') + '_text';
|
const textSourceName = cleanObsName(teamName) + '_text';
|
||||||
|
|
||||||
// Create a nested scene for this stream (acts as a group)
|
// Create a nested scene for this stream (acts as a group)
|
||||||
try {
|
try {
|
||||||
|
@ -594,11 +595,11 @@ async function deleteStreamComponents(streamName, teamName, groupName) {
|
||||||
try {
|
try {
|
||||||
const obsClient = await getOBSClient();
|
const obsClient = await getOBSClient();
|
||||||
|
|
||||||
const cleanGroupName = groupName.toLowerCase().replace(/\s+/g, '_');
|
const cleanGroupName = cleanObsName(groupName);
|
||||||
const cleanStreamName = streamName.toLowerCase().replace(/\s+/g, '_');
|
const cleanStreamName = cleanObsName(streamName);
|
||||||
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
const streamGroupName = `${cleanGroupName}_${cleanStreamName}_stream`;
|
||||||
const sourceName = `${cleanGroupName}_${cleanStreamName}`;
|
const sourceName = `${cleanGroupName}_${cleanStreamName}`;
|
||||||
const textSourceName = teamName.toLowerCase().replace(/\s+/g, '_') + '_text';
|
const textSourceName = cleanObsName(teamName) + '_text';
|
||||||
|
|
||||||
console.log(`Starting comprehensive deletion for stream "${streamName}"`);
|
console.log(`Starting comprehensive deletion for stream "${streamName}"`);
|
||||||
console.log(`Components to delete: scene="${streamGroupName}", source="${sourceName}"`);
|
console.log(`Components to delete: scene="${streamGroupName}", source="${sourceName}"`);
|
||||||
|
@ -650,15 +651,7 @@ async function deleteStreamComponents(streamName, teamName, groupName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Remove from all source switchers
|
// 5. Remove from all source switchers
|
||||||
const screens = [
|
const screens = SOURCE_SWITCHER_NAMES;
|
||||||
'ss_large',
|
|
||||||
'ss_left',
|
|
||||||
'ss_right',
|
|
||||||
'ss_top_left',
|
|
||||||
'ss_top_right',
|
|
||||||
'ss_bottom_left',
|
|
||||||
'ss_bottom_right'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const screen of screens) {
|
for (const screen of screens) {
|
||||||
try {
|
try {
|
||||||
|
@ -723,15 +716,7 @@ async function clearTextFilesForStream(streamGroupName) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files');
|
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files');
|
||||||
const screens = [
|
const screens = SCREEN_POSITIONS;
|
||||||
'large',
|
|
||||||
'left',
|
|
||||||
'right',
|
|
||||||
'topLeft',
|
|
||||||
'topRight',
|
|
||||||
'bottomLeft',
|
|
||||||
'bottomRight'
|
|
||||||
];
|
|
||||||
|
|
||||||
let clearedFiles = [];
|
let clearedFiles = [];
|
||||||
|
|
||||||
|
@ -785,7 +770,7 @@ async function deleteTeamComponents(teamName, groupName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Delete the team text source (shared across all team streams)
|
// 2. Delete the team text source (shared across all team streams)
|
||||||
const textSourceName = teamName.toLowerCase().replace(/\s+/g, '_') + '_text';
|
const textSourceName = cleanObsName(teamName) + '_text';
|
||||||
try {
|
try {
|
||||||
const { inputs } = await obsClient.call('GetInputList');
|
const { inputs } = await obsClient.call('GetInputList');
|
||||||
const textSource = inputs.find(input => input.inputName === textSourceName);
|
const textSource = inputs.find(input => input.inputName === textSourceName);
|
||||||
|
@ -801,7 +786,7 @@ async function deleteTeamComponents(teamName, groupName) {
|
||||||
// 3. Get all scenes to check for nested stream scenes
|
// 3. Get all scenes to check for nested stream scenes
|
||||||
try {
|
try {
|
||||||
const { scenes } = await obsClient.call('GetSceneList');
|
const { scenes } = await obsClient.call('GetSceneList');
|
||||||
const cleanGroupName = (groupName || teamName).toLowerCase().replace(/\s+/g, '_');
|
const cleanGroupName = cleanObsName(groupName || teamName);
|
||||||
|
|
||||||
// Find all nested stream scenes for this team
|
// Find all nested stream scenes for this team
|
||||||
const streamScenes = scenes.filter(scene =>
|
const streamScenes = scenes.filter(scene =>
|
||||||
|
@ -827,7 +812,7 @@ async function deleteTeamComponents(teamName, groupName) {
|
||||||
// 4. Remove any browser sources associated with this team
|
// 4. Remove any browser sources associated with this team
|
||||||
try {
|
try {
|
||||||
const { inputs } = await obsClient.call('GetInputList');
|
const { inputs } = await obsClient.call('GetInputList');
|
||||||
const cleanGroupName = (groupName || teamName).toLowerCase().replace(/\s+/g, '_');
|
const cleanGroupName = cleanObsName(groupName || teamName);
|
||||||
|
|
||||||
// Find all browser sources for this team
|
// Find all browser sources for this team
|
||||||
const teamBrowserSources = inputs.filter(input =>
|
const teamBrowserSources = inputs.filter(input =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue