refactor: API Router 코드 일부 리팩토링

- 패턴에 어긋나는 응답 포맷 수정
- 주석 작성
This commit is contained in:
yoosangwook 2025-03-25 13:33:36 +09:00
parent 553a259c1f
commit 8d645d08dc
2 changed files with 16 additions and 4 deletions

View File

@ -36,7 +36,6 @@ export async function POST(req) {
const file = formData.get('file') const file = formData.get('file')
const result = await uploadImage(file) const result = await uploadImage(file)
result.message = '이미지 업로드 성공'
return NextResponse.json(result) return NextResponse.json(result)
} catch (error) { } catch (error) {

View File

@ -75,7 +75,10 @@ export async function POST(req) {
const OriginalKey = `Drawing/${uuidv4()}` const OriginalKey = `Drawing/${uuidv4()}`
// Upload original image /**
* 원본 이미지를 우선 저장한다.
* 이미지 이름이 겹지는 현상을 방지하기 위해 uuid 사용한다.
*/
await s3.send( await s3.send(
new PutObjectCommand({ new PutObjectCommand({
Bucket, Bucket,
@ -85,12 +88,19 @@ export async function POST(req) {
}), }),
) )
// Process the image /**
* 저장된 원본 이미지를 기준으로 크롭여부를 결정하여 크롭 이미지를 저장한다.
*/
const bufferImage = await cropImage(OriginalKey, width, height, left, top) const bufferImage = await cropImage(OriginalKey, width, height, left, top)
/**
* 크롭 이미지 이름을 결정한다.
*/
const Key = `Drawing/${objectNo}_${planNo}_${type}` const Key = `Drawing/${objectNo}_${planNo}_${type}`
// Upload processed image /**
* 크롭이 완료된 이미지를 업로드한다.
*/
await s3.send( await s3.send(
new PutObjectCommand({ new PutObjectCommand({
Bucket, Bucket,
@ -100,6 +110,9 @@ export async function POST(req) {
}), }),
) )
/**
* 크롭이미지 저장이 완료되면 원본 이미지를 삭제한다.
*/
await s3.send( await s3.send(
new DeleteObjectCommand({ new DeleteObjectCommand({
Bucket, Bucket,