mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
Feature: Improve config for http server (#67)
* feat: improve config for http server * Feature: Support multiple action status per release (#69) * feat: move release actions to separate table * chore: update sqlite driver * fix(indexers): btn api client (#71) What: * Api key and torrentId in wrong order * Set hardcoded ID in jsonrpc request object * ParsetorrentId from url Fixes #68 * feat: show irc network status in settings list * feat: show irc channel status * chore: go mod tidy * feat: improve config for http server * feat: add context to user repo * feat: only set secure cookie if https
This commit is contained in:
parent
3475dddec7
commit
efa84fee8b
9 changed files with 74 additions and 56 deletions
|
@ -1,6 +1,7 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -16,10 +17,10 @@ func NewUserRepo(db *sql.DB) domain.UserRepo {
|
|||
return &UserRepo{db: db}
|
||||
}
|
||||
|
||||
func (r *UserRepo) FindByUsername(username string) (*domain.User, error) {
|
||||
func (r *UserRepo) FindByUsername(ctx context.Context, username string) (*domain.User, error) {
|
||||
query := `SELECT id, username, password FROM users WHERE username = ?`
|
||||
|
||||
row := r.db.QueryRow(query, username)
|
||||
row := r.db.QueryRowContext(ctx, query, username)
|
||||
if err := row.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -34,12 +35,12 @@ func (r *UserRepo) FindByUsername(username string) (*domain.User, error) {
|
|||
return &user, nil
|
||||
}
|
||||
|
||||
func (r *UserRepo) Store(user domain.User) error {
|
||||
func (r *UserRepo) Store(ctx context.Context, user domain.User) error {
|
||||
|
||||
var err error
|
||||
if user.ID != 0 {
|
||||
update := `UPDATE users SET password = ? WHERE username = ?`
|
||||
_, err = r.db.Exec(update, user.Password, user.Username)
|
||||
_, err = r.db.ExecContext(ctx, update, user.Password, user.Username)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error executing query")
|
||||
return err
|
||||
|
@ -47,7 +48,7 @@ func (r *UserRepo) Store(user domain.User) error {
|
|||
|
||||
} else {
|
||||
query := `INSERT INTO users (username, password) VALUES (?, ?)`
|
||||
_, err = r.db.Exec(query, user.Username, user.Password)
|
||||
_, err = r.db.ExecContext(ctx, query, user.Username, user.Password)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error executing query")
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue