@@ -22,6 +22,7 @@ import * as postAPI from "@/api/post";
2222import FileAttachmentViewer from "./FileAttachmentViewer" ;
2323import FilePreviewModal from "./FilePreviewModal" ;
2424import PostDetailTopSection from "./PostDetailTopSection" ;
25+ import { downloadAttachment } from "@/utils/downloadUtils" ;
2526
2627export default function PostDetailDrawer ( {
2728 open,
@@ -78,44 +79,8 @@ export default function PostDetailDrawer({
7879 } ;
7980
8081 // 파일 다운로드
81- const handleDownload = async ( attachment ) => {
82- try {
83- // 다운로드 URL 발급 API 호출
84- const response = await postAPI . getAttachmentDownloadUrl ( attachment . id ) ;
85-
86- if ( response . data . result === "SUCCESS" ) {
87- const downloadUrl = response . data . data . downloadUrl ;
88-
89- // S3에서 파일 다운로드 후 브라우저에서 다운로드
90- const fileResponse = await fetch ( downloadUrl ) ;
91- if ( ! fileResponse . ok ) {
92- throw new Error ( `파일 다운로드 실패: ${ fileResponse . status } ` ) ;
93- }
94-
95- // Blob으로 변환
96- const blob = await fileResponse . blob ( ) ;
97-
98- // Blob URL 생성하여 다운로드
99- const blobUrl = URL . createObjectURL ( blob ) ;
100- const link = document . createElement ( "a" ) ;
101- link . href = blobUrl ;
102- link . download = attachment . fileName ; // 파일명 지정
103- link . style . display = "none" ;
104-
105- // DOM에 추가 후 클릭하여 다운로드 실행
106- document . body . appendChild ( link ) ;
107- link . click ( ) ;
108-
109- // 정리
110- document . body . removeChild ( link ) ;
111- URL . revokeObjectURL ( blobUrl ) ; // 메모리 정리
112- } else {
113- throw new Error ( "다운로드 URL 발급 실패" ) ;
114- }
115- } catch ( error ) {
116- console . error ( "파일 다운로드 실패:" , error ) ;
117- alert ( "파일 다운로드에 실패했습니다." ) ;
118- }
82+ const handleDownload = ( attachment ) => {
83+ downloadAttachment ( attachment , postAPI . getAttachmentDownloadUrl ) ;
11984 } ;
12085
12186 useEffect ( ( ) => {
0 commit comments