@@ -401,6 +401,29 @@ const (
401401 indexCacheControlHeader = "no-cache, max-age=0, must-revalidate"
402402)
403403
404+ func upsertIndexMetaTag (indexContent []byte , metaName string , metaTag string ) []byte {
405+ metaMarker := []byte (fmt .Sprintf (`name="%s"` , metaName ))
406+ updated := false
407+
408+ if idx := bytes .Index (indexContent , metaMarker ); idx >= 0 {
409+ start := bytes .LastIndex (indexContent [:idx ], []byte ("<meta" ))
410+ if start >= 0 {
411+ endRel := bytes .IndexByte (indexContent [idx :], '>' )
412+ if endRel >= 0 {
413+ end := idx + endRel + 1
414+ indexContent = append (indexContent [:start ], append ([]byte (metaTag ), indexContent [end :]... )... )
415+ updated = true
416+ }
417+ }
418+ }
419+
420+ if ! updated && bytes .Contains (indexContent , []byte ("</head>" )) {
421+ indexContent = bytes .Replace (indexContent , []byte ("</head>" ), []byte (metaTag + "\n </head>" ), 1 )
422+ }
423+
424+ return indexContent
425+ }
426+
404427func registerFrontendRoutes (r * gin.Engine , frontendDistDir string , appVersion string ) error {
405428 assetsFS , sourceName , err := frontendAssetFS (frontendDistDir )
406429 if err != nil {
@@ -417,23 +440,22 @@ func registerFrontendRoutes(r *gin.Engine, frontendDistDir string, appVersion st
417440 log .Printf ("Invalid SBPM_NODES_VIRTUAL_THRESHOLD=%d, using default 50" , nodesVirtualThreshold )
418441 nodesVirtualThreshold = 50
419442 }
420- metaName := []byte (`name="sbpm-nodes-virtual-threshold"` )
421- meta := fmt .Sprintf (` <meta name="sbpm-nodes-virtual-threshold" content="%d" />` , nodesVirtualThreshold )
422- thresholdUpdated := false
423- if idx := bytes .Index (indexContent , metaName ); idx >= 0 {
424- start := bytes .LastIndex (indexContent [:idx ], []byte ("<meta" ))
425- if start >= 0 {
426- endRel := bytes .IndexByte (indexContent [idx :], '>' )
427- if endRel >= 0 {
428- end := idx + endRel + 1
429- indexContent = append (indexContent [:start ], append ([]byte (meta ), indexContent [end :]... )... )
430- thresholdUpdated = true
431- }
432- }
433- }
434- if ! thresholdUpdated && bytes .Contains (indexContent , []byte ("</head>" )) {
435- indexContent = bytes .Replace (indexContent , []byte ("</head>" ), []byte (meta + "\n </head>" ), 1 )
436- }
443+ nodesVirtualThresholdMeta := fmt .Sprintf (
444+ ` <meta name="sbpm-nodes-virtual-threshold" content="%d" />` ,
445+ nodesVirtualThreshold ,
446+ )
447+ indexContent = upsertIndexMetaTag (indexContent , "sbpm-nodes-virtual-threshold" , nodesVirtualThresholdMeta )
448+
449+ batchCheckIPConcurrency := readIntEnv ("SBPM_BATCH_CHECK_IP_CONCURRENCY" , 10 )
450+ if batchCheckIPConcurrency < 1 {
451+ log .Printf ("Invalid SBPM_BATCH_CHECK_IP_CONCURRENCY=%d, using default 10" , batchCheckIPConcurrency )
452+ batchCheckIPConcurrency = 10
453+ }
454+ batchCheckIPConcurrencyMeta := fmt .Sprintf (
455+ ` <meta name="sbpm-batch-check-ip-concurrency" content="%d" />` ,
456+ batchCheckIPConcurrency ,
457+ )
458+ indexContent = upsertIndexMetaTag (indexContent , "sbpm-batch-check-ip-concurrency" , batchCheckIPConcurrencyMeta )
437459
438460 indexFingerprint := calcContentFingerprint (indexContent )
439461 indexETag := fmt .Sprintf ("\" sbpm-%s\" " , indexFingerprint )
0 commit comments