Initial commit - OBS Source Switcher Plugin UI
Complete Next.js application for managing OBS Source Switcher - Stream management with multiple screen layouts - Team management CRUD operations - SQLite database integration - OBS WebSocket API integration - Updated to latest versions (Next.js 15.4.1, React 19.1.0, Tailwind CSS 4.0.0) - Enhanced .gitignore for privacy and development
This commit is contained in:
commit
1d4b1eefba
43 changed files with 9596 additions and 0 deletions
43
app/api/setActive/route.ts
Normal file
43
app/api/setActive/route.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
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 { Stream, Screen } from '@/types';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body: Screen = await request.json();
|
||||
const { screen, id } = body;
|
||||
|
||||
const validScreens = ['large', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'];
|
||||
if (!validScreens.includes(screen)) {
|
||||
return NextResponse.json({ error: 'Invalid screen name' }, { status: 400 });
|
||||
}
|
||||
|
||||
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: Stream | undefined = await db.get<Stream>(
|
||||
'SELECT * FROM streams_2025_spring_adr WHERE id = ?',
|
||||
[id]
|
||||
);
|
||||
|
||||
console.log('Stream:', stream);
|
||||
|
||||
if (!stream) {
|
||||
return NextResponse.json({ error: 'Stream not found' }, { status: 400 });
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, stream.obs_source_name);
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue