@@ -162,6 +162,18 @@ export const downloadBlob = (data: Blob, filename: string) => {
162
162
URL . revokeObjectURL ( url ) ;
163
163
} ;
164
164
165
+ export const downloadUrl = ( url : string , filename : string ) => {
166
+ const anchor = document . createElement ( 'a' ) ;
167
+ anchor . href = url ;
168
+ anchor . download = filename ;
169
+
170
+ document . body . append ( anchor ) ;
171
+ anchor . click ( ) ;
172
+ anchor . remove ( ) ;
173
+
174
+ URL . revokeObjectURL ( url ) ;
175
+ } ;
176
+
165
177
export const downloadArchive = async ( fileName : string , options : Omit < DownloadInfoDto , 'archiveSize' > ) => {
166
178
const $preferences = get < UserPreferencesResponseDto | undefined > ( preferences ) ;
167
179
const dto = { ...options , archiveSize : $preferences ?. download . archiveSize } ;
@@ -238,33 +250,18 @@ export const downloadFile = async (asset: AssetResponseDto) => {
238
250
}
239
251
}
240
252
241
- for ( const { filename, id, size } of assets ) {
242
- const downloadKey = filename ;
243
-
253
+ for ( const { filename, id } of assets ) {
244
254
try {
245
- const abort = new AbortController ( ) ;
246
- downloadManager . add ( downloadKey , size , abort ) ;
247
255
const key = getKey ( ) ;
248
256
249
257
notificationController . show ( {
250
258
type : NotificationType . Info ,
251
259
message : $t ( 'downloading_asset_filename' , { values : { filename : asset . originalFileName } } ) ,
252
260
} ) ;
253
261
254
- // TODO use sdk once it supports progress events
255
- const { data } = await downloadRequest ( {
256
- method : 'GET' ,
257
- url : getBaseUrl ( ) + `/assets/${ id } /original` + ( key ? `?key=${ key } ` : '' ) ,
258
- signal : abort . signal ,
259
- onDownloadProgress : ( event ) => downloadManager . update ( downloadKey , event . loaded , event . total ) ,
260
- } ) ;
261
-
262
- downloadBlob ( data , filename ) ;
262
+ downloadUrl ( getBaseUrl ( ) + `/assets/${ id } /original` + ( key ? `?key=${ key } ` : '' ) , filename ) ;
263
263
} catch ( error ) {
264
264
handleError ( error , $t ( 'errors.error_downloading' , { values : { filename } } ) ) ;
265
- downloadManager . clear ( downloadKey ) ;
266
- } finally {
267
- setTimeout ( ( ) => downloadManager . clear ( downloadKey ) , 5000 ) ;
268
265
}
269
266
}
270
267
} ;
0 commit comments