- Implemented new API routes for handling logs and settings related to the gateway. - Added a new Gateway section in the General Settings panel to manage gateway status and auto-start options. - Introduced a state management hook for gateway settings, including status, logs, and auto-start functionality. - Updated configuration service to include gateway auto-start setting. - Enhanced internationalization support for new gateway-related messages. - Refactored existing settings store to accommodate new gateway settings. - Cleaned up code and improved logging functionality.
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import logManager from '@electron/service/logger';
|
|
import type { HostApiResult } from '@src/types/runtime';
|
|
import type { HostApiContext } from '../context';
|
|
import type { NormalizedHostApiRequest } from '../route-utils';
|
|
import { fail, ok } from '../route-utils';
|
|
|
|
const DEFAULT_TAIL_LINES = 100;
|
|
|
|
function parseTailLines(rawValue: string | null): number {
|
|
const parsed = Number(rawValue ?? DEFAULT_TAIL_LINES);
|
|
if (!Number.isFinite(parsed)) {
|
|
return DEFAULT_TAIL_LINES;
|
|
}
|
|
|
|
return Math.max(1, Math.floor(parsed));
|
|
}
|
|
|
|
export async function handleLogRoutes(
|
|
request: NormalizedHostApiRequest,
|
|
_ctx: HostApiContext,
|
|
): Promise<HostApiResult<unknown> | null> {
|
|
const { pathname, method, url } = request;
|
|
|
|
if (pathname === '/api/logs' && method === 'GET') {
|
|
try {
|
|
return ok({
|
|
content: await logManager.readRecentLogText(parseTailLines(url.searchParams.get('tailLines'))),
|
|
});
|
|
} catch (error) {
|
|
return fail(500, error instanceof Error ? error.message : String(error));
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|