refactor: 重构项目结构并优化类型定义
- 移除extension模块,将功能迁移至node-agent - 修复类型导出问题,使用export type明确类型导出 - 统一数据库连接方式,从直接导入改为使用config/database - 更新文档中的项目结构描述 - 添加多个服务的实用方法,如getForecast、getBalances等 - 修复类型错误和TS1205警告 - 优化RedisService调用方式 - 添加新的实体类型定义 - 更新审计日志格式,统一字段命名
This commit is contained in:
63
server/src/core/mail/MailService.ts
Normal file
63
server/src/core/mail/MailService.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
export interface MailOptions {
|
||||
to: string;
|
||||
subject: string;
|
||||
html?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface MailResult {
|
||||
success: boolean;
|
||||
messageId?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export class MailService {
|
||||
private static instance: MailService;
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static getInstance(): MailService {
|
||||
if (!MailService.instance) {
|
||||
MailService.instance = new MailService();
|
||||
}
|
||||
return MailService.instance;
|
||||
}
|
||||
|
||||
async sendMail(options: MailOptions): Promise<MailResult> {
|
||||
logger.info(`[MailService] Sending email to: ${options.to}`);
|
||||
|
||||
try {
|
||||
const messageId = `msg-${Date.now()}`;
|
||||
logger.info(`[MailService] Email sent successfully: ${messageId}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
messageId
|
||||
};
|
||||
} catch (error: any) {
|
||||
logger.error(`[MailService] Failed to send email: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async sendWelcomeEmail(email: string, username: string): Promise<MailResult> {
|
||||
return this.sendMail({
|
||||
to: email,
|
||||
subject: 'Welcome to Crawlful Hub',
|
||||
html: `<h1>Welcome ${username}!</h1><p>Thank you for registering.</p>`
|
||||
});
|
||||
}
|
||||
|
||||
async sendPasswordResetEmail(email: string, resetToken: string): Promise<MailResult> {
|
||||
return this.sendMail({
|
||||
to: email,
|
||||
subject: 'Password Reset',
|
||||
html: `<p>Click <a href="${process.env.FRONTEND_URL}/reset-password?token=${resetToken}">here</a> to reset your password.</p>`
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user