fix(recipe): reimport data loss, local file support, and scroll bugs

- Add local file reimport support via _do_reimport_from_local
- Validate source_path BEFORE deleting old recipe (prevent data loss)
- Move delete_recipe after save_recipe (safe ordering)
- Preserve folder location, NSFW level, and carry over user edits
- Remove old timestamp preservation (use current time)
- Add scrollTop reset in resetAndReloadWithVirtualScroll
- Only reload on successful bulk reimport (avoid empty grid)
- Disable preserveScroll for both single and bulk reimport
This commit is contained in:
Will Miao
2026-06-11 21:31:30 +08:00
parent 05f3018495
commit 46cbcf94c8
5 changed files with 154 additions and 35 deletions

View File

@@ -49,8 +49,18 @@ class RecipePersistenceService:
tags: Iterable[str],
metadata: Optional[dict[str, Any]],
extension: str | None = None,
recipe_id: str | None = None,
target_dir: str | None = None,
) -> PersistenceResult:
"""Persist a user uploaded recipe."""
"""Persist a user uploaded recipe.
Args:
recipe_id: If provided, reuse this ID instead of generating a new
UUID. Used by re-import to preserve the original recipe identity.
target_dir: If provided, save recipe files to this directory instead
of the default recipes_dir. Used by re-import to preserve the
original folder location.
"""
missing_fields = []
if not name:
@@ -63,10 +73,10 @@ class RecipePersistenceService:
)
resolved_image_bytes = self._resolve_image_bytes(image_bytes, image_base64)
recipes_dir = recipe_scanner.recipes_dir
recipes_dir = target_dir or recipe_scanner.recipes_dir
os.makedirs(recipes_dir, exist_ok=True)
recipe_id = str(uuid.uuid4())
recipe_id = recipe_id or str(uuid.uuid4())
# Handle video formats by bypassing optimization and metadata embedding
is_video = extension in [".mp4", ".webm"]