Footer enhancements and performance optimizations #9

Merged
deco merged 10 commits from footer-enhancements into main 2025-07-22 23:01:23 +03:00
2 changed files with 24 additions and 35 deletions
Showing only changes of commit 5dd9707f13 - Show all commits

View file

@ -1,7 +1,7 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
// import config from '../../../config'; import { createSuccessResponse, createErrorResponse, withErrorHandling } from '../../../lib/apiHelpers';
const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files') const FILE_DIRECTORY = path.resolve(process.env.FILE_DIRECTORY || './files')
// Ensure directory exists // Ensure directory exists
@ -10,7 +10,7 @@ if (!fs.existsSync(FILE_DIRECTORY)) {
} }
console.log('using', FILE_DIRECTORY) console.log('using', FILE_DIRECTORY)
export async function GET() { async function getActiveHandler() {
try { try {
const largePath = path.join(FILE_DIRECTORY, 'large.txt'); const largePath = path.join(FILE_DIRECTORY, 'large.txt');
const leftPath = path.join(FILE_DIRECTORY, 'left.txt'); const leftPath = path.join(FILE_DIRECTORY, 'left.txt');
@ -20,38 +20,27 @@ export async function GET() {
const bottomLeftPath = path.join(FILE_DIRECTORY, 'bottomLeft.txt'); const bottomLeftPath = path.join(FILE_DIRECTORY, 'bottomLeft.txt');
const bottomRightPath = path.join(FILE_DIRECTORY, 'bottomRight.txt'); const bottomRightPath = path.join(FILE_DIRECTORY, 'bottomRight.txt');
const tankPath = path.join(FILE_DIRECTORY, 'tank.txt'); const large = fs.existsSync(largePath) ? fs.readFileSync(largePath, 'utf-8').trim() : null;
const treePath = path.join(FILE_DIRECTORY, 'tree.txt'); const left = fs.existsSync(leftPath) ? fs.readFileSync(leftPath, 'utf-8').trim() : null;
const kittyPath = path.join(FILE_DIRECTORY, 'kitty.txt'); const right = fs.existsSync(rightPath) ? fs.readFileSync(rightPath, 'utf-8').trim() : null;
const chickenPath = path.join(FILE_DIRECTORY, 'chicken.txt'); const topLeft = fs.existsSync(topLeftPath) ? fs.readFileSync(topLeftPath, 'utf-8').trim() : null;
const topRight = fs.existsSync(topRightPath) ? fs.readFileSync(topRightPath, 'utf-8').trim() : null;
const bottomLeft = fs.existsSync(bottomLeftPath) ? fs.readFileSync(bottomLeftPath, 'utf-8').trim() : null;
const bottomRight = fs.existsSync(bottomRightPath) ? fs.readFileSync(bottomRightPath, 'utf-8').trim() : null;
return createSuccessResponse({
// eslint-disable-next-line @typescript-eslint/no-unused-vars large,
const large = fs.existsSync(largePath) ? fs.readFileSync(largePath, 'utf-8') : null; left,
// eslint-disable-next-line @typescript-eslint/no-unused-vars right,
const left = fs.existsSync(leftPath) ? fs.readFileSync(leftPath, 'utf-8') : null; topLeft,
// eslint-disable-next-line @typescript-eslint/no-unused-vars topRight,
const right = fs.existsSync(rightPath) ? fs.readFileSync(rightPath, 'utf-8') : null; bottomLeft,
// eslint-disable-next-line @typescript-eslint/no-unused-vars bottomRight
const topLeft = fs.existsSync(topLeftPath) ? fs.readFileSync(topLeftPath, 'utf-8') : null; });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const topRight = fs.existsSync(topRightPath) ? fs.readFileSync(topRightPath, 'utf-8') : null;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const bottomLeft = fs.existsSync(bottomLeftPath) ? fs.readFileSync(bottomLeftPath, 'utf-8') : null;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const bottomRight = fs.existsSync(bottomRightPath) ? fs.readFileSync(bottomRightPath, 'utf-8') : null;
const tank = fs.existsSync(tankPath) ? fs.readFileSync(tankPath, 'utf-8') : null;
const tree = fs.existsSync(treePath) ? fs.readFileSync(treePath, 'utf-8') : null;
const kitty = fs.existsSync(kittyPath) ? fs.readFileSync(kittyPath, 'utf-8') : null;
const chicken = fs.existsSync(chickenPath) ? fs.readFileSync(chickenPath, 'utf-8') : null;
// For SaT
return NextResponse.json({ large, left, right, topLeft, topRight, bottomLeft, bottomRight }, {status: 201})
// return NextResponse.json({ tank, tree, kitty, chicken }, {status: 201})
} catch (error) { } catch (error) {
console.error('Error reading active sources:', error); console.error('Error reading active sources:', error);
return NextResponse.json({ error: 'Failed to read active sources' }, {status: 500}); return createErrorResponse('Failed to read active sources', 500, 'Could not read source files', error);
}
} }
} export const GET = withErrorHandling(getActiveHandler);

View file

@ -81,7 +81,7 @@ export default function Home() {
]); ]);
setStreams(streamsData.data); setStreams(streamsData.data);
setActiveSources(activeData); setActiveSources(activeData.data);
} catch (error) { } catch (error) {
console.error('Error fetching data:', error); console.error('Error fetching data:', error);
showError('Failed to Load Data', 'Could not fetch streams. Please refresh the page.'); showError('Failed to Load Data', 'Could not fetch streams. Please refresh the page.');