Fix duplicate download insert: handle NULL columns in download scan, check by torrent ID, enrich MonitorAlbum response, recover orphaned downloads on startup
This commit is contained in:
@@ -16,8 +16,8 @@ type Download struct {
|
||||
Quality string
|
||||
State string
|
||||
QbitHash string
|
||||
SavePath string
|
||||
ErrorMessage string
|
||||
SavePath *string
|
||||
ErrorMessage *string
|
||||
QueuedAt time.Time
|
||||
StartedAt *time.Time
|
||||
CompletedAt *time.Time
|
||||
@@ -107,6 +107,19 @@ func (r *DownloadRepository) GetByAlbumID(ctx context.Context, albumID string) (
|
||||
return downloads, nil
|
||||
}
|
||||
|
||||
func (r *DownloadRepository) GetActiveByTorrentID(ctx context.Context, torrentID string) (*Download, error) {
|
||||
d := &Download{}
|
||||
err := r.pool.QueryRow(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 torrent_id = $1 AND state NOT IN ('failed')
|
||||
ORDER BY created_at DESC LIMIT 1`, torrentID,
|
||||
).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)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting active download by torrent: %w", err)
|
||||
}
|
||||
return d, 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
|
||||
|
||||
Reference in New Issue
Block a user