From 059d3bae3f15f019f6b40c7f84b33ccb50919d31 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Sat, 25 Oct 2025 15:47:43 -0400 Subject: [PATCH] web: debug --- api/web_routes.py | 27 ++++++++------------------- nfoguard-web/static/index.html | 2 +- nfoguard-web/static/js/app.js | 16 +++------------- 3 files changed, 12 insertions(+), 33 deletions(-) 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 @@
- + \ No newline at end of file diff --git a/nfoguard-web/static/js/app.js b/nfoguard-web/static/js/app.js index c6323a0..1bb327c 100644 --- a/nfoguard-web/static/js/app.js +++ b/nfoguard-web/static/js/app.js @@ -1289,16 +1289,11 @@ async function deleteEpisode(imdbId, season, episode) { } try { - const response = await fetch(`/api/episodes/${imdbId}/${season}/${episode}`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } + const result = await apiCall(`/api/episodes/${imdbId}/${season}/${episode}`, { + method: 'DELETE' }); - const result = await response.json(); - - if (response.ok && result.success) { + if (result.success) { showToast(`✅ Episode ${episodeStr} deleted successfully`, 'success'); // Remove the row from the table @@ -1312,11 +1307,6 @@ async function deleteEpisode(imdbId, season, episode) { // Update episode counts in modal header updateEpisodeModalCounts(); - - } else { - const errorMsg = result.message || result.error || 'Unknown error'; - showToast(`❌ Failed to delete episode: ${errorMsg}`, 'error'); - } } catch (error) { console.error('Delete episode failed:', error);