obs-ss-plugin-webui/app/api/getActive/route.ts
Decobus a89fa7c8d6
All checks were successful
Lint and Build / build (pull_request) Successful in 2m46s
Standardize screen position naming to snake_case
- Update screen position naming from camelCase to snake_case (top_left, top_right, bottom_left, bottom_right)
- Refactor getActive route to use SCREEN_POSITIONS constant for DRY code
- Update documentation to reflect new file naming convention
- Remove unnecessary console.log for internal network requests in middleware
- Improve code maintainability and consistency across the codebase

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-25 19:25:38 -04:00

32 lines
No EOL
1.2 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import { createSuccessResponse, createErrorResponse, withErrorHandling } from '../../../lib/apiHelpers';
import { SCREEN_POSITIONS } from '../../../lib/constants';
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files')
// Ensure directory exists
if (!fs.existsSync(FILE_DIRECTORY)) {
fs.mkdirSync(FILE_DIRECTORY, { recursive: true });
}
console.log('using', FILE_DIRECTORY)
async function getActiveHandler() {
try {
const activeSources: Record<string, string | null> = {};
// Read each screen position file using the constant
for (const screen of SCREEN_POSITIONS) {
const filePath = path.join(FILE_DIRECTORY, `${screen}.txt`);
activeSources[screen] = fs.existsSync(filePath)
? fs.readFileSync(filePath, 'utf-8').trim()
: null;
}
return createSuccessResponse(activeSources);
} catch (error) {
console.error('Error reading active sources:', error);
return createErrorResponse('Failed to read active sources', 500, 'Could not read source files', error);
}
}
export const GET = withErrorHandling(getActiveHandler);