@@ -228,32 +228,43 @@ export class ApiService {
228228 onUploadProgress ?: ( progress : string | number ) => void ,
229229 abortSignal ?: Observable < void > ,
230230 ) : Observable < boolean > {
231+ const body = new window . FormData ( ) ;
232+ Object . entries ( rule ) . forEach ( ( e ) => {
233+ if ( ! e || ! e [ 0 ] || ! e [ 1 ] ) {
234+ return ;
235+ }
236+ if ( e [ 0 ] === 'metadata' ) {
237+ const labels = { } ;
238+ e [ 1 ] . labels . forEach ( ( kv : KeyValue ) => {
239+ labels [ kv . key ] = kv . value ;
240+ } ) ;
241+ body . append ( e [ 0 ] , JSON . stringify ( { labels } ) ) ;
242+ } else {
243+ body . append ( e [ 0 ] , e [ 1 ] ) ;
244+ }
245+ } ) ;
231246 window . onbeforeunload = ( event : BeforeUnloadEvent ) => event . preventDefault ( ) ;
232- return this . ctx
233- . headers ( {
234- 'Content-Type' : 'application/json' ,
235- } )
236- . pipe (
237- concatMap ( ( headers ) =>
238- this . sendLegacyRequest ( 'v4' , 'rules' , 'Rule Upload Failed' , {
239- method : 'POST' ,
240- body : JSON . stringify ( rule ) ,
241- headers,
242- listeners : {
243- onUploadProgress : ( event ) => {
244- onUploadProgress && onUploadProgress ( Math . floor ( ( event . loaded * 100 ) / event . total ) ) ;
245- } ,
247+ return this . ctx . headers ( ) . pipe (
248+ concatMap ( ( headers ) =>
249+ this . sendLegacyRequest ( 'v4' , 'rules' , 'Rule Upload Failed' , {
250+ body,
251+ method : 'POST' ,
252+ headers,
253+ listeners : {
254+ onUploadProgress : ( event ) => {
255+ onUploadProgress && onUploadProgress ( Math . floor ( ( event . loaded * 100 ) / event . total ) ) ;
246256 } ,
247- abortSignal,
248- } ) ,
249- ) ,
250- map ( ( resp ) => resp . ok ) ,
251- tap ( {
252- next : ( ) => ( window . onbeforeunload = null ) ,
253- error : ( ) => ( window . onbeforeunload = null ) ,
257+ } ,
258+ abortSignal,
254259 } ) ,
255- first ( ) ,
256- ) ;
260+ ) ,
261+ map ( ( resp ) => resp . ok ) ,
262+ tap ( {
263+ next : ( ) => ( window . onbeforeunload = null ) ,
264+ error : ( ) => ( window . onbeforeunload = null ) ,
265+ } ) ,
266+ first ( ) ,
267+ ) ;
257268 }
258269
259270 createRule ( rule : Rule ) : Observable < boolean > {
0 commit comments