Files
zn-ai/electron/api/routes/logs.ts
duanshuwen dfef9c90a5 feat: add gateway management features and settings
- 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.
2026-04-20 22:22:11 +08:00

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;
}