diff --git a/.github/workflows/artifact.yml b/.github/workflows/artifact.yml deleted file mode 100644 index f2eaf0a2..00000000 --- a/.github/workflows/artifact.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Remove old artifacts - -on: - schedule: - # Every every day at 02:00 (UTC) - - cron: '0 2 * * *' - -jobs: - remove-old-artifacts: - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - name: Remove old artifacts - uses: c-hive/gha-remove-artifacts@v1 - with: - age: '1 days' - skip-recent: 3 \ No newline at end of file diff --git a/triggers/bernard/bernard.go b/triggers/bernard/bernard.go index 7f460d44..55f0d29c 100644 --- a/triggers/bernard/bernard.go +++ b/triggers/bernard/bernard.go @@ -375,5 +375,10 @@ func (d daemon) getScanTask(drive *drive, paths *Paths) *scanTask { } func (d daemon) withDriveLog(driveID string) zerolog.Logger { - return d.log.With().Str("drive_id", driveID).Logger() + drive, err := d.store.GetDrive(driveID) + if err != nil { + return d.log.With().Str("drive_id", driveID).Logger() + } + + return d.log.With().Str("drive_id", driveID).Str("drive_name", drive.Name).Logger() } diff --git a/triggers/bernard/datastore.go b/triggers/bernard/datastore.go index 694f4e50..7fb2ab92 100644 --- a/triggers/bernard/datastore.go +++ b/triggers/bernard/datastore.go @@ -51,3 +51,23 @@ func (d *bds) GetFolder(driveID string, folderID string) (*datastore.Folder, err return f, nil } + +const sqlSelectDrive = `SELECT d.id, f.name, d.pageToken FROM drive d JOIN folder f ON f.id = d.id WHERE d.id = $1 LIMIT 1` + +func (d *bds) GetDrive(driveID string) (*datastore.Drive, error) { + drv := new(datastore.Drive) + + row := d.DB.QueryRow(sqlSelectDrive, driveID) + err := row.Scan(&drv.ID, &drv.Name, &drv.PageToken) + + switch { + case errors.Is(err, sql.ErrNoRows): + return nil, fmt.Errorf("%v: drive not found: %w", driveID, sql.ErrNoRows) + case err != nil: + return nil, err + default: + break + } + + return drv, nil +} diff --git a/triggers/bernard/paths.go b/triggers/bernard/paths.go index 71506fe4..9be807f8 100644 --- a/triggers/bernard/paths.go +++ b/triggers/bernard/paths.go @@ -72,6 +72,10 @@ func getDiffFolderMaps(diff *sqlite.Difference) *diffFolderMaps { oldFolders[f.Old.ID] = diff.ChangedFolders[i].Old } + for i, f := range diff.RemovedFolders { + oldFolders[f.ID] = diff.RemovedFolders[i] + } + return &diffFolderMaps{ Current: currentFolders, Old: oldFolders, @@ -105,7 +109,7 @@ func getDiffFolders(store *bds, driveId string, diff *sqlite.Difference) (*Paren for _, file := range diff.AddedFiles { folder, err := getFolder(store, driveId, file.Parent, folderMaps.Current) if err != nil { - return nil, err + return nil, fmt.Errorf("added file: %w", err) } newParents[folder.ID] = *folder @@ -116,7 +120,7 @@ func getDiffFolders(store *bds, driveId string, diff *sqlite.Difference) (*Paren // current currentFolder, err := getFolder(store, driveId, file.New.Parent, folderMaps.Current) if err != nil { - return nil, err + return nil, fmt.Errorf("changed new file: %w", err) } newParents[currentFolder.ID] = *currentFolder @@ -124,7 +128,7 @@ func getDiffFolders(store *bds, driveId string, diff *sqlite.Difference) (*Paren // old oldFolder, err := getFolder(store, driveId, file.Old.Parent, folderMaps.Old) if err != nil { - return nil, err + return nil, fmt.Errorf("changed old file: %w", err) } oldParents[oldFolder.ID] = *oldFolder @@ -134,7 +138,7 @@ func getDiffFolders(store *bds, driveId string, diff *sqlite.Difference) (*Paren for _, file := range diff.RemovedFiles { oldFolder, err := getFolder(store, driveId, file.Parent, folderMaps.Old) if err != nil { - return nil, err + return nil, fmt.Errorf("removed file: %w", err) } oldParents[oldFolder.ID] = *oldFolder diff --git a/triggers/lidarr/lidarr.go b/triggers/lidarr/lidarr.go index dacd3c2f..90d035e1 100644 --- a/triggers/lidarr/lidarr.go +++ b/triggers/lidarr/lidarr.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "path" + "strings" "time" "github.com/cloudbox/autoscan" @@ -64,13 +65,13 @@ func (h handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { l.Trace().Interface("event", event).Msg("Received JSON body") - if event.Type == "Test" { + if strings.EqualFold(event.Type, "Test") { l.Debug().Msg("Received test event") rw.WriteHeader(http.StatusOK) return } - if event.Type != "Download" || len(event.Files) == 0 { + if !strings.EqualFold(event.Type, "Download") || len(event.Files) == 0 { l.Error().Msg("Required fields are missing") rw.WriteHeader(http.StatusBadRequest) return diff --git a/triggers/radarr/radarr.go b/triggers/radarr/radarr.go index 6432540a..e0ecf059 100644 --- a/triggers/radarr/radarr.go +++ b/triggers/radarr/radarr.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "path" + "strings" "time" "github.com/cloudbox/autoscan" @@ -68,13 +69,13 @@ func (h handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { rlog.Trace().Interface("event", event).Msg("Received JSON body") - if event.Type == "Test" { + if strings.EqualFold(event.Type, "Test") { rlog.Debug().Msg("Received test event") rw.WriteHeader(http.StatusOK) return } - if event.Type != "Download" || event.File.RelativePath == "" || event.Movie.FolderPath == "" { + if !strings.EqualFold(event.Type, "Download") || event.File.RelativePath == "" || event.Movie.FolderPath == "" { rlog.Error().Msg("Required fields are missing") rw.WriteHeader(http.StatusBadRequest) return diff --git a/triggers/sonarr/sonarr.go b/triggers/sonarr/sonarr.go index 3e6c5e6c..f1fded83 100644 --- a/triggers/sonarr/sonarr.go +++ b/triggers/sonarr/sonarr.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "path" + "strings" "time" "github.com/cloudbox/autoscan" @@ -68,13 +69,13 @@ func (h handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { rlog.Trace().Interface("event", event).Msg("Received JSON body") - if event.Type == "Test" { + if strings.EqualFold(event.Type, "Test") { rlog.Debug().Msg("Received test event") rw.WriteHeader(http.StatusOK) return } - if event.Type != "Download" || event.File.RelativePath == "" || event.Series.Path == "" { + if !strings.EqualFold(event.Type, "Download") || event.File.RelativePath == "" || event.Series.Path == "" { rlog.Error().Msg("Required fields are missing") rw.WriteHeader(http.StatusBadRequest) return