diff --git a/api/web_routes.py b/api/web_routes.py index 6a199b5..ba5d3cf 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -1286,25 +1286,10 @@ def register_web_routes(app, dependencies): db = dependencies["db"] try: - # Check if episode exists - with db.get_connection() as conn: - cursor = conn.cursor() - cursor.execute( - "SELECT season, episode, dateadded, source FROM episodes WHERE imdb_id = %s AND season = %s AND episode = %s", - (imdb_id, season, episode) - ) - episode_data = cursor.fetchone() - - if not episode_data: - raise HTTPException(status_code=404, detail="Episode not found") - - # Delete the episode - cursor.execute( - "DELETE FROM episodes WHERE imdb_id = %s AND season = %s AND episode = %s", - (imdb_id, season, episode) - ) - conn.commit() - + # Use the existing database method + deleted = db.delete_episode(imdb_id, season, episode) + + if deleted: return { "success": True, "status": "success", @@ -1313,7 +1298,11 @@ def register_web_routes(app, dependencies): "season": season, "episode": episode } + else: + raise HTTPException(status_code=404, detail="Episode not found") + except HTTPException: + raise # Re-raise HTTP exceptions except Exception as e: print(f"❌ Error deleting episode: {e}") raise HTTPException(status_code=500, detail=f"Failed to delete episode: {str(e)}") diff --git a/nfoguard-web/static/index.html b/nfoguard-web/static/index.html index bebdb29..2d871c6 100644 --- a/nfoguard-web/static/index.html +++ b/nfoguard-web/static/index.html @@ -457,6 +457,6 @@
- +