summaryrefslogtreecommitdiff
path: root/app/api
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-21 06:57:36 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-21 06:57:36 +0000
commit02b1cf005cf3e1df64183d20ba42930eb2767a9f (patch)
treee932c54d5260b0e6fda2b46be2a6ba1c3ee30434 /app/api
parentd78378ecd7ceede1429359f8058c7a99ac34b1b7 (diff)
(대표님, 최겸) 설계메뉴추가, 작업사항 업데이트
설계메뉴 - 문서관리 설계메뉴 - 벤더 데이터 gtc 메뉴 업데이트 정보시스템 - 메뉴리스트 및 정보 업데이트 파일 라우트 업데이트 엑셀임포트 개선 기본계약 개선 벤더 가입과정 변경 및 개선 벤더 기본정보 - pq 돌체 오류 수정 및 개선 벤더 로그인 과정 이메일 오류 수정
Diffstat (limited to 'app/api')
-rw-r--r--app/api/files/[...path]/route.ts3
-rw-r--r--app/api/upload/basicContract/chunk/route.ts156
2 files changed, 88 insertions, 71 deletions
diff --git a/app/api/files/[...path]/route.ts b/app/api/files/[...path]/route.ts
index 9ef11bc7..0bc2e22f 100644
--- a/app/api/files/[...path]/route.ts
+++ b/app/api/files/[...path]/route.ts
@@ -45,6 +45,9 @@ const isAllowedPath = (requestedPath: string): boolean => {
'vendor-evaluation',
'evaluation-attachments',
'vendor-attachments',
+ 'vendor-attachments/nda',
+ 'vendors/nda',
+ 'vendors',
'pq',
'pq/vendor'
];
diff --git a/app/api/upload/basicContract/chunk/route.ts b/app/api/upload/basicContract/chunk/route.ts
index 383a8f36..db3d591e 100644
--- a/app/api/upload/basicContract/chunk/route.ts
+++ b/app/api/upload/basicContract/chunk/route.ts
@@ -33,83 +33,97 @@ export async function POST(request: NextRequest) {
console.log(`📦 청크 저장 완료: ${chunkIndex + 1}/${totalChunks} (${buffer.length} bytes)`);
// 마지막 청크인 경우 모든 청크를 합쳐 최종 파일 생성
- if (chunkIndex === totalChunks - 1) {
- console.log(`🔄 파일 병합 시작: ${filename}`);
-
- try {
- // 모든 청크를 순서대로 읽어서 병합
- const chunks: Buffer[] = [];
- let totalSize = 0;
-
- for (let i = 0; i < totalChunks; i++) {
- const chunkData = await readFile(path.join(tempDir, `chunk-${i}`));
- chunks.push(chunkData);
- totalSize += chunkData.length;
- }
-
- // 모든 청크를 하나의 Buffer로 병합
- const mergedBuffer = Buffer.concat(chunks, totalSize);
-
- const mergedFile = new File([mergedBuffer], filename, {
- type: chunk.type || 'application/octet-stream',
- lastModified: Date.now(),
- });
-
- const saveResult = await saveDRMFile(
- mergedFile,
- decryptWithServerAction, // 복호화 함수
- 'basicContract/template', // 저장 디렉토리
- // userId // 선택
- );
+// 마지막 청크인 경우 모든 청크를 합쳐 최종 파일 생성
+if (chunkIndex === totalChunks - 1) {
+ console.log(`🔄 파일 병합 시작: ${filename}`);
+
+ try {
+ // 모든 청크를 순서대로 읽어서 병합
+ const chunks: Buffer[] = [];
+ let totalSize = 0;
+
+ for (let i = 0; i < totalChunks; i++) {
+ const chunkData = await readFile(path.join(tempDir, `chunk-${i}`));
+ chunks.push(chunkData);
+ totalSize += chunkData.length;
+ }
+
+ // 모든 청크를 하나의 Buffer로 병합
+ const mergedBuffer = Buffer.concat(chunks, totalSize);
+ console.log(`📄 병합 완료: ${filename} (총 ${totalSize} bytes)`);
+ // 환경에 따른 저장 방식 선택
+ const isProduction = process.env.NODE_ENV === 'production';
+ let saveResult;
-
- console.log(`📄 병합 완료: ${filename} (총 ${totalSize} bytes)`);
+ if (isProduction) {
+ // Production: DRM 파일 처리
+ console.log(`🔐 Production 환경 - DRM 파일 처리: ${filename}`);
+
+ const mergedFile = new File([mergedBuffer], filename, {
+ type: chunk.type || 'application/octet-stream',
+ lastModified: Date.now(),
+ });
- // 공용 함수를 사용하여 파일 저장
- // const saveResult = await saveBuffer({
- // buffer: mergedBuffer,
- // fileName: filename,
- // directory: 'basicContract/template',
- // originalName: filename
- // });
+ saveResult = await saveDRMFile(
+ mergedFile,
+ decryptWithServerAction, // 복호화 함수
+ 'basicContract/template', // 저장 디렉토리
+ // userId // 선택사항
+ );
+ } else {
+ // Development: 일반 파일 저장
+ console.log(`🛠️ Development 환경 - 일반 파일 저장: ${filename}`);
+
+ saveResult = await saveBuffer({
+ buffer: mergedBuffer,
+ fileName: filename,
+ directory: 'basicContract/template',
+ originalName: filename
+ });
+ }
- // 임시 파일 정리 (비동기로 처리)
- rm(tempDir, { recursive: true, force: true })
- .then(() => console.log(`🗑️ 임시 파일 정리 완료: ${fileId}`))
- .catch((e: unknown) => console.error('청크 정리 오류:', e));
+ // 임시 파일 정리 (비동기로 처리)
+ rm(tempDir, { recursive: true, force: true })
+ .then(() => console.log(`🗑️ 임시 파일 정리 완료: ${fileId}`))
+ .catch((e: unknown) => console.error('청크 정리 오류:', e));
- if (saveResult.success) {
- console.log(`✅ 최종 파일 저장 완료: ${saveResult.fileName}`);
-
- return NextResponse.json({
- success: true,
- fileName: filename,
- filePath: saveResult.publicPath,
- hashedFileName: saveResult.fileName,
- fileSize: totalSize
- });
- } else {
- console.error('파일 저장 실패:', saveResult.error);
- return NextResponse.json({
- success: false,
- error: saveResult.error || '파일 저장에 실패했습니다'
- }, { status: 500 });
- }
-
- } catch (mergeError) {
- console.error('파일 병합 오류:', mergeError);
-
- // 오류 발생 시 임시 파일 정리
- rm(tempDir, { recursive: true, force: true })
- .catch((e: unknown) => console.error('임시 파일 정리 오류:', e));
-
- return NextResponse.json({
- success: false,
- error: '파일 병합 중 오류가 발생했습니다'
- }, { status: 500 });
- }
+ if (saveResult.success) {
+ const envPrefix = isProduction ? '🔐' : '🛠️';
+ console.log(`${envPrefix} 최종 파일 저장 완료: ${saveResult.fileName}`);
+
+ return NextResponse.json({
+ success: true,
+ fileName: filename,
+ filePath: saveResult.publicPath,
+ hashedFileName: saveResult.fileName,
+ fileSize: totalSize,
+ environment: isProduction ? 'production' : 'development',
+ processingType: isProduction ? 'DRM' : 'standard'
+ });
+ } else {
+ const envPrefix = isProduction ? '🔐' : '🛠️';
+ console.error(`${envPrefix} 파일 저장 실패:`, saveResult.error);
+ return NextResponse.json({
+ success: false,
+ error: saveResult.error || '파일 저장에 실패했습니다',
+ environment: isProduction ? 'production' : 'development'
+ }, { status: 500 });
}
+
+ } catch (mergeError) {
+ console.error('파일 병합 오류:', mergeError);
+
+ // 오류 발생 시 임시 파일 정리
+ rm(tempDir, { recursive: true, force: true })
+ .catch((e: unknown) => console.error('임시 파일 정리 오류:', e));
+
+ return NextResponse.json({
+ success: false,
+ error: '파일 병합 중 오류가 발생했습니다'
+ }, { status: 500 });
+ }
+}
return NextResponse.json({
success: true,