From f07413bcec9f17795ad91727aa0974264c26ba03 Mon Sep 17 00:00:00 2001 From: imddoy Date: Fri, 5 Jun 2026 17:53:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EA=B3=B5=EC=97=B0=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/register/Register.tsx | 156 ++++++++++++++++---------------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/src/pages/register/Register.tsx b/src/pages/register/Register.tsx index 2f22034f..82c932ae 100644 --- a/src/pages/register/Register.tsx +++ b/src/pages/register/Register.tsx @@ -180,95 +180,99 @@ const Register = () => { }; const { data, refetch } = useGetPresignedUrl(params); - const { mutate } = usePutS3Upload(); + const { mutateAsync: uploadToS3 } = usePutS3Upload(); const { mutateAsync: postPerformance, isPending } = usePostPerformance(); + const uploadFileToS3 = async (presignedUrl: string, localUrl: string) => { + const response = await fetch(localUrl); + const blob = await response.blob(); + const file = new File([blob], `fileName-${new Date()}`, { type: blob.type }); + await uploadToS3({ url: presignedUrl, file }); + }; + const handleComplete = async () => { if (isPending) { return; } const { data, isSuccess } = await refetch(); + if (!isSuccess) { + return; + } - let posterUrls; - let castUrls; - let staffUrls; - let performanceUrls; - - if (isSuccess) { - const extractUrls = (data: PresignedResponse) => { - posterUrls = Object.values(data.poster).map((url) => url.split("?")[0]); - castUrls = Object.values(data.cast).map((url) => (url !== "" ? url.split("?")[0] : null)); - staffUrls = Object.values(data.staff).map((url) => (url !== "" ? url.split("?")[0] : null)); - performanceUrls = Object.values(data.performance).map((url) => url.split("?")[0]); - - return [ - ...posterUrls, - ...castUrls.filter((url) => url !== null), - ...staffUrls.filter((url) => url !== null), - ...performanceUrls, - ]; + const posterPresigned = Object.values(data.poster); + const castPresigned = Object.values(data.cast); + const staffPresigned = Object.values(data.staff); + const performancePresigned = Object.values(data.performance); + + try { + await uploadFileToS3(posterPresigned[0], gigInfo.posterImage); + + const castUrls = await Promise.all( + gigInfo.castList.map(async (cast, index) => { + if (!cast.castPhoto) { + return ""; + } + await uploadFileToS3(castPresigned[index], cast.castPhoto); + return castPresigned[index].split("?")[0]; + }) + ); + + const staffUrls = await Promise.all( + gigInfo.staffList.map(async (staff, index) => { + if (!staff.staffPhoto) { + return ""; + } + await uploadFileToS3(staffPresigned[index], staff.staffPhoto); + return staffPresigned[index].split("?")[0]; + }) + ); + + const performanceUrls = await Promise.all( + gigInfo.performanceImageList.map(async (image, index) => { + await uploadFileToS3(performancePresigned[index], image.performanceImage); + return performancePresigned[index].split("?")[0]; + }) + ); + + const formData = { + ...gigInfo, + posterImage: posterPresigned[0].split("?")[0], + castList: gigInfo.castList.map((cast, index) => ({ + ...cast, + castPhoto: castUrls[index], + })), + staffList: gigInfo.staffList.map((staff, index) => ({ + ...staff, + staffPhoto: staffUrls[index], + })), + performanceImageList: performanceUrls.map((url) => ({ + performanceImage: url, + })), + scheduleList: gigInfo.scheduleList.map((schedule) => { + const date = dayjs(schedule.performanceDate).toDate(); + const offset = date.getTimezoneOffset() * 60000; + const dateOffset = new Date(date.getTime() - offset); + return { + ...schedule, + performanceDate: dateOffset.toISOString(), + }; + }), + bankName: bankInfo ? bankInfo : "NONE", }; - const S3Urls = extractUrls(data); - - const files = [ - gigInfo.posterImage, - ...gigInfo.castList.map((cast) => cast.castPhoto).filter((photo) => photo !== ""), - ...gigInfo.staffList.map((staff) => staff.staffPhoto).filter((photo) => photo !== ""), - ...gigInfo.performanceImageList.map((image) => image.performanceImage), - ]; try { - const res = await Promise.all( - S3Urls.map(async (url, index) => { - const file = files[index]; - - const response = await fetch(file); - const blob = await response.blob(); - const newFile = new File([blob], `fileName-${new Date()}`, { type: blob.type }); - - return mutate({ url, file: newFile }); - }) - ); - - const formData = { - ...gigInfo, - posterImage: posterUrls[0], - castList: gigInfo.castList.map((cast, index) => ({ - ...cast, - castPhoto: cast.castPhoto === "" ? "" : castUrls[index] || cast.castPhoto, - })), - staffList: gigInfo.staffList.map((staff, index) => ({ - ...staff, - staffPhoto: staff.staffPhoto === "" ? "" : staffUrls[index] || staff.staffPhoto, - })), - scheduleList: gigInfo.scheduleList.map((schedule) => { - const date = dayjs(schedule.performanceDate).toDate(); - const offset = date.getTimezoneOffset() * 60000; //ms 단위로 변환 - const dateOffset = new Date(date.getTime() - offset); - return { - ...schedule, - performanceDate: dateOffset.toISOString(), - }; - }), - bankName: bankInfo ? bankInfo : "NONE", - performanceImageList: gigInfo.performanceImageList.map((image, index) => ({ - performanceImage: performanceUrls[index] || image.performanceImage, - })), - }; - try { - await postPerformance(formData); - } catch (err) { - console.error("공연 등록 오류:", err); - const errorMessage = - err?.response?.status === 401 - ? "로그인 세션이 만료되었습니다.\n 다시 로그인 후 시도해주세요." - : "공연 등록을 실패했습니다.\n 다시 시도해주세요."; - - openAlert({ title: errorMessage }); - } + await postPerformance(formData); } catch (err) { - console.error("파일 업로드 중 오류 발생:", err); + console.error("공연 등록 오류:", err); + const errorMessage = + err?.response?.status === 401 + ? "로그인 세션이 만료되었습니다.\n 다시 로그인 후 시도해주세요." + : "공연 등록을 실패했습니다.\n 다시 시도해주세요."; + openAlert({ title: errorMessage }); } + } catch (err) { + console.error("파일 업로드 중 오류 발생:", err); + openAlert({ title: "이미지 업로드에 실패했습니다.\n 다시 시도해주세요." }); } }; From be936470f3e68cff6c9de569419a5707439cc73a Mon Sep 17 00:00:00 2001 From: imddoy Date: Fri, 5 Jun 2026 18:08:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=BD=94=EB=93=9C=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/register/Register.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pages/register/Register.tsx b/src/pages/register/Register.tsx index 82c932ae..e39e010a 100644 --- a/src/pages/register/Register.tsx +++ b/src/pages/register/Register.tsx @@ -187,7 +187,11 @@ const Register = () => { const response = await fetch(localUrl); const blob = await response.blob(); const file = new File([blob], `fileName-${new Date()}`, { type: blob.type }); - await uploadToS3({ url: presignedUrl, file }); + const result = await uploadToS3({ url: presignedUrl, file }); + + if (!result) { + throw new Error("S3 업로드 실패"); + } }; const handleComplete = async () => { @@ -195,7 +199,8 @@ const Register = () => { return; } const { data, isSuccess } = await refetch(); - if (!isSuccess) { + if (!isSuccess || !data) { + openAlert({ title: "이미지 업로드에 실패했습니다.\n 다시 시도해주세요." }); return; }