feat: 구글 맵 컨버트 기능 추가
This commit is contained in:
parent
a7b9062154
commit
2492b45a66
68
src/app/api/image/map/route.js
Normal file
68
src/app/api/image/map/route.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
export async function GET(req) {
|
||||||
|
try {
|
||||||
|
const searchParams = req.nextUrl.searchParams
|
||||||
|
const q = searchParams.get('q')
|
||||||
|
const fileNm = searchParams.get('fileNm')
|
||||||
|
const zoom = searchParams.get('zoom')
|
||||||
|
|
||||||
|
/** 구글 맵을 이미지로 변경하기 위한 API */
|
||||||
|
const API_KEY = 'AIzaSyDO7nVR1N_D2tKy60hgGFavpLaXkHpiHpc'
|
||||||
|
const targetUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${q}&zoom=${zoom}&maptype=satellite&size=640x640&scale=1&key=${API_KEY}`
|
||||||
|
const decodeUrl = decodeURIComponent(targetUrl)
|
||||||
|
|
||||||
|
/** 구글 맵을 이미지로 변경하기 위한 API 호출 */
|
||||||
|
const response = await fetch(decodeUrl)
|
||||||
|
const data = await response.arrayBuffer()
|
||||||
|
// const buffer = Buffer.from(data)
|
||||||
|
|
||||||
|
/** 변경된 이미지를 S3에 업로드 */
|
||||||
|
const Body = Buffer.from(data)
|
||||||
|
const Key = `map/${file.name}`
|
||||||
|
const ContentType = 'image/png'
|
||||||
|
|
||||||
|
await s3.send(
|
||||||
|
new PutObjectCommand({
|
||||||
|
Bucket,
|
||||||
|
Key,
|
||||||
|
Body,
|
||||||
|
ContentType,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
filePath: `https://${process.env.AMPLIFY_BUCKET}.s3.${process.env.AWS_REGION}.amazonaws.com/${Key}`,
|
||||||
|
fileName: Key,
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(result)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return NextResponse.json({ error: 'Failed to upload image' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(req) {
|
||||||
|
try {
|
||||||
|
const searchParams = req.nextUrl.searchParams
|
||||||
|
const Key = `map/${searchParams.get('fileName')}`
|
||||||
|
console.log('🚀 ~ DELETE ~ Key:', Key)
|
||||||
|
|
||||||
|
if (!Key) {
|
||||||
|
return NextResponse.json({ error: 'fileName parameter is required' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
await s3.send(
|
||||||
|
new DeleteObjectCommand({
|
||||||
|
Bucket,
|
||||||
|
Key,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return NextResponse.json({ message: '이미지 삭제 성공' }, { status: 200 })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('S3 Delete Error:', error)
|
||||||
|
return NextResponse.json({ error: 'Failed to delete image' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -105,6 +105,9 @@ export function useRefFiles() {
|
|||||||
text: '삭제하시겠습니까?',
|
text: '삭제하시겠습니까?',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
confirmFn: async () => {
|
confirmFn: async () => {
|
||||||
|
console.log('🚀 ~ handleAddressDelete ~ handleAddressDelete:', refImage)
|
||||||
|
console.log('🚀 ~ handleAddressDelete ~ currentCanvasPlan.bgImageName:', currentCanvasPlan.bgImageName)
|
||||||
|
await del({ url: `http://localhost:3000/api/image/map?fileName=${currentCanvasPlan.bgImageName}` })
|
||||||
setMapPositionAddress('')
|
setMapPositionAddress('')
|
||||||
setCurrentBgImage(null)
|
setCurrentBgImage(null)
|
||||||
setCurrentCanvasPlan((prev) => ({ ...prev, mapPositionAddress: null }))
|
setCurrentCanvasPlan((prev) => ({ ...prev, mapPositionAddress: null }))
|
||||||
@ -135,16 +138,21 @@ export function useRefFiles() {
|
|||||||
option1: newOption1,
|
option1: newOption1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// const res = await get({
|
||||||
|
// url: `${process.env.NEXT_PUBLIC_HOST_URL}/map/convert?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`,
|
||||||
|
// })
|
||||||
const res = await get({
|
const res = await get({
|
||||||
url: `${process.env.NEXT_PUBLIC_HOST_URL}/map/convert?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`,
|
url: `http://localhost:3000/api/map/upload?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`,
|
||||||
})
|
})
|
||||||
console.log('🚀 ~ handleMapImageDown ~ res:', res)
|
console.log('🚀 ~ handleMapImageDown ~ res:', res)
|
||||||
setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`)
|
// setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`)
|
||||||
|
setCurrentBgImage(`${res.filePath}`)
|
||||||
|
|
||||||
await setBackGroundImage({
|
await setBackGroundImage({
|
||||||
objectId: currentCanvasPlan.id,
|
objectId: currentCanvasPlan.id,
|
||||||
planNo: currentCanvasPlan.planNo,
|
planNo: currentCanvasPlan.planNo,
|
||||||
imagePath: `${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`,
|
// imagePath: `${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`,
|
||||||
|
imagePath: `${res.filePath}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user