Show scan overlay after page reload
- Add is_scanning state tracking in AnimeService - Add get_scan_status method to AnimeService - Add /api/anime/scan/status endpoint to check scan state - Add checkActiveScanStatus in JS to restore overlay on reconnect - All 1024 tests passing
This commit is contained in:
@@ -54,6 +54,8 @@ class AnimeService:
|
||||
self._scan_directories_count: int = 0
|
||||
self._scan_files_count: int = 0
|
||||
self._scan_total_items: int = 0
|
||||
self._is_scanning: bool = False
|
||||
self._scan_current_directory: str = ""
|
||||
# Subscribe to SeriesApp events
|
||||
# Note: Events library uses assignment (=), not += operator
|
||||
try:
|
||||
@@ -219,6 +221,8 @@ class AnimeService:
|
||||
self._scan_directories_count = 0
|
||||
self._scan_files_count = 0
|
||||
self._scan_total_items = args.total
|
||||
self._is_scanning = True
|
||||
self._scan_current_directory = ""
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
self._progress_service.start_progress(
|
||||
@@ -237,6 +241,7 @@ class AnimeService:
|
||||
elif args.status == "progress":
|
||||
# Update scan counters
|
||||
self._scan_directories_count = args.current
|
||||
self._scan_current_directory = args.folder or ""
|
||||
# Estimate files found (use current as proxy since detailed
|
||||
# file count isn't available from SerieScanner)
|
||||
|
||||
@@ -265,6 +270,9 @@ class AnimeService:
|
||||
if self._scan_start_time:
|
||||
elapsed = time.time() - self._scan_start_time
|
||||
|
||||
# Mark scan as complete
|
||||
self._is_scanning = False
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
self._progress_service.complete_progress(
|
||||
progress_id=scan_id,
|
||||
@@ -282,6 +290,7 @@ class AnimeService:
|
||||
loop
|
||||
)
|
||||
elif args.status == "failed":
|
||||
self._is_scanning = False
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
self._progress_service.fail_progress(
|
||||
progress_id=scan_id,
|
||||
@@ -290,6 +299,7 @@ class AnimeService:
|
||||
loop
|
||||
)
|
||||
elif args.status == "cancelled":
|
||||
self._is_scanning = False
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
self._progress_service.fail_progress(
|
||||
progress_id=scan_id,
|
||||
@@ -385,6 +395,25 @@ class AnimeService:
|
||||
error=str(exc)
|
||||
)
|
||||
|
||||
def get_scan_status(self) -> dict:
|
||||
"""Get the current scan status.
|
||||
|
||||
Returns:
|
||||
Dictionary with scan status information including:
|
||||
- is_scanning: Whether a scan is currently in progress
|
||||
- total_items: Total number of items to scan
|
||||
- directories_scanned: Number of directories scanned so far
|
||||
- current_directory: Current directory being scanned
|
||||
- directory: Root directory being scanned
|
||||
"""
|
||||
return {
|
||||
"is_scanning": self._is_scanning,
|
||||
"total_items": self._scan_total_items,
|
||||
"directories_scanned": self._scan_directories_count,
|
||||
"current_directory": self._scan_current_directory,
|
||||
"directory": self._directory,
|
||||
}
|
||||
|
||||
@lru_cache(maxsize=128)
|
||||
def _cached_list_missing(self) -> list[dict]:
|
||||
# Synchronous cached call - SeriesApp.series_list is populated
|
||||
|
||||
Reference in New Issue
Block a user