mail-templates도 수정

This commit is contained in:
dohyeons
2025-10-13 16:18:54 +09:00
parent b6eaaed85e
commit fbb42dd83c
5 changed files with 289 additions and 197 deletions

View File

@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import { encryptionService } from './encryptionService';
import fs from "fs/promises";
import path from "path";
import { encryptionService } from "./encryptionService";
export interface MailAccount {
id: string;
@@ -12,7 +12,7 @@ export interface MailAccount {
smtpUsername: string;
smtpPassword: string; // 암호화된 비밀번호
dailyLimit: number;
status: 'active' | 'inactive' | 'suspended';
status: "active" | "inactive" | "suspended";
createdAt: string;
updatedAt: string;
}
@@ -21,7 +21,11 @@ class MailAccountFileService {
private accountsDir: string;
constructor() {
this.accountsDir = path.join(process.cwd(), 'uploads', 'mail-accounts');
// 운영 환경에서는 /app/uploads/mail-accounts, 개발 환경에서는 프로젝트 루트
this.accountsDir =
process.env.NODE_ENV === "production"
? "/app/uploads/mail-accounts"
: path.join(process.cwd(), "uploads", "mail-accounts");
this.ensureDirectoryExists();
}
@@ -29,7 +33,11 @@ class MailAccountFileService {
try {
await fs.access(this.accountsDir);
} catch {
await fs.mkdir(this.accountsDir, { recursive: true });
try {
await fs.mkdir(this.accountsDir, { recursive: true });
} catch (error) {
console.error("메일 계정 디렉토리 생성 실패:", error);
}
}
}
@@ -39,23 +47,24 @@ class MailAccountFileService {
async getAllAccounts(): Promise<MailAccount[]> {
await this.ensureDirectoryExists();
try {
const files = await fs.readdir(this.accountsDir);
const jsonFiles = files.filter(f => f.endsWith('.json'));
const jsonFiles = files.filter((f) => f.endsWith(".json"));
const accounts = await Promise.all(
jsonFiles.map(async (file) => {
const content = await fs.readFile(
path.join(this.accountsDir, file),
'utf-8'
"utf-8"
);
return JSON.parse(content) as MailAccount;
})
);
return accounts.sort((a, b) =>
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
return accounts.sort(
(a, b) =>
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
);
} catch {
return [];
@@ -64,7 +73,7 @@ class MailAccountFileService {
async getAccountById(id: string): Promise<MailAccount | null> {
try {
const content = await fs.readFile(this.getAccountPath(id), 'utf-8');
const content = await fs.readFile(this.getAccountPath(id), "utf-8");
return JSON.parse(content);
} catch {
return null;
@@ -72,7 +81,7 @@ class MailAccountFileService {
}
async createAccount(
data: Omit<MailAccount, 'id' | 'createdAt' | 'updatedAt'>
data: Omit<MailAccount, "id" | "createdAt" | "updatedAt">
): Promise<MailAccount> {
const id = `account-${Date.now()}`;
const now = new Date().toISOString();
@@ -91,7 +100,7 @@ class MailAccountFileService {
await fs.writeFile(
this.getAccountPath(id),
JSON.stringify(account, null, 2),
'utf-8'
"utf-8"
);
return account;
@@ -99,7 +108,7 @@ class MailAccountFileService {
async updateAccount(
id: string,
data: Partial<Omit<MailAccount, 'id' | 'createdAt'>>
data: Partial<Omit<MailAccount, "id" | "createdAt">>
): Promise<MailAccount | null> {
const existing = await this.getAccountById(id);
if (!existing) {
@@ -122,7 +131,7 @@ class MailAccountFileService {
await fs.writeFile(
this.getAccountPath(id),
JSON.stringify(updated, null, 2),
'utf-8'
"utf-8"
);
return updated;
@@ -139,12 +148,12 @@ class MailAccountFileService {
async getAccountByEmail(email: string): Promise<MailAccount | null> {
const accounts = await this.getAllAccounts();
return accounts.find(a => a.email === email) || null;
return accounts.find((a) => a.email === email) || null;
}
async getActiveAccounts(): Promise<MailAccount[]> {
const accounts = await this.getAllAccounts();
return accounts.filter(a => a.status === 'active');
return accounts.filter((a) => a.status === "active");
}
/**
@@ -156,4 +165,3 @@ class MailAccountFileService {
}
export const mailAccountFileService = new MailAccountFileService();