From 387a1fd57713db0d19fb453740195b20d0ec4bb2 Mon Sep 17 00:00:00 2001 From: yjnoh Date: Wed, 4 Jun 2025 08:54:00 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=84=9C=20=EB=B3=B5?= =?UTF-8?q?=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [작업내용] : 이미지 존재 여부 확인 후 복사 진행 --- .../api/image/estimate-image-copy/route.js | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/app/api/image/estimate-image-copy/route.js b/src/app/api/image/estimate-image-copy/route.js index 16984c8c..5d8a6348 100644 --- a/src/app/api/image/estimate-image-copy/route.js +++ b/src/app/api/image/estimate-image-copy/route.js @@ -12,28 +12,29 @@ const s3 = new S3Client({ }) export async function POST(req) { - try { - const { objectNo, planNo, newObjectNo, newPlanNo } = await req.json() + const { objectNo, planNo, newObjectNo, newPlanNo } = await req.json() - const responseArray = [] + const responseArray = [] - // const isExistImage1 = await s3.send( - // new GetObjectCommand({ - // Bucket, - // Key: `Drawing/${objectNo}_${planNo}_1.png`, - // }), - // ) + //견적서1 번 이미지 + const isExistImage1 = await s3.send( + new GetObjectCommand({ + Bucket, + Key: `Drawing/${objectNo}_${planNo}_1.png`, + }), + ) - // const isExistImage2 = await s3.send( - // new GetObjectCommand({ - // Bucket, - // Key: `Drawing/${objectNo}_${planNo}_1.png`, - // }), - // ) - - // console.log('🚀 ~ isExistImage1:', isExistImage1.$metadata.httpStatusCode === 200) - // console.log('🚀 ~ isExistImage2:', isExistImage2.$metadata.httpStatusCode === 200) + //견적서2 번 이미지 + const isExistImage2 = await s3.send( + new GetObjectCommand({ + Bucket, + Key: `Drawing/${objectNo}_${planNo}_1.png`, + }), + ) + //견적서1,2 번 이미지 둘다 있어야함 + if (isExistImage1.$metadata.httpStatusCode === 200 && isExistImage2.$metadata.httpStatusCode === 200) { + //견적서1 번 이미지 복사 const copyCommand = new CopyObjectCommand({ Bucket, CopySource: encodeURI(`${Bucket}/Drawing/${objectNo}_${planNo}_1.png`), @@ -52,8 +53,7 @@ export async function POST(req) { responseArray.push(response, response2) return NextResponse.json({ message: '견적서 이미지 복사 성공', responseArray }, { status: 200 }) - } catch (error) { - console.error(error) - return NextResponse.json({ message: '견적서 이미지 복사 실패' }, { status: 500 }) + } else { + return NextResponse.json({ message: '견적서 이미지 복사 실패(존재하지 않는 이미지)', responseArray }, { status: 400 }) } }