@@ -112,7 +112,7 @@ class BackendResponse {
112
112
return this . body ;
113
113
}
114
114
async getBlob ( ) {
115
- return await this . response . blob ( ) ;
115
+ return this . response . blob ( ) ;
116
116
}
117
117
}
118
118
@@ -2122,34 +2122,23 @@ class Component {
2122
2122
this . isRequestPending = false ;
2123
2123
this . backendRequest . promise . then ( async ( response ) => {
2124
2124
const backendResponse = new BackendResponse ( response ) ;
2125
+ const headers = backendResponse . response . headers ;
2125
2126
for ( const input of Object . values ( this . pendingFiles ) ) {
2126
2127
input . value = '' ;
2127
2128
}
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 ) {
2143
2132
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 ] ,
2146
2136
style : 'display: none' ,
2147
- href : window . URL . createObjectURL ( blob ) ,
2148
- download : fileName ,
2137
+ target : '_blank' ,
2149
2138
} ) ;
2150
- this . element . appendChild ( link ) ;
2139
+ document . body . appendChild ( link ) ;
2151
2140
link . click ( ) ;
2152
- this . element . removeChild ( link ) ;
2141
+ setTimeout ( ( ) => document . body . removeChild ( link ) , 75 ) ;
2153
2142
this . backendRequest = null ;
2154
2143
thisPromiseResolve ( backendResponse ) ;
2155
2144
if ( this . isRequestPending ) {
0 commit comments