diff options
| author | joonhoekim <26rote@gmail.com> | 2025-09-26 14:13:20 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-09-26 14:13:20 +0900 |
| commit | f8fc02e175f93466cd7693eb6e549c45362e785b (patch) | |
| tree | 1037ec1f9225b0a0142defd6a27c68c3e6a47009 /lib/pos/download-pos-file.ts | |
| parent | 11bc8239ad474a8f31c1c73de51f7d0f101594df (diff) | |
(김준회) POS 및 구매 피드백 처리
- 요구사항 28.(0.1) 24번 행 (prItem번호 별도 표기)
- pos nfs 경로에서 가져오도록 수정개발
Diffstat (limited to 'lib/pos/download-pos-file.ts')
| -rw-r--r-- | lib/pos/download-pos-file.ts | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/lib/pos/download-pos-file.ts b/lib/pos/download-pos-file.ts index d285c618..9fd6867f 100644 --- a/lib/pos/download-pos-file.ts +++ b/lib/pos/download-pos-file.ts @@ -3,20 +3,29 @@ import fs from 'fs/promises'; import path from 'path'; import type { DownloadPosFileParams, DownloadPosFileResult } from './types'; +import { DOCUMENTUM_NFS_PATH } from './types'; import { debugLog, debugError, debugSuccess, debugProcess } from '@/lib/debug-utils'; -const POS_BASE_PATH = '\\\\60.100.99.123\\ECM_NAS_PRM\\Download'; +// 레거시: Windows 네트워크 경로 (하위 호환성을 위해 유지) +const POS_BASE_PATH_LEGACY = '\\\\60.100.99.123\\ECM_NAS_PRM\\Download'; + +// NFS 마운트 경로 사용 +const POS_BASE_PATH = path.posix.join(DOCUMENTUM_NFS_PATH, 'Download'); /** - * POS API에서 반환된 경로의 파일을 내부망에서 읽어서 클라이언트에게 전달 - * 내부망 파일을 직접 접근할 수 없는 클라이언트를 위한 프록시 역할 + * POS API에서 반환된 경로의 파일을 NFS 마운트를 통해 읽어서 클라이언트에게 전달 + * NFS 마운트된 Documentum 저장소에서 파일을 직접 접근하여 제공 */ export async function downloadPosFile( params: DownloadPosFileParams ): Promise<DownloadPosFileResult> { try { const { relativePath } = params; - debugLog(`⬇️ POS 파일 다운로드 시작`, { relativePath, basePath: POS_BASE_PATH }); + debugLog(`⬇️ POS 파일 다운로드 시작 (NFS)`, { + relativePath, + nfsBasePath: DOCUMENTUM_NFS_PATH, + basePath: POS_BASE_PATH + }); if (!relativePath) { debugError(`❌ 파일 경로가 제공되지 않음`); @@ -26,21 +35,28 @@ export async function downloadPosFile( }; } - // Windows 경로 구분자를 정규화 - const normalizedRelativePath = relativePath.replace(/\\/g, path.sep); - debugLog(`📁 경로 정규화`, { original: relativePath, normalized: normalizedRelativePath }); + // Windows 경로 구분자를 Unix 스타일로 정규화 (NFS용) + const normalizedRelativePath = relativePath.replace(/\\/g, '/'); + debugLog(`📁 경로 정규화 (NFS)`, { + original: relativePath, + normalized: normalizedRelativePath + }); - // 전체 파일 경로 구성 - const fullPath = path.join(POS_BASE_PATH, normalizedRelativePath); - debugLog(`📍 전체 파일 경로 구성`, { fullPath }); + // NFS 마운트 경로와 상대 경로를 결합 + const fullPath = path.posix.join(POS_BASE_PATH, normalizedRelativePath); + debugLog(`📍 NFS 전체 파일 경로 구성`, { fullPath }); // 경로 보안 검증 (디렉토리 탈출 방지) const resolvedPath = path.resolve(fullPath); - const resolvedBasePath = path.resolve(POS_BASE_PATH); - debugLog(`🔒 경로 보안 검증`, { resolvedPath, resolvedBasePath, isValid: resolvedPath.startsWith(resolvedBasePath) }); + const resolvedBasePath = path.resolve(DOCUMENTUM_NFS_PATH); + debugLog(`🔒 경로 보안 검증 (NFS)`, { + resolvedPath, + resolvedBasePath, + isValid: resolvedPath.startsWith(resolvedBasePath) + }); if (!resolvedPath.startsWith(resolvedBasePath)) { - debugError(`❌ 디렉토리 탈출 시도 감지`, { resolvedPath, resolvedBasePath }); + debugError(`❌ 디렉토리 탈출 시도 감지 (NFS)`, { resolvedPath, resolvedBasePath }); return { success: false, error: '잘못된 파일 경로입니다.', @@ -48,7 +64,7 @@ export async function downloadPosFile( } // 파일 존재 여부 확인 - debugProcess(`🔍 파일 존재 여부 확인 중...`); + debugProcess(`🔍 NFS 파일 존재 여부 확인 중...`); try { await fs.access(resolvedPath); debugSuccess(`✅ 파일 존재 확인됨 (${resolvedPath})`); @@ -95,10 +111,11 @@ export async function downloadPosFile( const mimeType = await getMimeType(fileName); debugLog(`🔍 MIME 타입 추정 완료`, { fileName, mimeType }); - debugSuccess(`✅ POS 파일 다운로드 성공`, { + debugSuccess(`✅ NFS를 통한 POS 파일 다운로드 성공`, { fileName, fileSize: fileBuffer.length, - mimeType + mimeType, + nfsPath: resolvedPath }); return { @@ -108,8 +125,9 @@ export async function downloadPosFile( mimeType, }; } catch (error) { - debugError('❌ POS 파일 다운로드 실패', { - relativePath: params.relativePath, + debugError('❌ NFS를 통한 POS 파일 다운로드 실패', { + relativePath: params.relativePath, + nfsBasePath: DOCUMENTUM_NFS_PATH, error: error instanceof Error ? error.message : '알 수 없는 오류', stack: error instanceof Error ? error.stack : undefined }); |
