🐛 Erreurs de fichiers explicites (droits, introuvable) sur chaque action + annulation reservee a l'etat a valider
This commit is contained in:
1 parent
70ce0b95a8
commit
6191b32bf7
4 files changed
+185
-35
No files matched your search
+34
-10
@@ -31,6 +31,8 @@ from app.converter import (
|
||||
conversion_paths,
|
||||
finalize_validation,
|
||||
looks_like_iso,
|
||||
rmdir_if_empty,
|
||||
unlink_if_exists,
|
||||
workspace_files,
|
||||
)
|
||||
from app.database import Base, engine, get_db
|
||||
@@ -514,16 +516,30 @@ def convert_movie(movie_id: int, db: DbSession, force: bool = False) -> IsoMovie
|
||||
|
||||
@app.post("/api/movies/{movie_id}/cancel", response_model=IsoMovieRead)
|
||||
def cancel_movie(movie_id: int, db: DbSession) -> IsoMovie:
|
||||
"""Annule une conversion en attente de validation et supprime le MKV.
|
||||
|
||||
Reserve a l'etat ``validating``: avant cette etape le MKV converti
|
||||
n'existe pas. Les fichiers deja disparus sont toleres; seule une erreur
|
||||
de droits interrompt, remontee en erreur explicite.
|
||||
"""
|
||||
movie = db.get(IsoMovie, movie_id)
|
||||
if movie is None:
|
||||
raise HTTPException(status_code=404, detail="Film introuvable")
|
||||
if movie.status not in {"queued", "validating"}:
|
||||
if movie.status != "validating":
|
||||
raise HTTPException(status_code=409, detail="Aucune conversion à annuler")
|
||||
if movie.status == "validating":
|
||||
paths = conversion_paths(movie)
|
||||
linked = _linked_mkv(movie)
|
||||
cancel_conversion(paths.mkv_path, paths.destination_folder, linked.name if linked else None)
|
||||
paths = conversion_paths(movie)
|
||||
linked = _linked_mkv(movie)
|
||||
try:
|
||||
cancel_conversion(
|
||||
paths.mkv_path, paths.destination_folder, linked.name if linked else None
|
||||
)
|
||||
except Exception as error: # noqa: BLE001 - message explicite pour l'UI
|
||||
raise HTTPException(
|
||||
status_code=409, detail=f"Annulation impossible: {error}"
|
||||
) from error
|
||||
movie.status = "detected"
|
||||
movie.failed_step = None
|
||||
movie.last_error = None
|
||||
db.commit()
|
||||
return movie
|
||||
|
||||
@@ -547,14 +563,22 @@ async def validate_movie(movie_id: int, db: DbSession) -> IsoMovie:
|
||||
raise HTTPException(status_code=409, detail="Aucun MKV lié à valider")
|
||||
|
||||
# Supprime l'ISO et le reste du dossier du film, puis le torrent qBittorrent.
|
||||
finalize_validation(paths.destination_folder, linked.name)
|
||||
try:
|
||||
finalize_validation(paths.destination_folder, linked.name)
|
||||
except Exception as error: # noqa: BLE001 - message explicite pour l'UI
|
||||
raise HTTPException(
|
||||
status_code=409, detail=f"Validation impossible (dossier du film): {error}"
|
||||
) from error
|
||||
await _delete_iso_torrent(movie.path)
|
||||
|
||||
# Nettoyage du dossier de travail (le lien dur garde les donnees).
|
||||
if linked.exists() and paths.mkv_path.exists():
|
||||
paths.mkv_path.unlink()
|
||||
if paths.mkv_path.parent.is_dir() and not any(paths.mkv_path.parent.iterdir()):
|
||||
paths.mkv_path.parent.rmdir()
|
||||
try:
|
||||
unlink_if_exists(paths.mkv_path)
|
||||
rmdir_if_empty(paths.mkv_path.parent)
|
||||
except Exception as error: # noqa: BLE001 - message explicite pour l'UI
|
||||
raise HTTPException(
|
||||
status_code=409, detail=f"Validation impossible (dossier de travail): {error}"
|
||||
) from error
|
||||
|
||||
movie.status = "completed"
|
||||
now = datetime.now(UTC)
|
||||
|
||||
Reference in new issue
Block a user