feat: download all episodes when following anime, then auto-check for new episodes
This commit is contained in:
@@ -2086,11 +2086,56 @@ async def check_watchlist_item(
|
||||
return result
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking watchlist item: {e}", exc_info=True)
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking watchlist item: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@app.post("/api/watchlist/{item_id}/download-all", tags=["Watchlist"])
|
||||
async def download_all_episodes(
|
||||
item_id: str,
|
||||
current_user: User = Depends(get_current_user_from_token)
|
||||
):
|
||||
"""Download ALL episodes for a watchlist item (used when first following an anime)"""
|
||||
try:
|
||||
item = watchlist_manager.get_by_id(item_id)
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Watchlist item not found")
|
||||
|
||||
# Check ownership
|
||||
if item.user_id != current_user.id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
|
||||
# Temporarily set last_episode_downloaded to 0 to trigger download of ALL episodes
|
||||
original_last_episode = item.last_episode_downloaded
|
||||
item.last_episode_downloaded = 0
|
||||
watchlist_manager.db.commit()
|
||||
|
||||
try:
|
||||
result = await episode_checker.manual_check(item_id)
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Downloading all episodes for {item.anime_title}",
|
||||
"result": result
|
||||
}
|
||||
finally:
|
||||
# Restore original value (the check will update it)
|
||||
item.last_episode_downloaded = original_last_episode
|
||||
watchlist_manager.db.commit()
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Error downloading all episodes: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
|
||||
@app.post("/api/watchlist/{item_id}/pause", response_model=WatchlistItem, tags=["Watchlist"])
|
||||
TB|@app.post("/api/watchlist/{item_id}/pause", response_model=WatchlistItem, tags=["Watchlist"])
|
||||
|
||||
|
||||
@app.post("/api/watchlist/{item_id}/pause", response_model=WatchlistItem, tags=["Watchlist"])
|
||||
async def pause_watchlist_item(
|
||||
item_id: str,
|
||||
|
||||
@@ -206,6 +206,31 @@ async function handleAddToWatchlist(animeUrl, providerId) {
|
||||
|
||||
const result = await addToWatchlist(itemData);
|
||||
|
||||
// Trigger download of all episodes immediately
|
||||
try {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const downloadResponse = await fetch(`${API_BASE}/watchlist/${result.id}/download-all`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (downloadResponse.ok) {
|
||||
const downloadResult = await downloadResponse.json();
|
||||
alert(`✅ "${result.anime_title}" a été ajouté et le téléchargement de tous les épisodes a commencé!\n\nVous recevrez automatiquement les nouveaux épisodes.`);
|
||||
} else {
|
||||
// Still show success even if download failed
|
||||
alert(`✅ "${result.anime_title}" a été ajouté à votre watchlist!\n\nLe téléchargement automatique des nouveaux épisodes est activé.`);
|
||||
}
|
||||
} catch (downloadError) {
|
||||
console.warn('Auto-download trigger failed:', downloadError);
|
||||
alert(`✅ "${result.anime_title}" a été ajouté à votre watchlist!\n\nLe téléchargement automatique des nouveaux épisodes est activé.`);
|
||||
}
|
||||
|
||||
// Update button to show it's already in watchlist
|
||||
updateAddButton(animeUrl, true);
|
||||
|
||||
alert(`✅ "${result.anime_title}" a été ajouté à votre watchlist!`);
|
||||
|
||||
// Update button to show it's already in watchlist
|
||||
|
||||
Reference in New Issue
Block a user