Enrich MonitorAlbum response, prevent duplicate downloads, recover orphaned jobs on startup
This commit is contained in:
@@ -107,6 +107,27 @@ func (r *DownloadRepository) GetByAlbumID(ctx context.Context, albumID string) (
|
||||
return downloads, nil
|
||||
}
|
||||
|
||||
func (r *DownloadRepository) GetActive(ctx context.Context) ([]*Download, error) {
|
||||
rows, err := r.pool.Query(ctx,
|
||||
`SELECT id, torrent_id, album_id, format, quality, state, qbit_hash, save_path, error_message, queued_at, started_at, completed_at, created_at, updated_at
|
||||
FROM downloads WHERE state IN ('pending', 'downloading') ORDER BY created_at`,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing active downloads: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var downloads []*Download
|
||||
for rows.Next() {
|
||||
d := &Download{}
|
||||
if err := rows.Scan(&d.ID, &d.TorrentID, &d.AlbumID, &d.Format, &d.Quality, &d.State, &d.QbitHash, &d.SavePath, &d.ErrorMessage, &d.QueuedAt, &d.StartedAt, &d.CompletedAt, &d.CreatedAt, &d.UpdatedAt); err != nil {
|
||||
return nil, fmt.Errorf("scanning download: %w", err)
|
||||
}
|
||||
downloads = append(downloads, d)
|
||||
}
|
||||
return downloads, nil
|
||||
}
|
||||
|
||||
func (r *DownloadRepository) HasAlbumInQuality(ctx context.Context, albumID string, format string, quality string) (bool, error) {
|
||||
var exists bool
|
||||
err := r.pool.QueryRow(ctx,
|
||||
|
||||
Reference in New Issue
Block a user