@@ -23,23 +23,32 @@ import {
2323 useQuickSaveYoutubeContent ,
2424} from "../lib/tanstack/mutation/content" ;
2525
26- const getHtmlContent = async ( ) => {
26+ const createHtmlFile = ( htmlContent : string ) => {
27+ const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
28+ return new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
29+ } ;
30+
31+ // 현재 탭의 HTML과 썸네일 메타 정보를 읽어 저장에 필요한 파일과 데이터를 만든다.
32+ const getHtmlPayload = async ( ) => {
2733 const html = await getHtmlText ( ) ;
2834 const htmlContent = html . split ( "------MultipartBoundary--" ) [ 1 ] ;
2935
3036 if ( ! htmlContent ) {
3137 errorToast ( "잘못된 페이지에요. 다시 시도해주세요." ) ;
32- return { htmlContent : "" , thumbnail : "" } ;
38+ return null ;
3339 }
3440
3541 const thumbnail = extractMetaContent ( htmlContent , "og:image" ) ;
3642
37- if ( thumbnail === null ) {
43+ if ( ! thumbnail ) {
3844 errorToast ( "썸네일 추출 중 오류가 발생했어요. 다시 시도해주세요." ) ;
39- return { htmlContent : "" , thumbnail : "" } ;
45+ return null ;
4046 }
4147
42- return { htmlContent, thumbnail } ;
48+ return {
49+ htmlFile : createHtmlFile ( htmlContent ) ,
50+ thumbnail,
51+ } ;
4352} ;
4453
4554function LogoutDialogContent ( ) {
@@ -74,6 +83,7 @@ function LogoutDialogContent() {
7483 ) ;
7584}
7685
86+ // 현재 탭을 빠르게 저장하거나 요약 생성 플로우로 이어주는 북마크 저장 페이지.
7787export default function SearchContent ( ) {
7888 const { currentTab, isFindingExistPath } = useTabStore ( ) ;
7989
@@ -92,7 +102,7 @@ export default function SearchContent() {
92102 isPending : isPendingDetailSaveYoutubeContent ,
93103 } = useDetailSaveYoutubeContent ( ) ;
94104
95- const saveDisabledd =
105+ const isSaveDisabled =
96106 isFindingExistPath ||
97107 isPendingQuickSaveContent ||
98108 isPendingDetailSaveContent ||
@@ -108,12 +118,10 @@ export default function SearchContent() {
108118 url : currentTab . url ,
109119 } ) ;
110120 } else {
111- const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
112- if ( ! htmlContent || ! thumbnail ) return ;
113-
114- const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
115- const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
121+ const payload = await getHtmlPayload ( ) ;
122+ if ( ! payload ) return ;
116123
124+ const { htmlFile, thumbnail } = payload ;
117125 const formData = new FormData ( ) ;
118126
119127 formData . append ( "htmlFile" , htmlFile ) ;
@@ -139,12 +147,10 @@ export default function SearchContent() {
139147 } ,
140148 } ) ;
141149 } else {
142- const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
143- if ( ! htmlContent || ! thumbnail ) return ;
144-
145- const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
146- const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
150+ const payload = await getHtmlPayload ( ) ;
151+ if ( ! payload ) return ;
147152
153+ const { htmlFile, thumbnail } = payload ;
148154 const formData = new FormData ( ) ;
149155 formData . append ( "htmlFile" , htmlFile ) ;
150156
@@ -212,7 +218,7 @@ export default function SearchContent() {
212218 { /* 저장만 하기 */ }
213219 < Button
214220 onClick = { onSaveOnly }
215- disabled = { saveDisabledd }
221+ disabled = { isSaveDisabled }
216222 variant = "outline"
217223 size = "lg"
218224 className = "w-full justify-start"
@@ -232,7 +238,7 @@ export default function SearchContent() {
232238 { /* 요약과 함께 저장하기 */ }
233239 < Button
234240 onClick = { onSaveWithSummary }
235- disabled = { saveDisabledd }
241+ disabled = { isSaveDisabled }
236242 size = "lg"
237243 className = "w-full justify-start"
238244 aria-label = "요약과 함께 저장하기"
0 commit comments