@@ -112,7 +112,7 @@ class BackendResponse {
112112 return this . body ;
113113 }
114114 async getBlob ( ) {
115- return await this . response . blob ( ) ;
115+ return this . response . blob ( ) ;
116116 }
117117}
118118
@@ -2122,34 +2122,23 @@ class Component {
21222122 this . isRequestPending = false ;
21232123 this . backendRequest . promise . then ( async ( response ) => {
21242124 const backendResponse = new BackendResponse ( response ) ;
2125+ const headers = backendResponse . response . headers ;
21252126 for ( const input of Object . values ( this . pendingFiles ) ) {
21262127 input . value = '' ;
21272128 }
2128- const headers = backendResponse . response . headers ;
2129- if ( headers . get ( 'X-Live-Download' ) ) {
2130- if ( ! ( headers . get ( 'Content-Disposition' ) ?. includes ( 'attachment' ) ||
2131- headers . get ( 'Content-Disposition' ) ?. includes ( 'inline' ) ) ||
2132- ! headers . get ( 'Content-Disposition' ) ?. includes ( 'filename=' ) ) {
2133- throw new Error ( 'Invalid LiveDownload response' ) ;
2134- }
2135- const fileSize = Number . parseInt ( headers . get ( 'Content-Length' ) || '0' ) ;
2136- if ( fileSize > 10000000 ) {
2137- throw new Error ( 'File is too large to download (10MB limit)' ) ;
2138- }
2139- const fileName = headers . get ( 'Content-Disposition' ) ?. split ( 'filename=' ) [ 1 ] ;
2140- if ( ! fileName ) {
2141- throw new Error ( 'No filename found in Content-Disposition header' ) ;
2142- }
2129+ const contentDisposition = headers . get ( 'Content-Disposition' ) ;
2130+ const fileResponse = contentDisposition ?. match ( / ^ ( a t t a c h m e n t | i n l i n e ) .* f i l e n a m e = " ? ( [ ^ ; ] + ) " ? / ) ;
2131+ if ( fileResponse ) {
21432132 const blob = await backendResponse . getBlob ( ) ;
2144- const link = Object . assign ( window . document . createElement ( 'a' ) , {
2145- target : '_blank' ,
2133+ const link = Object . assign ( document . createElement ( 'a' ) , {
2134+ href : URL . createObjectURL ( blob ) ,
2135+ download : fileResponse [ 2 ] ,
21462136 style : 'display: none' ,
2147- href : window . URL . createObjectURL ( blob ) ,
2148- download : fileName ,
2137+ target : '_blank' ,
21492138 } ) ;
2150- this . element . appendChild ( link ) ;
2139+ document . body . appendChild ( link ) ;
21512140 link . click ( ) ;
2152- this . element . removeChild ( link ) ;
2141+ setTimeout ( ( ) => document . body . removeChild ( link ) , 75 ) ;
21532142 this . backendRequest = null ;
21542143 thisPromiseResolve ( backendResponse ) ;
21552144 if ( this . isRequestPending ) {
0 commit comments