@@ -151,6 +151,9 @@ let huntarrUI = {
151
151
// Setup Swaparr status polling (refresh every 30 seconds)
152
152
this . setupSwaparrStatusPolling ( ) ;
153
153
154
+ // Setup Prowlarr status polling (refresh every 30 seconds)
155
+ this . setupProwlarrStatusPolling ( ) ;
156
+
154
157
// Make dashboard visible after initialization to prevent FOUC
155
158
setTimeout ( ( ) => {
156
159
this . showDashboard ( ) ;
@@ -2300,7 +2303,178 @@ let huntarrUI = {
2300
2303
}
2301
2304
} , 30000 ) ;
2302
2305
} ,
2303
-
2306
+
2307
+ // Setup Prowlarr status polling
2308
+ setupProwlarrStatusPolling : function ( ) {
2309
+ // Load initial status
2310
+ this . loadProwlarrStatus ( ) ;
2311
+
2312
+ // Set up polling to refresh Prowlarr status every 30 seconds
2313
+ // Only poll when home section is active to reduce unnecessary requests
2314
+ setInterval ( ( ) => {
2315
+ if ( this . currentSection === 'home' ) {
2316
+ this . loadProwlarrStatus ( ) ;
2317
+ }
2318
+ } , 30000 ) ;
2319
+ } ,
2320
+
2321
+ // Load and update Prowlarr status card
2322
+ loadProwlarrStatus : function ( ) {
2323
+ HuntarrUtils . fetchWithTimeout ( './api/prowlarr/status' )
2324
+ . then ( response => response . json ( ) )
2325
+ . then ( statusData => {
2326
+ const prowlarrCard = document . getElementById ( 'prowlarrStatusCard' ) ;
2327
+ if ( ! prowlarrCard ) return ;
2328
+
2329
+ // Show/hide card based on whether Prowlarr is configured and enabled
2330
+ if ( statusData . configured && statusData . enabled ) {
2331
+ prowlarrCard . style . display = 'block' ;
2332
+
2333
+ // Update connection status
2334
+ const statusElement = document . getElementById ( 'prowlarrConnectionStatus' ) ;
2335
+ if ( statusElement ) {
2336
+ if ( statusData . connected ) {
2337
+ statusElement . textContent = '🟢 Connected' ;
2338
+ statusElement . className = 'status-badge success' ;
2339
+ } else {
2340
+ statusElement . textContent = '🔴 Disconnected' ;
2341
+ statusElement . className = 'status-badge error' ;
2342
+ }
2343
+ }
2344
+
2345
+ // Load detailed stats if connected
2346
+ if ( statusData . connected ) {
2347
+ this . loadProwlarrStats ( ) ;
2348
+ } else {
2349
+ // Show disconnected state
2350
+ this . updateProwlarrStatsDisplay ( {
2351
+ active_indexers : '--' ,
2352
+ total_api_calls : '--' ,
2353
+ throttled_indexers : '--' ,
2354
+ failed_indexers : '--' ,
2355
+ health_status : 'Disconnected'
2356
+ } ) ;
2357
+ }
2358
+
2359
+ // Setup refresh button
2360
+ this . setupProwlarrRefreshButton ( ) ;
2361
+
2362
+ } else {
2363
+ prowlarrCard . style . display = 'none' ;
2364
+ }
2365
+ } )
2366
+ . catch ( error => {
2367
+ console . error ( 'Error loading Prowlarr status:' , error ) ;
2368
+ const prowlarrCard = document . getElementById ( 'prowlarrStatusCard' ) ;
2369
+ if ( prowlarrCard ) {
2370
+ prowlarrCard . style . display = 'none' ;
2371
+ }
2372
+ } ) ;
2373
+ } ,
2374
+
2375
+ // Load detailed Prowlarr statistics
2376
+ loadProwlarrStats : function ( ) {
2377
+ HuntarrUtils . fetchWithTimeout ( './api/prowlarr/stats' )
2378
+ . then ( response => response . json ( ) )
2379
+ . then ( data => {
2380
+ if ( data . success ) {
2381
+ this . updateProwlarrStatsDisplay ( data . stats ) ;
2382
+ } else {
2383
+ console . error ( 'Failed to load Prowlarr stats:' , data . error ) ;
2384
+ this . updateProwlarrStatsDisplay ( {
2385
+ active_indexers : '--' ,
2386
+ total_api_calls : '--' ,
2387
+ throttled_indexers : '--' ,
2388
+ failed_indexers : '--' ,
2389
+ health_status : 'Error loading stats'
2390
+ } ) ;
2391
+ }
2392
+ } )
2393
+ . catch ( error => {
2394
+ console . error ( 'Error loading Prowlarr stats:' , error ) ;
2395
+ this . updateProwlarrStatsDisplay ( {
2396
+ active_indexers : '--' ,
2397
+ total_api_calls : '--' ,
2398
+ throttled_indexers : '--' ,
2399
+ failed_indexers : '--' ,
2400
+ health_status : 'Connection error'
2401
+ } ) ;
2402
+ } ) ;
2403
+ } ,
2404
+
2405
+ // Update Prowlarr stats display
2406
+ updateProwlarrStatsDisplay : function ( stats ) {
2407
+ // Update stat numbers
2408
+ const activeElement = document . getElementById ( 'prowlarr-active-indexers' ) ;
2409
+ if ( activeElement ) activeElement . textContent = stats . active_indexers ;
2410
+
2411
+ const callsElement = document . getElementById ( 'prowlarr-total-calls' ) ;
2412
+ if ( callsElement ) callsElement . textContent = this . formatLargeNumber ( stats . total_api_calls ) ;
2413
+
2414
+ const throttledElement = document . getElementById ( 'prowlarr-throttled' ) ;
2415
+ if ( throttledElement ) throttledElement . textContent = stats . throttled_indexers ;
2416
+
2417
+ const failedElement = document . getElementById ( 'prowlarr-failed' ) ;
2418
+ if ( failedElement ) failedElement . textContent = stats . failed_indexers ;
2419
+
2420
+ // Update health status
2421
+ const healthElement = document . getElementById ( 'prowlarr-health-status' ) ;
2422
+ if ( healthElement ) {
2423
+ healthElement . textContent = stats . health_status || 'Unknown' ;
2424
+
2425
+ // Add color coding based on health
2426
+ if ( stats . health_status && stats . health_status . includes ( 'throttled' ) ) {
2427
+ healthElement . style . color = '#f59e0b' ; // amber
2428
+ } else if ( stats . health_status && ( stats . health_status . includes ( 'failed' ) || stats . health_status . includes ( 'disabled' ) ) ) {
2429
+ healthElement . style . color = '#ef4444' ; // red
2430
+ } else if ( stats . health_status && stats . health_status . includes ( 'healthy' ) ) {
2431
+ healthElement . style . color = '#10b981' ; // green
2432
+ } else {
2433
+ healthElement . style . color = '#9ca3af' ; // gray
2434
+ }
2435
+ }
2436
+ } ,
2437
+
2438
+ // Setup Prowlarr refresh button
2439
+ setupProwlarrRefreshButton : function ( ) {
2440
+ const refreshButton = document . getElementById ( 'refresh-prowlarr-data' ) ;
2441
+ if ( refreshButton ) {
2442
+ refreshButton . addEventListener ( 'click' , ( ) => {
2443
+ this . refreshProwlarrData ( ) ;
2444
+ } ) ;
2445
+ }
2446
+ } ,
2447
+
2448
+ // Refresh Prowlarr data
2449
+ refreshProwlarrData : function ( ) {
2450
+ // Prevent multiple refreshes
2451
+ if ( this . prowlarrRefreshInProgress ) {
2452
+ return ;
2453
+ }
2454
+
2455
+ this . prowlarrRefreshInProgress = true ;
2456
+
2457
+ // Update button to show refreshing state
2458
+ const refreshButton = document . getElementById ( 'refresh-prowlarr-data' ) ;
2459
+ if ( refreshButton ) {
2460
+ const originalText = refreshButton . innerHTML ;
2461
+ refreshButton . innerHTML = '<i class="fas fa-spinner fa-spin"></i> Refreshing...' ;
2462
+ refreshButton . disabled = true ;
2463
+
2464
+ // Restore button after refresh
2465
+ setTimeout ( ( ) => {
2466
+ refreshButton . innerHTML = originalText ;
2467
+ refreshButton . disabled = false ;
2468
+ this . prowlarrRefreshInProgress = false ;
2469
+ } , 2000 ) ;
2470
+ }
2471
+
2472
+ // Reload Prowlarr status and stats
2473
+ this . loadProwlarrStatus ( ) ;
2474
+
2475
+ // Show notification
2476
+ this . showNotification ( 'Prowlarr data refreshed' , 'success' ) ;
2477
+ } ,
2304
2478
2305
2479
2306
2480
// User
0 commit comments