@@ -4642,6 +4642,150 @@ let huntarrUI = {
4642
4642
// Fall back to loading Swaparr status/info
4643
4643
this . loadSwaparrStatus ( ) ;
4644
4644
}
4645
+ } ,
4646
+
4647
+ // Setup Prowlarr status polling
4648
+ setupProwlarrStatusPolling : function ( ) {
4649
+ console . log ( '[huntarrUI] Setting up Prowlarr status polling' ) ;
4650
+
4651
+ // Load initial status
4652
+ this . loadProwlarrStatus ( ) ;
4653
+
4654
+ // Set up polling to refresh Prowlarr status every 30 seconds
4655
+ // Only poll when home section is active to reduce unnecessary requests
4656
+ this . prowlarrPollingInterval = setInterval ( ( ) => {
4657
+ if ( this . currentSection === 'home' ) {
4658
+ this . loadProwlarrStatus ( ) ;
4659
+ }
4660
+ } , 30000 ) ;
4661
+
4662
+ // Set up refresh button handler
4663
+ const refreshButton = document . getElementById ( 'refresh-prowlarr-data' ) ;
4664
+ if ( refreshButton ) {
4665
+ refreshButton . addEventListener ( 'click' , ( ) => {
4666
+ console . log ( '[huntarrUI] Manual Prowlarr refresh triggered' ) ;
4667
+ this . loadProwlarrStatus ( ) ;
4668
+ } ) ;
4669
+ }
4670
+ } ,
4671
+
4672
+ // Load and update Prowlarr status card
4673
+ loadProwlarrStatus : function ( ) {
4674
+ console . log ( '[huntarrUI] Loading Prowlarr status' ) ;
4675
+
4676
+ HuntarrUtils . fetchWithTimeout ( './api/prowlarr/stats' )
4677
+ . then ( response => response . json ( ) )
4678
+ . then ( data => {
4679
+ console . log ( '[huntarrUI] Prowlarr stats received:' , data ) ;
4680
+
4681
+ const prowlarrCard = document . getElementById ( 'prowlarrStatusCard' ) ;
4682
+ if ( ! prowlarrCard ) {
4683
+ console . log ( '[huntarrUI] Prowlarr card not found in DOM' ) ;
4684
+ return ;
4685
+ }
4686
+
4687
+ if ( data . success && data . stats ) {
4688
+ const stats = data . stats ;
4689
+
4690
+ // Show the card since we have data
4691
+ prowlarrCard . style . display = 'block' ;
4692
+
4693
+ // Update connection status
4694
+ const connectionStatus = document . getElementById ( 'prowlarrConnectionStatus' ) ;
4695
+ if ( connectionStatus ) {
4696
+ if ( stats . connected ) {
4697
+ connectionStatus . textContent = '🟢 Connected' ;
4698
+ connectionStatus . className = 'status-badge connected' ;
4699
+ } else {
4700
+ connectionStatus . textContent = '🔴 Disconnected' ;
4701
+ connectionStatus . className = 'status-badge disconnected' ;
4702
+ }
4703
+ }
4704
+
4705
+ // Update stats display
4706
+ const updateElement = ( id , value , tooltip = '' ) => {
4707
+ const element = document . getElementById ( id ) ;
4708
+ if ( element ) {
4709
+ element . textContent = value || '--' ;
4710
+ if ( tooltip ) {
4711
+ element . title = tooltip ;
4712
+ }
4713
+ }
4714
+ } ;
4715
+
4716
+ // Update basic stats
4717
+ updateElement ( 'prowlarr-active-indexers' , stats . active_indexers ) ;
4718
+ updateElement ( 'prowlarr-total-calls' , stats . total_api_calls ) ;
4719
+ updateElement ( 'prowlarr-throttled' , stats . throttled_indexers ) ;
4720
+ updateElement ( 'prowlarr-failed' , stats . failed_indexers ) ;
4721
+
4722
+ // Update detailed tooltips with indexer names if available
4723
+ if ( stats . indexer_details ) {
4724
+ const activeNames = stats . indexer_details . active ?. map ( idx => idx . name ) . join ( ', ' ) || 'None' ;
4725
+ const throttledNames = stats . indexer_details . throttled ?. map ( idx => idx . name ) . join ( ', ' ) || 'None' ;
4726
+ const failedNames = stats . indexer_details . failed ?. map ( idx => idx . name ) . join ( ', ' ) || 'None' ;
4727
+
4728
+ updateElement ( 'prowlarr-active-indexers' , stats . active_indexers , `Active: ${ activeNames } ` ) ;
4729
+ updateElement ( 'prowlarr-throttled' , stats . throttled_indexers , `Throttled: ${ throttledNames } ` ) ;
4730
+ updateElement ( 'prowlarr-failed' , stats . failed_indexers , `Failed: ${ failedNames } ` ) ;
4731
+ }
4732
+
4733
+ // Update health status
4734
+ const healthStatus = document . getElementById ( 'prowlarr-health-status' ) ;
4735
+ if ( healthStatus ) {
4736
+ healthStatus . textContent = stats . health_status || 'Unknown' ;
4737
+
4738
+ // Color-code health status
4739
+ healthStatus . className = 'health-status-text' ;
4740
+ if ( stats . health_status ?. includes ( 'healthy' ) ) {
4741
+ healthStatus . style . color = '#10b981' ; // Green
4742
+ } else if ( stats . health_status ?. includes ( 'throttled' ) ) {
4743
+ healthStatus . style . color = '#f59e0b' ; // Amber
4744
+ } else if ( stats . health_status ?. includes ( 'failed' ) || stats . health_status ?. includes ( 'disabled' ) ) {
4745
+ healthStatus . style . color = '#ef4444' ; // Red
4746
+ } else {
4747
+ healthStatus . style . color = '#9ca3af' ; // Gray
4748
+ }
4749
+ }
4750
+
4751
+ } else {
4752
+ // Handle error case
4753
+ console . log ( '[huntarrUI] Error in Prowlarr stats:' , data . message || 'Unknown error' ) ;
4754
+
4755
+ // Still show the card but with error states
4756
+ prowlarrCard . style . display = 'block' ;
4757
+
4758
+ const connectionStatus = document . getElementById ( 'prowlarrConnectionStatus' ) ;
4759
+ if ( connectionStatus ) {
4760
+ connectionStatus . textContent = '🔴 Error' ;
4761
+ connectionStatus . className = 'status-badge error' ;
4762
+ }
4763
+
4764
+ // Set all stats to error state
4765
+ [ 'prowlarr-active-indexers' , 'prowlarr-total-calls' , 'prowlarr-throttled' , 'prowlarr-failed' ] . forEach ( id => {
4766
+ const element = document . getElementById ( id ) ;
4767
+ if ( element ) {
4768
+ element . textContent = '--' ;
4769
+ element . title = data . message || 'Connection error' ;
4770
+ }
4771
+ } ) ;
4772
+
4773
+ const healthStatus = document . getElementById ( 'prowlarr-health-status' ) ;
4774
+ if ( healthStatus ) {
4775
+ healthStatus . textContent = data . message || 'Connection error' ;
4776
+ healthStatus . style . color = '#ef4444' ; // Red
4777
+ }
4778
+ }
4779
+ } )
4780
+ . catch ( error => {
4781
+ console . error ( '[huntarrUI] Error loading Prowlarr status:' , error ) ;
4782
+
4783
+ // Hide the card on error
4784
+ const prowlarrCard = document . getElementById ( 'prowlarrStatusCard' ) ;
4785
+ if ( prowlarrCard ) {
4786
+ prowlarrCard . style . display = 'none' ;
4787
+ }
4788
+ } ) ;
4645
4789
}
4646
4790
} ;
4647
4791
0 commit comments