mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(filters): store and update with no external filters (#1049)
* fix(filters): store and update * fix(filters): bad fmt var * fix(filters): store expect status * fix(filters): store expect status * fix(filters): external filter always rejected
This commit is contained in:
parent
0fa53b0b2e
commit
3e244fac10
14 changed files with 151 additions and 125 deletions
|
@ -186,10 +186,11 @@ func (r *ActionRepo) attachDownloadClient(ctx context.Context, tx *Tx, clientID
|
|||
var settingsJsonStr string
|
||||
|
||||
if err := row.Scan(&client.ID, &client.Name, &client.Type, &client.Enabled, &client.Host, &client.Port, &client.TLS, &client.TLSSkipVerify, &client.Username, &client.Password, &settingsJsonStr); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
r.log.Warn().Msgf("no download client with id %d", clientID)
|
||||
return nil, nil
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
|
@ -346,8 +347,8 @@ func (r *ActionRepo) Get(ctx context.Context, req *domain.GetActionRequest) (*do
|
|||
var paused, ignoreRules sql.NullBool
|
||||
|
||||
if err := row.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID, &filterID); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
|
@ -506,14 +507,14 @@ func (r *ActionRepo) Store(ctx context.Context, action domain.Action) (*domain.A
|
|||
// return values
|
||||
var retID int64
|
||||
|
||||
err := queryBuilder.QueryRowContext(ctx).Scan(&retID)
|
||||
if err != nil {
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||
return nil, errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
r.log.Debug().Msgf("action.store: added new %v", retID)
|
||||
action.ID = int(retID)
|
||||
|
||||
r.log.Debug().Msgf("action.store: added new %d", retID)
|
||||
|
||||
return &action, nil
|
||||
}
|
||||
|
||||
|
@ -588,7 +589,7 @@ func (r *ActionRepo) Update(ctx context.Context, action domain.Action) (*domain.
|
|||
return &action, nil
|
||||
}
|
||||
|
||||
func (r *ActionRepo) StoreFilterActions(ctx context.Context, actions []*domain.Action, filterID int64) ([]*domain.Action, error) {
|
||||
func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, actions []*domain.Action) ([]*domain.Action, error) {
|
||||
tx, err := r.db.handler.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error begin transaction")
|
||||
|
|
|
@ -156,7 +156,7 @@ func (r *DownloadClientRepo) FindByID(ctx context.Context, id int32) (*domain.Do
|
|||
var settingsJsonStr string
|
||||
|
||||
if err := row.Scan(&client.ID, &client.Name, &client.Type, &client.Enabled, &client.Host, &client.Port, &client.TLS, &client.TLSSkipVerify, &client.Username, &client.Password, &settingsJsonStr); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.New("no client configured")
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,11 @@ func (r *FeedCacheRepo) Get(bucket string, key string) ([]byte, error) {
|
|||
var value []byte
|
||||
var ttl time.Duration
|
||||
|
||||
if err := row.Scan(&value, &ttl); err != nil && err != sql.ErrNoRows {
|
||||
if err := row.Scan(&value, &ttl); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
|
@ -143,7 +147,11 @@ func (r *FeedCacheRepo) Exists(bucket string, key string) (bool, error) {
|
|||
|
||||
var exists bool
|
||||
err = r.db.handler.QueryRow(query, args...).Scan(&exists)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return false, domain.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return false, errors.Wrap(err, "error query")
|
||||
}
|
||||
|
||||
|
|
|
@ -769,7 +769,7 @@ func (r *FilterRepo) FindExternalFiltersByID(ctx context.Context, filterId int)
|
|||
return externalFilters, nil
|
||||
}
|
||||
|
||||
func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.Filter, error) {
|
||||
func (r *FilterRepo) Store(ctx context.Context, filter *domain.Filter) error {
|
||||
queryBuilder := r.db.squirrel.
|
||||
Insert("filter").
|
||||
Columns(
|
||||
|
@ -896,15 +896,15 @@ func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.F
|
|||
var retID int
|
||||
|
||||
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||
return nil, errors.Wrap(err, "error executing query")
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
filter.ID = retID
|
||||
|
||||
return &filter, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *FilterRepo) Update(ctx context.Context, filter domain.Filter) (*domain.Filter, error) {
|
||||
func (r *FilterRepo) Update(ctx context.Context, filter *domain.Filter) error {
|
||||
var err error
|
||||
|
||||
queryBuilder := r.db.squirrel.
|
||||
|
@ -971,15 +971,15 @@ func (r *FilterRepo) Update(ctx context.Context, filter domain.Filter) (*domain.
|
|||
|
||||
query, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error building query")
|
||||
return errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
_, err = r.db.handler.ExecContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error executing query")
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
return &filter, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *FilterRepo) UpdatePartial(ctx context.Context, filter domain.FilterUpdate) error {
|
||||
|
@ -1245,13 +1245,23 @@ func (r *FilterRepo) StoreIndexerConnections(ctx context.Context, filterID int,
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, deleteQuery, deleteArgs...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
if len(indexers) == 0 {
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "error store indexers for filter: %d", filterID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
queryBuilder := r.db.squirrel.
|
||||
Insert("filter_indexer").Columns("filter_id", "indexer_id")
|
||||
Insert("filter_indexer").
|
||||
Columns("filter_id", "indexer_id")
|
||||
|
||||
for _, indexer := range indexers {
|
||||
queryBuilder = queryBuilder.Values(filterID, indexer.ID)
|
||||
|
@ -1311,6 +1321,24 @@ func (r *FilterRepo) DeleteIndexerConnections(ctx context.Context, filterID int)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *FilterRepo) DeleteFilterExternal(ctx context.Context, filterID int) error {
|
||||
queryBuilder := r.db.squirrel.
|
||||
Delete("filter_external").
|
||||
Where(sq.Eq{"filter_id": filterID})
|
||||
|
||||
query, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error building query")
|
||||
}
|
||||
|
||||
_, err = r.db.handler.ExecContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *FilterRepo) Delete(ctx context.Context, filterID int) error {
|
||||
queryBuilder := r.db.squirrel.
|
||||
Delete("filter").
|
||||
|
@ -1411,6 +1439,14 @@ func (r *FilterRepo) StoreFilterExternal(ctx context.Context, filterID int, exte
|
|||
return errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
if len(externalFilters) == 0 {
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "error delete external filters for filter: %d", filterID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
qb := r.db.squirrel.
|
||||
Insert("filter_external").
|
||||
Columns(
|
||||
|
|
|
@ -260,12 +260,12 @@ func (r *IrcRepo) CheckExistingNetwork(ctx context.Context, network *domain.IrcN
|
|||
var tls sql.NullBool
|
||||
|
||||
if err = row.Scan(&net.ID, &net.Enabled, &net.Name, &net.Server, &net.Port, &tls, &pass, &nick, &net.Auth.Mechanism, &account, &password, &inviteCmd, &bouncerAddr, &net.UseBouncer); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
// no result is not an error in our case
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
net.TLS = tls.Bool
|
||||
|
|
|
@ -425,7 +425,7 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
|
|||
var filterId sql.NullInt64
|
||||
|
||||
if err := row.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &indexerName, &filterName, &filterId, &rls.Protocol, &infoUrl, &downloadUrl, &rls.Title, &rls.TorrentName, &rls.Size, &rls.Timestamp); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
|
@ -468,7 +468,7 @@ func (repo *ReleaseRepo) GetActionStatus(ctx context.Context, req *domain.GetRel
|
|||
var actionId, filterId sql.NullInt64
|
||||
|
||||
if err := row.Scan(&rls.ID, &rls.Status, &rls.Action, &actionId, &rls.Type, &client, &filter, &filterId, &rls.ReleaseID, pq.Array(&rls.Rejections), &rls.Timestamp); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ func (r *UserRepo) FindByUsername(ctx context.Context, username string) (*domain
|
|||
var user domain.User
|
||||
|
||||
if err := row.Scan(&user.ID, &user.Username, &user.Password); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue