- Created /api/counts endpoint for database statistics - Updated footer to display team and stream counts - Shows counts when OBS is connected (alongside OBS stats) - Shows database stats when OBS is disconnected (fallback display) - Polls counts every 60 seconds (less frequent than OBS status) - Maintains backward compatibility with API response formats Footer now shows: - Teams: X - Streams: Y 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
25 lines
No EOL
826 B
TypeScript
25 lines
No EOL
826 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getDatabase } from '../../../lib/database';
|
|
import { TABLE_NAMES } from '../../../lib/constants';
|
|
import { createSuccessResponse, createDatabaseError, withErrorHandling } from '../../../lib/apiHelpers';
|
|
|
|
async function getCountsHandler() {
|
|
try {
|
|
const db = await getDatabase();
|
|
|
|
// Get counts in parallel
|
|
const [streamsResult, teamsResult] = await Promise.all([
|
|
db.get(`SELECT COUNT(*) as count FROM ${TABLE_NAMES.STREAMS}`),
|
|
db.get(`SELECT COUNT(*) as count FROM ${TABLE_NAMES.TEAMS}`)
|
|
]);
|
|
|
|
return createSuccessResponse({
|
|
streams: streamsResult.count,
|
|
teams: teamsResult.count
|
|
});
|
|
} catch (error) {
|
|
return createDatabaseError('fetch counts', error);
|
|
}
|
|
}
|
|
|
|
export const GET = withErrorHandling(getCountsHandler); |