견적서 복사 -> 이미지 복사 로직 추가
This commit is contained in:
parent
84c18c80f0
commit
639c057e0c
42
src/app/api/image/estimate-image-copy/route.js
Normal file
42
src/app/api/image/estimate-image-copy/route.js
Normal file
@ -0,0 +1,42 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { S3Client, CopyObjectCommand } from '@aws-sdk/client-s3'
|
||||
import sharp from 'sharp'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
const Bucket = process.env.AMPLIFY_BUCKET
|
||||
const s3 = new S3Client({
|
||||
region: process.env.AWS_REGION,
|
||||
credentials: {
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
},
|
||||
})
|
||||
|
||||
export async function POST(req) {
|
||||
try {
|
||||
const { objectNo, planNo, newObjectNo, newPlanNo } = await req.json()
|
||||
|
||||
const responseArray = []
|
||||
|
||||
const copyCommand = new CopyObjectCommand({
|
||||
Bucket,
|
||||
CopySource: encodeURI(`${Bucket}/Drawing/${objectNo}_${planNo}_1.png`),
|
||||
Key: `Drawing/${newObjectNo}_${newPlanNo}_1.png`,
|
||||
})
|
||||
|
||||
const response = await s3.send(copyCommand)
|
||||
|
||||
const copyCommand2 = new CopyObjectCommand({
|
||||
Bucket,
|
||||
CopySource: encodeURI(`${Bucket}/Drawing/${objectNo}_${planNo}_2.png`),
|
||||
Key: `Drawing/${newObjectNo}_${newPlanNo}_2.png`,
|
||||
})
|
||||
|
||||
const response2 = await s3.send(copyCommand2)
|
||||
|
||||
responseArray.push(response, response2)
|
||||
return NextResponse.json({ message: '견적서 이미지 복사 성공', responseArray }, { status: 200 })
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return NextResponse.json({ message: '견적서 이미지 복사 실패' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,8 @@ import { useSwal } from '@/hooks/useSwal'
|
||||
// Constants
|
||||
const ESTIMATE_API_ENDPOINT = '/api/estimate' // API 엔드포인트 정의
|
||||
|
||||
import Config from '@/config/config.export'
|
||||
|
||||
// Helper functions
|
||||
const updateItemInList = (itemList, dispOrder, updates) => {
|
||||
return itemList.map((item) => (item.dispOrder === dispOrder ? { ...item, ...updates } : item))
|
||||
@ -464,11 +466,13 @@ export const useEstimateController = (planNo, flag) => {
|
||||
|
||||
setIsGlobalLoading(true)
|
||||
await promisePost({ url: '/api/estimate/save-estimate-copy', data: params })
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
setIsGlobalLoading(false)
|
||||
if (res.status === 201) {
|
||||
if (isObjectNotEmpty(res.data)) {
|
||||
let newObjectNo = res.data.objectNo
|
||||
const copyImage = await handleEstimateImageCopy(params.objectNo, params.planNo, newObjectNo, '1')
|
||||
|
||||
swalFire({
|
||||
text: getMessage('estimate.detail.estimateCopyPopup.copy.alertMessage'),
|
||||
type: 'alert',
|
||||
@ -489,6 +493,14 @@ export const useEstimateController = (planNo, flag) => {
|
||||
})
|
||||
}
|
||||
|
||||
const handleEstimateImageCopy = async (objectNo, planNo, newObjectNo, newPlanNo) => {
|
||||
await promisePost({ url: `${Config().baseUrl}/api/image/estimate-image-copy`, data: { objectNo, planNo, newObjectNo, newPlanNo } }).then(
|
||||
(res) => {
|
||||
return res
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const handleDeleteEstimate = async (canvasStatus) => {
|
||||
try {
|
||||
setIsGlobalLoading(true)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user