migration to postgres
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { createRouter } from '../../create-router';
|
||||
import { settingsPath } from './server-settings';
|
||||
import { readServerSettings, writeServerSettings } from 'officerdb';
|
||||
import { getTransport } from 'emailer';
|
||||
|
||||
type SmtpConfig = {
|
||||
@@ -46,24 +46,24 @@ function buildTransportUrl(config: SmtpConfig): string {
|
||||
export const smtpRouter = createRouter();
|
||||
|
||||
smtpRouter.get('/', async (ctx) => {
|
||||
const settings = await Bun.file(settingsPath).json().catch(() => ({}));
|
||||
const smtp: SmtpConfig | undefined = settings.smtp;
|
||||
const settings = await readServerSettings();
|
||||
const smtp: SmtpConfig | undefined = settings.smtp as SmtpConfig | undefined;
|
||||
if (smtp) return ctx.json(serializeConfig(smtp));
|
||||
return ctx.json(null);
|
||||
});
|
||||
|
||||
smtpRouter.put('/', async (ctx) => {
|
||||
const body = await ctx.req.json<SmtpConfig>();
|
||||
const settings = await Bun.file(settingsPath).json().catch(() => ({}));
|
||||
const settings = await readServerSettings();
|
||||
|
||||
const existing: SmtpConfig | undefined = settings.smtp;
|
||||
const existing: SmtpConfig | undefined = settings.smtp as SmtpConfig | undefined;
|
||||
if (existing) {
|
||||
if (body.apiKey && body.apiKey.includes('****')) body.apiKey = existing.apiKey;
|
||||
if (body.password && body.password.includes('****')) body.password = existing.password;
|
||||
}
|
||||
|
||||
settings.smtp = body;
|
||||
await Bun.write(settingsPath, JSON.stringify(settings, null, 2));
|
||||
await writeServerSettings(settings);
|
||||
return ctx.json({ success: true });
|
||||
});
|
||||
|
||||
@@ -95,8 +95,8 @@ smtpRouter.post('/test', async (ctx) => {
|
||||
if (!body.to) return ctx.json({ error: 'Recipient address required' }, 400);
|
||||
|
||||
// Resolve masked secrets from saved config
|
||||
const settings = await Bun.file(settingsPath).json().catch(() => ({}));
|
||||
const saved: SmtpConfig | undefined = settings.smtp;
|
||||
const settings = await readServerSettings();
|
||||
const saved: SmtpConfig | undefined = settings.smtp as SmtpConfig | undefined;
|
||||
if (saved) {
|
||||
if (body.apiKey?.includes('****')) body.apiKey = saved.apiKey;
|
||||
if (body.password?.includes('****')) body.password = saved.password;
|
||||
|
||||
Reference in New Issue
Block a user