summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rfq-last/service.ts41
1 files changed, 31 insertions, 10 deletions
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: "-"
};
}
}