@@ -1138,10 +1138,11 @@ export class ApiService {
11381138
11391139 downloadRecording ( recording : Recording ) : void {
11401140 this . ctx . url ( recording . downloadUrl ) . subscribe ( ( resourceUrl ) => {
1141- this . downloadFile ( resourceUrl , recording . name + ( recording . name . endsWith ( '.jfr' ) ? '' : '.jfr' ) ) ;
1141+ const jfrFilename = recording . name + ( recording . name . endsWith ( '.jfr' ) ? '' : '.jfr' ) ;
1142+ this . downloadFile ( resourceUrl , new URLSearchParams ( { filename : jfrFilename } ) , jfrFilename ) ;
11421143
11431144 const metadataUrl = createBlobURL ( JSON . stringify ( recording . metadata ) , 'application/json' ) ;
1144- this . downloadFile ( metadataUrl , recording . name . replace ( / \. j f r $ / , '' ) + '.metadata.json' , false ) ;
1145+ this . downloadFile ( metadataUrl , undefined , recording . name . replace ( / \. j f r $ / , '' ) + '.metadata.json' , false ) ;
11451146 setTimeout ( ( ) => URL . revokeObjectURL ( metadataUrl ) , 1000 ) ;
11461147 } ) ;
11471148 }
@@ -1154,24 +1155,17 @@ export class ApiService {
11541155 first ( ) ,
11551156 ) ;
11561157 filename . subscribe ( ( name ) => {
1157- resourceUrl += `?filename=${ name } ` ;
1158- this . downloadFile ( resourceUrl , name ) ;
1158+ this . downloadFile ( resourceUrl , new URLSearchParams ( { filename : name } ) , name ) ;
11591159 } ) ;
11601160 } ) ;
11611161 }
11621162
11631163 downloadHeapDump ( heapDump : HeapDump ) : void {
1164- this . ctx . url ( heapDump . downloadUrl ) . subscribe ( ( resourceUrl ) => {
1165- let filename = this . target . target ( ) . pipe (
1166- filter ( ( t ) => ! ! t ) ,
1167- map ( ( ) => `${ heapDump . heapDumpId } ` ) ,
1168- first ( ) ,
1164+ this . ctx
1165+ . url ( heapDump . downloadUrl )
1166+ . subscribe ( ( resourceUrl ) =>
1167+ this . downloadFile ( resourceUrl , new URLSearchParams ( { filename : heapDump . heapDumpId } ) , heapDump . heapDumpId ) ,
11691168 ) ;
1170- filename . subscribe ( ( name ) => {
1171- resourceUrl += `?filename=${ name } ` ;
1172- this . downloadFile ( resourceUrl , name ) ;
1173- } ) ;
1174- } ) ;
11751169 }
11761170
11771171 downloadTemplate ( template : EventTemplate ) : void {
@@ -1199,7 +1193,7 @@ export class ApiService {
11991193 return ;
12001194 }
12011195 url . subscribe ( ( resourceUrl ) => {
1202- this . downloadFile ( resourceUrl , `${ template . name } .jfc` ) ;
1196+ this . downloadFile ( resourceUrl , undefined , `${ template . name } .jfc` ) ;
12031197 } ) ;
12041198 }
12051199
@@ -1210,7 +1204,7 @@ export class ApiService {
12101204 const filename = `${ rule . name } .json` ;
12111205 const file = new File ( [ JSON . stringify ( rule ) ] , filename ) ;
12121206 const resourceUrl = URL . createObjectURL ( file ) ;
1213- this . downloadFile ( resourceUrl , filename , false ) ;
1207+ this . downloadFile ( resourceUrl , undefined , filename , false ) ;
12141208 setTimeout ( ( ) => URL . revokeObjectURL ( resourceUrl ) , 1000 ) ;
12151209 } ) ;
12161210 }
@@ -1917,7 +1911,7 @@ export class ApiService {
19171911 const stringifiedSerializedLayout = this . stringifyLayoutTemplate ( template ) ;
19181912 const filename = `cryostat-dashboard-${ template . name } .json` ;
19191913 const resourceUrl = createBlobURL ( stringifiedSerializedLayout , 'application/json' ) ;
1920- this . downloadFile ( resourceUrl , filename , false ) ;
1914+ this . downloadFile ( resourceUrl , undefined , filename , false ) ;
19211915 }
19221916
19231917 private stringifyLayoutTemplate ( template : LayoutTemplate ) : string {
@@ -1953,14 +1947,17 @@ export class ApiService {
19531947 ) ;
19541948 }
19551949
1956- private downloadFile ( url : string , filename : string , headers = true ) : void {
1950+ private downloadFile ( url : string , query : URLSearchParams | undefined , filename : string , headers = true ) : void {
19571951 const o = headers ? this . instanceSelectorHeadersAsQuery ( ) : of ( '' ) ;
19581952 o . subscribe ( ( q ) => {
19591953 const anchor = document . createElement ( 'a' ) ;
19601954 anchor . setAttribute ( 'style' , 'display: none; visibility: hidden;' ) ;
19611955 anchor . target = '_blank' ;
19621956 let href = url ;
19631957 anchor . download = filename ;
1958+ if ( query ) {
1959+ href . includes ( '?' ) ? ( href += `&${ query . toString ( ) } ` ) : ( href += `?${ query . toString ( ) } ` ) ;
1960+ }
19641961 if ( q ) {
19651962 href . includes ( '?' ) ? ( href += `&${ q } ` ) : ( href += `?${ q } ` ) ;
19661963 }
0 commit comments