fix download
This commit is contained in:
@@ -341,12 +341,6 @@ class AddSeriesRequest(BaseModel):
|
||||
name: str
|
||||
|
||||
|
||||
class DownloadFoldersRequest(BaseModel):
|
||||
"""Request model for downloading missing episodes from folders."""
|
||||
|
||||
folders: List[str]
|
||||
|
||||
|
||||
def validate_search_query(query: str) -> str:
|
||||
"""Validate and sanitize search query.
|
||||
|
||||
@@ -594,48 +588,6 @@ async def add_series(
|
||||
) from exc
|
||||
|
||||
|
||||
@router.post("/download")
|
||||
async def download_folders(
|
||||
request: DownloadFoldersRequest,
|
||||
_auth: dict = Depends(require_auth),
|
||||
series_app: Any = Depends(get_series_app),
|
||||
) -> dict:
|
||||
"""Start downloading missing episodes from the specified folders.
|
||||
|
||||
Args:
|
||||
request: Request containing list of folder names
|
||||
_auth: Ensures the caller is authenticated (value unused)
|
||||
series_app: Core `SeriesApp` instance provided via dependency
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Status payload with success message
|
||||
|
||||
Raises:
|
||||
HTTPException: If download initiation fails
|
||||
"""
|
||||
try:
|
||||
if not hasattr(series_app, "Download"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_501_NOT_IMPLEMENTED,
|
||||
detail="Download functionality not available",
|
||||
)
|
||||
|
||||
# Call Download with the folders and a no-op callback
|
||||
series_app.Download(request.folders, lambda *args, **kwargs: None)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Download started for {len(request.folders)} series"
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to start download: {str(exc)}",
|
||||
) from exc
|
||||
|
||||
|
||||
@router.get("/{anime_id}", response_model=AnimeDetail)
|
||||
async def get_anime(
|
||||
anime_id: str,
|
||||
|
||||
@@ -912,22 +912,69 @@ class AniWorldApp {
|
||||
|
||||
try {
|
||||
const folders = Array.from(this.selectedSeries);
|
||||
let totalEpisodesAdded = 0;
|
||||
let failedSeries = [];
|
||||
|
||||
const response = await this.makeAuthenticatedRequest('/api/anime/download', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ folders })
|
||||
});
|
||||
// For each selected series, get its missing episodes and add to queue
|
||||
for (const folder of folders) {
|
||||
const serie = this.seriesData.find(s => s.folder === folder);
|
||||
if (!serie || !serie.episodeDict) {
|
||||
failedSeries.push(folder);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
// Convert episodeDict format {season: [episodes]} to episode identifiers
|
||||
const episodes = [];
|
||||
for (const [season, episodeNumbers] of Object.entries(serie.episodeDict)) {
|
||||
if (Array.isArray(episodeNumbers)) {
|
||||
for (const episode of episodeNumbers) {
|
||||
episodes.push({
|
||||
season: parseInt(season),
|
||||
episode: episode
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.status === 'success') {
|
||||
this.showToast('Download started', 'success');
|
||||
if (episodes.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add episodes to download queue
|
||||
const response = await this.makeAuthenticatedRequest('/api/queue/add', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
serie_id: serie.key,
|
||||
serie_name: serie.name,
|
||||
episodes: episodes,
|
||||
priority: 'NORMAL'
|
||||
})
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
failedSeries.push(folder);
|
||||
continue;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (data.status === 'success') {
|
||||
totalEpisodesAdded += episodes.length;
|
||||
} else {
|
||||
failedSeries.push(folder);
|
||||
}
|
||||
}
|
||||
|
||||
// Show result message
|
||||
if (totalEpisodesAdded > 0) {
|
||||
const message = failedSeries.length > 0
|
||||
? `Added ${totalEpisodesAdded} episode(s) to queue (${failedSeries.length} series failed)`
|
||||
: `Added ${totalEpisodesAdded} episode(s) to download queue`;
|
||||
this.showToast(message, 'success');
|
||||
} else {
|
||||
this.showToast(`Download error: ${data.message}`, 'error');
|
||||
this.showToast('Failed to add episodes to queue', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Download error:', error);
|
||||
|
||||
Reference in New Issue
Block a user