migration to postgres
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { createRouter } from '../../create-router';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
import { SERVER_CONFIG_DIR } from '@@/data-path';
|
||||
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';
|
||||
@@ -14,14 +13,6 @@ import { sttRouter } from './stt';
|
||||
import { ocrRouter } from './ocr';
|
||||
import { searxngRouter } from './searxng';
|
||||
|
||||
export const settingsPath = `${SERVER_CONFIG_DIR}/server-settings.json`;
|
||||
|
||||
const settingsFile = Bun.file(settingsPath);
|
||||
if (!(await settingsFile.exists())) {
|
||||
await mkdir(SERVER_CONFIG_DIR, { recursive: true });
|
||||
await Bun.write(settingsPath, '{}');
|
||||
}
|
||||
|
||||
export const serverSettingsRouter = createRouter();
|
||||
|
||||
serverSettingsRouter.route('/claude-code', claudeCodeRouter);
|
||||
@@ -35,33 +26,29 @@ serverSettingsRouter.route('/stt', sttRouter);
|
||||
serverSettingsRouter.route('/ocr', ocrRouter);
|
||||
serverSettingsRouter.route('/searxng', searxngRouter);
|
||||
|
||||
export const readSettings = async () => {
|
||||
try { return await Bun.file(settingsPath).json(); } catch { return {}; }
|
||||
};
|
||||
export { readServerSettings as readSettings };
|
||||
|
||||
serverSettingsRouter.get('/settings', async (ctx) => {
|
||||
return ctx.json(await readSettings());
|
||||
return ctx.json(await readServerSettings());
|
||||
});
|
||||
|
||||
serverSettingsRouter.get('/onboarding-complete', async (ctx) => {
|
||||
const settings = await readSettings();
|
||||
const settings = await readServerSettings();
|
||||
return ctx.json({ onboardingComplete: !!settings.onboardingComplete });
|
||||
});
|
||||
|
||||
serverSettingsRouter.put('/', async (ctx) => {
|
||||
const body = await ctx.req.json();
|
||||
const settings = await readSettings();
|
||||
const settings = await readServerSettings();
|
||||
const updated = { ...settings, ...body };
|
||||
await Bun.write(settingsPath, JSON.stringify(updated, null, 2));
|
||||
await writeServerSettings(updated);
|
||||
return ctx.json(updated);
|
||||
});
|
||||
|
||||
serverSettingsRouter.get('/plugins', async (ctx) => {
|
||||
const pluginsDir = join(import.meta.dir, '../../../workspaces/plugins');
|
||||
const settings = await Bun.file(settingsPath)
|
||||
.json()
|
||||
.catch(() => ({}));
|
||||
const pluginSettings: Record<string, boolean> = settings.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 }[] = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user