Refactor: Defer folder creation to download time

- Remove folder creation from add_series endpoint
- Add folder creation to download() method in SeriesApp
- Maintain database persistence and targeted scanning
- Update tests to use tmp_path fixtures
- All add_series and download tests passing (13/13)
This commit is contained in:
2026-01-11 17:15:59 +01:00
parent 3d2ef53463
commit 5c0a019e72
4 changed files with 96 additions and 47 deletions

View File

@@ -739,8 +739,7 @@ async def add_series(
db_id
)
# Step D: Create folder on disk and add to SerieList
folder_path = None
# Step D: Add to SerieList (in-memory only, no folder creation)
if series_app and hasattr(series_app, "list"):
serie = Serie(
key=key,
@@ -750,25 +749,15 @@ async def add_series(
episodeDict={}
)
# Add to SerieList - this creates the folder with sanitized name
if hasattr(series_app.list, 'add'):
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
folder_path = series_app.list.add(serie, use_sanitized_folder=True)
# Update folder to reflect what was actually created
folder = serie.folder
elif hasattr(series_app.list, 'keyDict'):
# Manual folder creation and cache update
if hasattr(series_app.list, 'directory'):
folder_path = os.path.join(series_app.list.directory, folder)
os.makedirs(folder_path, exist_ok=True)
# Add to in-memory cache without creating folder on disk
if hasattr(series_app.list, 'keyDict'):
series_app.list.keyDict[key] = serie
logger.info(
"Created folder for series: %s at %s",
name,
folder_path or folder
)
logger.info(
"Added series to in-memory cache: %s (key=%s, folder=%s)",
name,
key,
folder
)
# Step E: Trigger targeted scan for missing episodes
try:
@@ -818,7 +807,7 @@ async def add_series(
"status": "success",
"message": f"Successfully added series: {name}",
"key": key,
"folder": folder_path or folder,
"folder": folder,
"db_id": db_id,
"missing_episodes": missing_episodes_serializable,
"total_missing": total_missing