Add OBS group management feature and documentation
- Add group_name column to teams table for mapping teams to OBS groups - Create API endpoints for group creation (/api/createGroup) and bulk sync (/api/syncGroups) - Update teams UI with group status display and creation buttons - Implement automatic group assignment when adding streams - Add comprehensive OBS setup documentation (docs/OBS_SETUP.md) - Fix team list spacing issue with explicit margins - Update OBS client with group management functions - Add database migration script for existing deployments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c259f0d943
commit
5789986bb6
14 changed files with 540 additions and 144 deletions
81
app/api/syncGroups/route.ts
Normal file
81
app/api/syncGroups/route.ts
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
import { open } from 'sqlite';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import path from 'path';
|
||||
import { getTableName, BASE_TABLE_NAMES } from '@/lib/constants';
|
||||
|
||||
const { createGroupIfNotExists } = require('@/lib/obsClient');
|
||||
|
||||
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files');
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
// Open database connection
|
||||
const dbPath = path.join(FILE_DIRECTORY, 'sources.db');
|
||||
const db = await open({
|
||||
filename: dbPath,
|
||||
driver: sqlite3.Database,
|
||||
});
|
||||
|
||||
const teamsTableName = getTableName(BASE_TABLE_NAMES.TEAMS, {
|
||||
year: 2025,
|
||||
season: 'summer',
|
||||
suffix: 'sat'
|
||||
});
|
||||
|
||||
// Get all teams without groups
|
||||
const teamsWithoutGroups = await db.all(
|
||||
`SELECT team_id, team_name FROM ${teamsTableName} WHERE group_name IS NULL`
|
||||
);
|
||||
|
||||
const syncResults = [];
|
||||
|
||||
for (const team of teamsWithoutGroups) {
|
||||
try {
|
||||
// Create group in OBS using team name
|
||||
const obsResult = await createGroupIfNotExists(team.team_name);
|
||||
|
||||
// Update database with group name
|
||||
await db.run(
|
||||
`UPDATE ${teamsTableName} SET group_name = ? WHERE team_id = ?`,
|
||||
[team.team_name, team.team_id]
|
||||
);
|
||||
|
||||
syncResults.push({
|
||||
teamId: team.team_id,
|
||||
teamName: team.team_name,
|
||||
groupName: team.team_name,
|
||||
success: true,
|
||||
obsResult
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error syncing team ${team.team_id}:`, error);
|
||||
syncResults.push({
|
||||
teamId: team.team_id,
|
||||
teamName: team.team_name,
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await db.close();
|
||||
|
||||
const successCount = syncResults.filter(r => r.success).length;
|
||||
const failureCount = syncResults.filter(r => !r.success).length;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: `Sync completed: ${successCount} successful, ${failureCount} failed`,
|
||||
results: syncResults,
|
||||
summary: {
|
||||
total: syncResults.length,
|
||||
successful: successCount,
|
||||
failed: failureCount
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error syncing groups:', error);
|
||||
return NextResponse.json({ error: 'Failed to sync groups' }, { status: 500 });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue