📌fix: 이미지 불러오기 기능 수정

This commit is contained in:
yoosangwook 2025-02-06 16:55:17 +09:00
parent f194eb603c
commit 70c3956625

View File

@ -66,15 +66,20 @@ export function useRefFiles() {
} }
const refFileSetting = (file) => { const refFileSetting = (file) => {
if (file && ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif'].includes(file.type)) { console.log('🚀 ~ refFileSetting ~ file:', file)
// setRefImage(file) if (file.name.split('.').pop() === 'dwg') {
file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file) handleUploadConvertRefFile(file)
} else { } else {
swalFire({ if (file && ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif'].includes(file.type)) {
text: '이미지가 아닙니다.', // file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file)
type: 'alert', handleUploadImageRefFile(file)
icon: 'error', } else {
}) swalFire({
text: '이미지가 아닙니다.',
type: 'alert',
icon: 'error',
})
}
} }
} }
/** /**
@ -121,14 +126,13 @@ export function useRefFiles() {
} }
const res = await get({ const res = await get({
url: `http://localhost:3000/api/html2canvas?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`, url: `${process.env.NEXT_PUBLIC_HOST_URL}/map/convert?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`,
}) })
console.log('🚀 ~ handleMapImageDown ~ res:', res) console.log('🚀 ~ handleMapImageDown ~ res:', res)
const file = await readImage(res.fileNm) // const file = await readImage(res.fileNm)
console.log('🚀 ~ handleMapImageDown ~ file:', file) // console.log('🚀 ~ handleMapImageDown ~ file:', file)
setCurrentBgImage(file) // setCurrentBgImage(file)
// handleBackImageLoadToCanvas(`plan-images/${currentCanvasPlan.id}.png`) setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`)
// setCurrentCanvasPlan((prev) => ({ ...prev, bgImageName: currentCanvasPlan.id, mapPositionAddress: queryRef.current.value }))
} }
/** /**
@ -158,7 +162,6 @@ export function useRefFiles() {
console.log('🚀 ~ handleUploadImageRefFile ~ res:', res) console.log('🚀 ~ handleUploadImageRefFile ~ res:', res)
// const image = await readImage(res.filePath) // const image = await readImage(res.filePath)
// console.log('🚀 ~ handleUploadImageRefFile ~ file:', image) // console.log('🚀 ~ handleUploadImageRefFile ~ file:', image)
setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`) setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${res.filePath}`)
setRefImage(file) setRefImage(file)
} }
@ -171,15 +174,21 @@ export function useRefFiles() {
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
await promisePost({ url: converterUrl, data: formData }) const res = await post({ url: converterUrl, data: formData })
.then((res) => { console.log('🚀 ~ handleUploadConvertRefFile ~ res:', res)
convertDwgToPng(res.data.Files[0].FileName, res.data.Files[0].FileData) const result = await post({ url: `${process.env.NEXT_PUBLIC_HOST_URL}/cad/convert`, data: res })
swalFire({ text: '파일 변환 성공' }) console.log('🚀 ~ handleUploadConvertRefFile ~ result:', result)
setRefImage(res.data.Files[0].FileData) setCurrentBgImage(`${process.env.NEXT_PUBLIC_HOST_URL}${result.filePath}`)
}) setRefImage(res.Files[0].FileData)
.catch((err) => { // await promisePost({ url: converterUrl, data: formData })
swalFire({ text: '파일 변환 실패', icon: 'error' }) // .then((res) => {
}) // convertDwgToPng(res.data.Files[0].FileName, res.data.Files[0].FileData)
// swalFire({ text: '파일 변환 성공' })
// setRefImage(res.data.Files[0].FileData)
// })
// .catch((err) => {
// swalFire({ text: '파일 변환 실패', icon: 'error' })
// })
} }
/** /**