From aac4e61398ed829e9dfa2c038f76405f92563d14 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Thu, 6 Nov 2025 21:05:36 +0900 Subject: (김준회) 견적 이메일 발송시, 첨부파일 복호화 처리 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/rfq-last/service.ts | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/rfq-last/service.ts b/lib/rfq-last/service.ts index 65ead12b..462b5604 100644 --- a/lib/rfq-last/service.ts +++ b/lib/rfq-last/service.ts @@ -3153,6 +3153,12 @@ export interface SendRfqParams { fileName: string; }>; hasToSendEmail?: boolean; // 이메일 발송 여부 + currentUser?: { // ⚠️ cronjob 환경을 위한 선택적 파라미터 + id: string | number; + name?: string | null; + email?: string | null; + epId?: string | null; + }; } export async function sendRfqToVendors({ @@ -3162,14 +3168,22 @@ export async function sendRfqToVendors({ attachmentIds, message, generatedPdfs, - hasToSendEmail = true + hasToSendEmail = true, + currentUser: providedUser // ⚠️ cronjob 환경에서는 payload로 받은 유저 정보 사용 }: SendRfqParams) { - const session = await getServerSession(authOptions); - if (!session?.user) { - throw new Error("인증이 필요합니다."); - } + let currentUser; - const currentUser = session.user; + if (providedUser) { + // ✅ Cronjob 환경: payload에서 받은 유저 정보 사용 + currentUser = providedUser; + } else { + // ✅ 일반 환경: session에서 유저 정보 가져오기 + const session = await getServerSession(authOptions); + if (!session?.user) { + throw new Error("인증이 필요합니다."); + } + currentUser = session.user; + } try { // 1. RFQ 기본 정보 조회 (트랜잭션 외부) @@ -4183,13 +4197,20 @@ async function handleRfqSendEmail({ ? path.join(process.cwd(), `public`, cleanPath) : path.join(`${process.env.NAS_PATH}`, cleanPath); + // 파일 읽기 const fileBuffer = await fs.readFile(fullPath); + + // DRM 복호화 처리 + const fileName = revision.originalFileName || `${attachment.attachmentType}_${attachment.serialNo}`; + const { decryptBufferWithServerAction } = await import('@/components/drm/drmUtils'); + const decryptedBuffer = await decryptBufferWithServerAction(fileBuffer, fileName); + emailAttachmentsList.push({ - filename: revision.originalFileName || `${attachment.attachmentType}_${attachment.serialNo}`, - content: fileBuffer + filename: fileName, + content: decryptedBuffer }); } catch (error) { - console.error(`이메일 첨부파일 읽기 실패: ${cleanPath}`, error); + console.error(`이메일 첨부파일 처리 실패: ${revision.filePath || 'unknown'}`, error); } } } @@ -5367,7 +5388,7 @@ export async function getAvlVendorsForRfq(rfqId: number) { console.error("AVL 벤더 조회 오류:", error); return { success: false, - error: "AVL 벤더 정보를 가져오는 중 오류가 발생했습니다." + error: "-" }; } } -- cgit v1.2.3