- 后端:基于 NestJS 的分层架构设计 - 前端:基于 VbenAdmin + Element Plus 的管理系统 - 支持 SaaS + 独立版双架构模式 - 完整的用户权限管理系统 - 系统设置、文件上传、通知等核心功能 - 多租户支持和插件化扩展架构
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { Injectable } from '@nestjs/common';
|
|
import type { EmailSettingsVo } from './email-settings.dto';
|
|
|
|
const SETTINGS_DIR = path.resolve(process.cwd(), 'config', 'runtime');
|
|
const SETTINGS_FILE = path.resolve(SETTINGS_DIR, 'email.settings.json');
|
|
|
|
const DEFAULT_SETTINGS: EmailSettingsVo = {
|
|
enabled: false,
|
|
host: '',
|
|
port: 465,
|
|
secure: true,
|
|
user: '',
|
|
pass: '',
|
|
from: '',
|
|
};
|
|
|
|
@Injectable()
|
|
export class EmailSettingsService {
|
|
async getSettings(): Promise<EmailSettingsVo> {
|
|
try {
|
|
const buf = await fs.promises.readFile(SETTINGS_FILE, 'utf8');
|
|
const json = JSON.parse(buf);
|
|
return { ...DEFAULT_SETTINGS, ...json };
|
|
} catch {
|
|
return { ...DEFAULT_SETTINGS };
|
|
}
|
|
}
|
|
|
|
async updateSettings(patch: Partial<EmailSettingsVo>): Promise<EmailSettingsVo> {
|
|
const current = await this.getSettings();
|
|
const next: EmailSettingsVo = { ...current, ...patch };
|
|
await fs.promises.mkdir(SETTINGS_DIR, { recursive: true });
|
|
await fs.promises.writeFile(SETTINGS_FILE, JSON.stringify(next, null, 2), 'utf8');
|
|
return next;
|
|
}
|
|
|
|
static getSettingsPath() {
|
|
return SETTINGS_FILE;
|
|
}
|
|
} |