@@ -140,6 +140,29 @@ export const fetchToGetImageBlob = async ({ imageUrl }: { imageUrl: string }): P
140140 return null
141141}
142142
143+ export const fetchToGetImageBlobByXHR = async ( { imageUrl } : { imageUrl : string } ) : Promise < null | Blob > => {
144+ if ( ! imageUrl ) return null
145+ try {
146+ const responseBlob = await new Promise < Blob | null > ( ( resolve , reject ) => {
147+ const xhr = new XMLHttpRequest ( )
148+ xhr . open ( 'get' , imageUrl )
149+ xhr . responseType = 'blob'
150+ xhr . onload = ( ) => {
151+ resolve ( xhr . response as Blob )
152+ }
153+ xhr . send ( )
154+ xhr . onerror = ( ) => {
155+ resolve ( null )
156+ }
157+ } )
158+ await sleep ( 3 * Math . random ( ) )
159+ return responseBlob
160+ } catch ( e ) {
161+ console . log ( `fetchToGetImageBlobByXHR` , e )
162+ }
163+ return null
164+ }
165+
143166export const fetchToGetVideoBlob = async ( { videoUrl } : { videoUrl : string } ) : Promise < null | Blob > => {
144167 if ( ! videoUrl ) return null
145168 try {
@@ -159,7 +182,7 @@ export const fetchToGetVideoBlob = async ({ videoUrl }: { videoUrl: string }): P
159182 await sleep ( 3 * Math . random ( ) )
160183 return respBlob
161184 } catch ( e ) {
162- console . log ( `fetchToGetImageBlob ` , e )
185+ console . log ( `fetchToGetVideoBlob ` , e )
163186 }
164187 return null
165188}
@@ -181,7 +204,7 @@ export const fetchToGetVideoBlobByXHR = async ({ videoUrl }: { videoUrl: string
181204 } )
182205 return responseBlob
183206 } catch ( e ) {
184- console . log ( `fetchToGetImageBlob ` , e )
207+ console . log ( `fetchToGetVideoBlobByXHR ` , e )
185208 }
186209 return null
187210}
@@ -200,7 +223,7 @@ export const fetchToGetLongText = async ({ mblogId }: { mblogId?: string }) => {
200223 await sleep ( 3 * Math . random ( ) )
201224 return longTextContent || null
202225 } catch ( e ) {
203- console . log ( `fetchToGetImageBlob ` , e )
226+ console . log ( `fetchToGetLongText ` , e )
204227 }
205228 return null
206229}
0 commit comments