79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
import { createRouter } from '../../create-router';
|
|
import { readdirSync, existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { readServerSettings, writeServerSettings } from 'officerdb';
|
|
import { claudeCodeRouter } from './claude-code';
|
|
import { opencodeRouter } from './opencode';
|
|
import { piMonoRouter } from './pi-mono';
|
|
import { applicationsRouter } from './applications';
|
|
import { resourcesRouter } from './resources';
|
|
import { smtpRouter } from './smtp';
|
|
import { ttsRouter } from './tts';
|
|
import { sttRouter } from './stt';
|
|
import { ocrRouter } from './ocr';
|
|
import { searxngRouter } from './searxng';
|
|
|
|
export const serverSettingsRouter = createRouter();
|
|
|
|
serverSettingsRouter.route('/claude-code', claudeCodeRouter);
|
|
serverSettingsRouter.route('/opencode', opencodeRouter);
|
|
serverSettingsRouter.route('/pi-mono', piMonoRouter);
|
|
serverSettingsRouter.route('/applications', applicationsRouter);
|
|
serverSettingsRouter.route('/resources', resourcesRouter);
|
|
serverSettingsRouter.route('/smtp', smtpRouter);
|
|
serverSettingsRouter.route('/tts', ttsRouter);
|
|
serverSettingsRouter.route('/stt', sttRouter);
|
|
serverSettingsRouter.route('/ocr', ocrRouter);
|
|
serverSettingsRouter.route('/searxng', searxngRouter);
|
|
|
|
export { readServerSettings as readSettings };
|
|
|
|
serverSettingsRouter.get('/settings', async (ctx) => {
|
|
return ctx.json(await readServerSettings());
|
|
});
|
|
|
|
serverSettingsRouter.get('/onboarding-complete', async (ctx) => {
|
|
const settings = await readServerSettings();
|
|
return ctx.json({ onboardingComplete: !!settings.onboardingComplete });
|
|
});
|
|
|
|
serverSettingsRouter.put('/', async (ctx) => {
|
|
const body = await ctx.req.json();
|
|
const settings = await readServerSettings();
|
|
const updated = { ...settings, ...body };
|
|
await writeServerSettings(updated);
|
|
return ctx.json(updated);
|
|
});
|
|
|
|
serverSettingsRouter.get('/plugins', async (ctx) => {
|
|
const pluginsDir = join(import.meta.dir, '../../../workspaces/plugins');
|
|
const settings = await readServerSettings();
|
|
const pluginSettings: Record<string, boolean> = (settings.plugins as Record<string, boolean>) ?? {};
|
|
|
|
const plugins: { id: string; name: string; description: string; enabled: boolean }[] = [];
|
|
|
|
if (!existsSync(pluginsDir)) return ctx.json(plugins);
|
|
|
|
const dirs = readdirSync(pluginsDir, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
|
|
for (const dir of dirs) {
|
|
const hasServer = existsSync(join(pluginsDir, dir.name, 'server', 'index.ts'));
|
|
const hasClient = existsSync(join(pluginsDir, dir.name, 'client', 'index.ts'));
|
|
if (!hasServer && !hasClient) continue;
|
|
|
|
const mainIndex = join(pluginsDir, dir.name, 'index.ts');
|
|
if (!existsSync(mainIndex)) continue;
|
|
|
|
const mod = await import(mainIndex);
|
|
const meta = mod.plugin ?? { id: dir.name, name: dir.name, description: '' };
|
|
plugins.push({
|
|
id: meta.id,
|
|
name: meta.name,
|
|
description: meta.description,
|
|
enabled: pluginSettings[meta.id] !== false,
|
|
});
|
|
}
|
|
|
|
return ctx.json(plugins);
|
|
});
|