migration to postgres

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 17:42:59 +00:00
co-authored by Claude Opus 4.6
parent 7f04ecd644
commit 500a70910e
54 changed files with 4016 additions and 264 deletions
+1
View File
@@ -11,6 +11,7 @@
"@react-email/code-block": "^0.0.11",
"@react-email/components": "^0.0.31",
"@react-email/render": "^1.0.3",
"officerdb": "workspace:*",
"react-email": "^3.0.4"
}
}
+15 -21
View File
@@ -1,8 +1,7 @@
import { createTransport, type Transporter } from 'nodemailer';
import { join } from 'node:path';
import { readServerSettings } from 'officerdb';
const { MAIL_TRANSPORT, DATA_PATH } = process.env;
const dataPath = DATA_PATH ?? join(process.cwd(), 'data');
const { MAIL_TRANSPORT } = process.env;
type SmtpConfig = {
provider: 'resend' | 'smtp' | 'mailhog';
@@ -16,8 +15,6 @@ type SmtpConfig = {
fromEmail: string;
};
const settingsPath = join(dataPath, 'server-settings', 'server-settings.json');
let cachedTransport: Transporter | null = null;
let cachedConfigHash: string | null = null;
@@ -36,26 +33,23 @@ export type TransportResult = SmtpTransport | ResendTransport;
export async function getTransport(): Promise<TransportResult> {
try {
const file = Bun.file(settingsPath);
if (await file.exists()) {
const settings = await file.json();
const smtp: SmtpConfig | undefined = settings.smtp;
if (smtp) {
const from = `${smtp.fromName} <${smtp.fromEmail}>`;
const settings = await readServerSettings();
const smtp: SmtpConfig | undefined = settings.smtp as SmtpConfig | undefined;
if (smtp) {
const from = `${smtp.fromName} <${smtp.fromEmail}>`;
if (smtp.provider === 'resend') {
return { type: 'resend', apiKey: smtp.apiKey ?? '', from };
}
if (smtp.provider === 'resend') {
return { type: 'resend', apiKey: smtp.apiKey ?? '', from };
}
const hash = JSON.stringify(smtp);
if (cachedTransport && cachedConfigHash === hash) {
return { type: 'smtp', transport: cachedTransport, from };
}
const url = buildTransportUrl(smtp);
cachedTransport = createTransport(url);
cachedConfigHash = hash;
const hash = JSON.stringify(smtp);
if (cachedTransport && cachedConfigHash === hash) {
return { type: 'smtp', transport: cachedTransport, from };
}
const url = buildTransportUrl(smtp);
cachedTransport = createTransport(url);
cachedConfigHash = hash;
return { type: 'smtp', transport: cachedTransport, from };
}
} catch {
// Fall through to env var