You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import { requireAdmin } from "#server/utils/admin-guard";
|
|
import { setGlobalConfigValue } from "#server/service/config";
|
|
import { delCache } from "#server/utils/context";
|
|
|
|
interface EmailConfigBody {
|
|
host?: string;
|
|
port?: number;
|
|
user?: string;
|
|
pass?: string;
|
|
from?: string;
|
|
secure?: boolean;
|
|
}
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
await requireAdmin(event);
|
|
const body = await readBody<EmailConfigBody>(event);
|
|
|
|
const updates: Promise<void>[] = [];
|
|
|
|
if (body.host !== undefined) {
|
|
updates.push(setGlobalConfigValue("smtpHost", body.host));
|
|
}
|
|
if (body.port !== undefined) {
|
|
updates.push(setGlobalConfigValue("smtpPort", body.port));
|
|
}
|
|
if (body.user !== undefined) {
|
|
updates.push(setGlobalConfigValue("smtpUser", body.user));
|
|
}
|
|
if (body.pass !== undefined && body.pass !== "") {
|
|
// Only update password if a new non-empty value is provided
|
|
updates.push(setGlobalConfigValue("smtpPass", body.pass));
|
|
}
|
|
if (body.from !== undefined) {
|
|
updates.push(setGlobalConfigValue("smtpFrom", body.from));
|
|
}
|
|
if (body.secure !== undefined) {
|
|
updates.push(setGlobalConfigValue("smtpSecure", body.secure));
|
|
}
|
|
|
|
await Promise.all(updates);
|
|
|
|
// Invalidate config caches
|
|
await delCache("config:global:public");
|
|
await delCache("config:global:admin");
|
|
|
|
return R.success({ message: "邮件配置已保存" });
|
|
});
|
|
|