mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(irc): panic when creating indexer with irc (#986)
fix(irc): store channel panic
This commit is contained in:
parent
1f8804154e
commit
2af0021ce6
3 changed files with 14 additions and 18 deletions
|
@ -279,7 +279,7 @@ func (r *IrcRepo) CheckExistingNetwork(ctx context.Context, network *domain.IrcN
|
||||||
return &net, nil
|
return &net, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IrcRepo) StoreNetwork(network *domain.IrcNetwork) error {
|
func (r *IrcRepo) StoreNetwork(ctx context.Context, network *domain.IrcNetwork) error {
|
||||||
netName := toNullString(network.Name)
|
netName := toNullString(network.Name)
|
||||||
pass := toNullString(network.Pass)
|
pass := toNullString(network.Pass)
|
||||||
nick := toNullString(network.Nick)
|
nick := toNullString(network.Nick)
|
||||||
|
@ -289,7 +289,6 @@ func (r *IrcRepo) StoreNetwork(network *domain.IrcNetwork) error {
|
||||||
account := toNullString(network.Auth.Account)
|
account := toNullString(network.Auth.Account)
|
||||||
password := toNullString(network.Auth.Password)
|
password := toNullString(network.Auth.Password)
|
||||||
|
|
||||||
var err error
|
|
||||||
var retID int64
|
var retID int64
|
||||||
|
|
||||||
queryBuilder := r.db.squirrel.
|
queryBuilder := r.db.squirrel.
|
||||||
|
@ -327,13 +326,13 @@ func (r *IrcRepo) StoreNetwork(network *domain.IrcNetwork) error {
|
||||||
Suffix("RETURNING id").
|
Suffix("RETURNING id").
|
||||||
RunWith(r.db.handler)
|
RunWith(r.db.handler)
|
||||||
|
|
||||||
if err = queryBuilder.QueryRow().Scan(&retID); err != nil {
|
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||||
return errors.Wrap(err, "error executing query")
|
return errors.Wrap(err, "error executing query")
|
||||||
}
|
}
|
||||||
|
|
||||||
network.ID = retID
|
network.ID = retID
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IrcRepo) UpdateNetwork(ctx context.Context, network *domain.IrcNetwork) error {
|
func (r *IrcRepo) UpdateNetwork(ctx context.Context, network *domain.IrcNetwork) error {
|
||||||
|
@ -459,7 +458,6 @@ func (r *IrcRepo) StoreNetworkChannels(ctx context.Context, networkID int64, cha
|
||||||
func (r *IrcRepo) StoreChannel(ctx context.Context, networkID int64, channel *domain.IrcChannel) error {
|
func (r *IrcRepo) StoreChannel(ctx context.Context, networkID int64, channel *domain.IrcChannel) error {
|
||||||
pass := toNullString(channel.Password)
|
pass := toNullString(channel.Password)
|
||||||
|
|
||||||
var err error
|
|
||||||
if channel.ID != 0 {
|
if channel.ID != 0 {
|
||||||
// update record
|
// update record
|
||||||
channelQueryBuilder := r.db.squirrel.
|
channelQueryBuilder := r.db.squirrel.
|
||||||
|
@ -475,7 +473,7 @@ func (r *IrcRepo) StoreChannel(ctx context.Context, networkID int64, channel *do
|
||||||
return errors.Wrap(err, "error building query")
|
return errors.Wrap(err, "error building query")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = r.db.handler.ExecContext(ctx, query, args...); err != nil {
|
if _, err := r.db.handler.ExecContext(ctx, query, args...); err != nil {
|
||||||
return errors.Wrap(err, "error executing query")
|
return errors.Wrap(err, "error executing query")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -501,7 +499,7 @@ func (r *IrcRepo) StoreChannel(ctx context.Context, networkID int64, channel *do
|
||||||
// returning
|
// returning
|
||||||
var retID int64
|
var retID int64
|
||||||
|
|
||||||
if err = queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
|
||||||
return errors.Wrap(err, "error executing query")
|
return errors.Wrap(err, "error executing query")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +521,7 @@ func (r *IrcRepo) StoreChannel(ctx context.Context, networkID int64, channel *do
|
||||||
//channel.ID, err = res.LastInsertId()
|
//channel.ID, err = res.LastInsertId()
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IrcRepo) UpdateChannel(channel *domain.IrcChannel) error {
|
func (r *IrcRepo) UpdateChannel(channel *domain.IrcChannel) error {
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (m IrcMessage) Bytes() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IrcRepo interface {
|
type IrcRepo interface {
|
||||||
StoreNetwork(network *IrcNetwork) error
|
StoreNetwork(ctx context.Context, network *IrcNetwork) error
|
||||||
UpdateNetwork(ctx context.Context, network *IrcNetwork) error
|
UpdateNetwork(ctx context.Context, network *IrcNetwork) error
|
||||||
StoreChannel(ctx context.Context, networkID int64, channel *IrcChannel) error
|
StoreChannel(ctx context.Context, networkID int64, channel *IrcChannel) error
|
||||||
UpdateChannel(channel *IrcChannel) error
|
UpdateChannel(channel *IrcChannel) error
|
||||||
|
|
|
@ -561,17 +561,16 @@ func (s *service) StoreNetwork(ctx context.Context, network *domain.IrcNetwork)
|
||||||
}
|
}
|
||||||
|
|
||||||
if existingNetwork == nil {
|
if existingNetwork == nil {
|
||||||
if err := s.repo.StoreNetwork(network); err != nil {
|
if err := s.repo.StoreNetwork(ctx, network); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.log.Debug().Msgf("store network: %+v", network)
|
s.log.Debug().Msgf("store network: %+v", network)
|
||||||
|
|
||||||
if network.Channels != nil {
|
if network.Channels != nil {
|
||||||
for _, channel := range network.Channels {
|
for _, channel := range network.Channels {
|
||||||
if err := s.repo.StoreChannel(nil, network.ID, &channel); err != nil {
|
if err := s.repo.StoreChannel(ctx, network.ID, &channel); err != nil {
|
||||||
s.log.Error().Stack().Err(err).Msg("irc.storeChannel: error executing query")
|
s.log.Error().Stack().Err(err).Msg("irc.storeChannel: error executing query")
|
||||||
return errors.Wrap(err, "error storing channel on network")
|
return errors.Wrap(err, "error storing channel on network")
|
||||||
//return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -582,14 +581,14 @@ func (s *service) StoreNetwork(ctx context.Context, network *domain.IrcNetwork)
|
||||||
// get channels for existing network
|
// get channels for existing network
|
||||||
existingChannels, err := s.repo.ListChannels(existingNetwork.ID)
|
existingChannels, err := s.repo.ListChannels(existingNetwork.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error().Err(err).Msgf("failed to list channels for network %q", existingNetwork.Server)
|
s.log.Error().Err(err).Msgf("failed to list channels for network %s", existingNetwork.Server)
|
||||||
}
|
}
|
||||||
existingNetwork.Channels = existingChannels
|
existingNetwork.Channels = existingChannels
|
||||||
|
|
||||||
if network.Channels != nil {
|
if network.Channels != nil {
|
||||||
for _, channel := range network.Channels {
|
for _, channel := range network.Channels {
|
||||||
// add channels. Make sure it doesn't delete before
|
// add channels. Make sure it doesn't delete before
|
||||||
if err := s.repo.StoreChannel(nil, existingNetwork.ID, &channel); err != nil {
|
if err := s.repo.StoreChannel(ctx, existingNetwork.ID, &channel); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,10 +610,9 @@ func (s *service) StoreNetwork(ctx context.Context, network *domain.IrcNetwork)
|
||||||
// if nickserv account, nickserv password : changed - stay connected, and change those
|
// if nickserv account, nickserv password : changed - stay connected, and change those
|
||||||
// if channels len : changes - join or leave
|
// if channels len : changes - join or leave
|
||||||
|
|
||||||
err := s.checkIfNetworkRestartNeeded(existingNetwork)
|
if err := s.checkIfNetworkRestartNeeded(existingNetwork); err != nil {
|
||||||
if err != nil {
|
s.log.Error().Err(err).Msgf("could not restart network: %s", existingNetwork.Name)
|
||||||
s.log.Error().Err(err).Msgf("could not restart network: %+v", existingNetwork.Name)
|
return errors.New("could not restart network: %s", existingNetwork.Name)
|
||||||
return errors.New("could not restart network: %v", existingNetwork.Name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue