Skip to content

Commit

Permalink
Merge branch 'main' into dn2_bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 21, 2024
2 parents 27adcdf + 2397db5 commit cb6be3d
Show file tree
Hide file tree
Showing 80 changed files with 578 additions and 542 deletions.
27 changes: 7 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude funlen for testing files.
- linters:
- nonamedreturns
- wsl
- cyclop
- nolintlint
path: 'cmd/'
linters:
enable-all: true
disable:
# deprecated
- gomnd
- execinquery
# unused
- exhaustruct
- exhaustive
- dupl
- nlreturn
- nonamedreturns
- varnamelen
- godot # does not work with annotations.
- perfsprint
- musttag # broken in 1.59.
- depguard
- tagalign
# unused
- exhaustruct # This will never work in this app.
- dupl # Maybe one day we can reduce the duplicate code with generics.
- nlreturn # Not needed because wsl is good enough; better actually.
- godot # Does not work with annotations.
- musttag # Broken in 1.59: https://github.com/go-simpler/musttag/issues/98
- depguard # Not even sure why this is useful. We have too many deps to care.
run:
timeout: 5m
output:
Expand Down
8 changes: 4 additions & 4 deletions pkg/apps/apppkg/plex/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ func (s *Server) HandleKillSession(r *http.Request) (int, interface{}) {
// @Failure 404 {object} string "bad token or api key"
// @Router /api/plex/1/directory [get]
// @Security ApiKeyAuth
func (s *Server) HandleDirectory(r *http.Request) (int, interface{}) {
plexID, _ := r.Context().Value(starr.Plex).(int)
func (s *Server) HandleDirectory(req *http.Request) (int, interface{}) {
plexID, _ := req.Context().Value(starr.Plex).(int)

directory, err := s.GetDirectoryWithContext(r.Context())
directory, err := s.GetDirectoryWithContext(req.Context())
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("directory request failed (%d): %w", plexID, err)
}

for idx, library := range directory.Directory {
directory.Directory[idx].TrashSize, err = s.GetDirectoryTrashSizeWithContext(r.Context(), library.Key)
directory.Directory[idx].TrashSize, err = s.GetDirectoryTrashSizeWithContext(req.Context(), library.Key)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("directory trash request failed (%d): %w", plexID, err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/apps/apppkg/plex/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ func (s *Server) GetInfo(ctx context.Context) (*PMSInfo, error) {
return nil, err
}

var v struct {
var output struct {
MediaContainer *PMSInfo `json:"MediaContainer"`
}

if err := json.Unmarshal(data, &v); err != nil {
if err := json.Unmarshal(data, &output); err != nil {
return nil, fmt.Errorf("unmarshaling main page from %s: %w", s.config.URL, err)
}

s.name = v.MediaContainer.FriendlyName
s.name = output.MediaContainer.FriendlyName

return v.MediaContainer, nil
return output.MediaContainer, nil
}

// PMSInfo is the `/` path on Plex.
Expand Down
11 changes: 6 additions & 5 deletions pkg/apps/apppkg/plex/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// This package also provides a web handler for incoming plex webhooks, and another
// two handlers for requests from Notifiarr.com to list sessions and kill a session.
// The purpose is to keep track of Plex viewers and send meaningful alerts to their
// respective Disord server about user behavior.
// respective Discord server about user behavior.
// ie. user started watching something, paused it, resumed it, and finished something.
// This package can be disabled by not providing a Plex Media Server URL or Token.
package plex

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -24,9 +25,9 @@ type Server struct {
}

type Config struct {
URL string `toml:"url" json:"url" xml:"url"`
Token string `toml:"token" json:"token" xml:"token"`
Client *http.Client `toml:"-" json:"-" xml:"-"`
URL string `json:"url" toml:"url" xml:"url"`
Token string `json:"token" toml:"token" xml:"token"`
Client *http.Client `json:"-" toml:"-" xml:"-"`
}

// New turns a config into a server.
Expand All @@ -48,7 +49,7 @@ func (s *Server) Name() string {
}

// ErrNoURLToken is returned when there is no token or URL.
var ErrNoURLToken = fmt.Errorf("token or URL for Plex missing")
var ErrNoURLToken = errors.New("token or URL for Plex missing")

func (s *Server) getPlexURL(ctx context.Context, url string, params url.Values) ([]byte, error) {
return s.reqPlexURL(ctx, url, http.MethodGet, params, nil)
Expand Down
18 changes: 9 additions & 9 deletions pkg/apps/apppkg/plex/sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ func (s *Server) GetPlexSectionKeyWithContext(ctx context.Context, keyPath strin
return nil, err
}

var v struct {
var output struct {
MediaContainer *MediaSection `json:"MediaContainer"`
}

if err := json.Unmarshal(data, &v); err != nil {
if err := json.Unmarshal(data, &output); err != nil {
return nil, fmt.Errorf("parsing library section from %s: %w; failed payload: %s", url, err, string(data))
}

return v.MediaContainer, nil
return output.MediaContainer, nil
}

// GetDirectory returns data about all the library sections.
Expand All @@ -221,15 +221,15 @@ func (s *Server) GetDirectoryWithContext(ctx context.Context) (*SectionDirectory
return nil, err
}

var v struct {
var output struct {
MediaContainer *SectionDirectory `json:"MediaContainer"`
}

if err := json.Unmarshal(data, &v); err != nil {
if err := json.Unmarshal(data, &output); err != nil {
return nil, fmt.Errorf("unmarshaling directory from %s: %w; failed payload: %s", url, err, string(data))
}

return v.MediaContainer, nil
return output.MediaContainer, nil
}

// GetDirectoryWithContext returns data about all the library sections.
Expand All @@ -244,13 +244,13 @@ func (s *Server) GetDirectoryTrashSizeWithContext(ctx context.Context, key strin
return 0, err
}

var v struct {
var output struct {
MediaContainer *SectionDirectory `json:"MediaContainer"`
}

if err := json.Unmarshal(data, &v); err != nil {
if err := json.Unmarshal(data, &output); err != nil {
return 0, fmt.Errorf("unmarshaling trash directory from %s: %w; failed payload: %s", uri, err, string(data))
}

return v.MediaContainer.Size, nil
return output.MediaContainer.Size, nil
}
9 changes: 5 additions & 4 deletions pkg/apps/apppkg/plex/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plex
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/url"
"strings"
Expand All @@ -16,7 +17,7 @@ type Sessions struct {
}

// ErrBadStatus is returned when plex returns an invalid status code.
var ErrBadStatus = fmt.Errorf("status code not 200")
var ErrBadStatus = errors.New("status code not 200")

// GetSessions returns the Plex sessions in JSON format, no timeout.
func (s *Server) GetSessions() (*Sessions, error) {
Expand All @@ -26,7 +27,7 @@ func (s *Server) GetSessions() (*Sessions, error) {
// GetSessionsWithContext returns the Plex sessions in JSON format.
func (s *Server) GetSessionsWithContext(ctx context.Context) (*Sessions, error) {
var (
v struct {
output struct {
//nolint:tagliatelle
MediaContainer struct {
Sessions []*Session `json:"Metadata"`
Expand All @@ -40,11 +41,11 @@ func (s *Server) GetSessionsWithContext(ctx context.Context) (*Sessions, error)
return sessions, fmt.Errorf("%w: %s", err, string(body))
}

if err = json.Unmarshal(body, &v); err != nil {
if err = json.Unmarshal(body, &output); err != nil {
return sessions, fmt.Errorf("parsing plex sessions (TRY UPGRADING PLEX): %w: %s", err, string(body))
}

sessions.Sessions = v.MediaContainer.Sessions
sessions.Sessions = output.MediaContainer.Sessions

return sessions, nil
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/apps/apppkg/sabnzbd/sabnzbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -15,12 +16,12 @@ import (
"github.com/Notifiarr/notifiarr/pkg/mnd"
)

var ErrUnknownByteType = fmt.Errorf("unknown byte type")
var ErrUnknownByteType = errors.New("unknown byte type")

type Config struct {
URL string `toml:"url" xml:"url"`
URL string `toml:"url" xml:"url"`
APIKey string `toml:"api_key" xml:"api_key"`
*http.Client `toml:"-" xml:"-" json:"-"`
*http.Client `json:"-" toml:"-" xml:"-"`
}

// QueueSlots has the following data structure.
Expand Down Expand Up @@ -270,14 +271,16 @@ type SabNZBDate struct {
}

// UnmarshalJSON exists because weird date formats and "unknown" seem sane in json output.
func (s *SabNZBDate) UnmarshalJSON(b []byte) (err error) {
func (s *SabNZBDate) UnmarshalJSON(b []byte) error {
s.String = strings.Trim(string(b), `"`)

if s.String == "unknown" {
s.Time = time.Now().Add(time.Hour * 24 * 366) //nolint:mnd
return nil
}

var err error

s.Time, err = time.Parse("15:04 Mon 02 Jan 2006", s.String+" "+strconv.Itoa(time.Now().Year()))
if err != nil {
return fmt.Errorf("invalid time: %w", err)
Expand All @@ -287,7 +290,7 @@ func (s *SabNZBDate) UnmarshalJSON(b []byte) (err error) {
}

// UnmarshalJSON exists because someone decided that bytes should be strings with letters.
func (s *SabNZBSize) UnmarshalJSON(b []byte) (err error) {
func (s *SabNZBSize) UnmarshalJSON(b []byte) error {
s.String = strings.Trim(string(b), `"`)
split := strings.Split(s.String, " ")

Expand Down
6 changes: 3 additions & 3 deletions pkg/apps/apppkg/tautulli/tautulli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

// Config is the Tautulli configuration.
type Config struct {
URL string `toml:"url" xml:"url" json:"url"`
APIKey string `toml:"api_key" xml:"api_key" json:"apiKey"`
*http.Client `toml:"-" xml:"-" json:"-"`
URL string `json:"url" toml:"url" xml:"url"`
APIKey string `json:"apiKey" toml:"api_key" xml:"api_key"`
*http.Client `json:"-" toml:"-" xml:"-"`
}

// GetURLInto gets a url and unmarshals the contents into the provided interface pointer.
Expand Down
20 changes: 10 additions & 10 deletions pkg/apps/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *TautulliConfig) Enabled() bool {
type DelugeConfig struct {
ExtraConfig
*deluge.Config
*deluge.Deluge `toml:"-" xml:"-" json:"-"`
*deluge.Deluge `json:"-" toml:"-" xml:"-"`
}

func (a *Apps) setupDeluge() error {
Expand Down Expand Up @@ -184,7 +184,7 @@ func (c *SabNZBConfig) Enabled() bool {
type QbitConfig struct {
ExtraConfig
*qbit.Config
*qbit.Qbit `toml:"-" xml:"-" json:"-"`
*qbit.Qbit `json:"-" toml:"-" xml:"-"`
}

func (a *Apps) setupQbit() error {
Expand Down Expand Up @@ -233,9 +233,9 @@ func (c *QbitConfig) Enabled() bool {
type RtorrentConfig struct {
ExtraConfig
*xmlrpc.Client
URL string `toml:"url" xml:"url" json:"url"`
User string `toml:"user" xml:"user" json:"user"`
Pass string `toml:"pass" xml:"pass" json:"pass"`
URL string `json:"url" toml:"url" xml:"url"`
User string `json:"user" toml:"user" xml:"user"`
Pass string `json:"pass" toml:"pass" xml:"pass"`
}

func (a *Apps) setupRtorrent() error {
Expand Down Expand Up @@ -289,7 +289,7 @@ func (c *RtorrentConfig) Enabled() bool {
type NZBGetConfig struct {
ExtraConfig
*nzbget.Config
*nzbget.NZBGet `toml:"-" xml:"-" json:"-"`
*nzbget.NZBGet `json:"-" toml:"-" xml:"-"`
}

func (a *Apps) setupNZBGet() error {
Expand Down Expand Up @@ -325,11 +325,11 @@ func (c *NZBGetConfig) Enabled() bool {

// XmissionConfig is the Transmission input configuration.
type XmissionConfig struct {
URL string `toml:"url" xml:"url" json:"url"`
User string `toml:"user" xml:"user" json:"user"`
Pass string `toml:"pass" xml:"pass" json:"pass"`
URL string `json:"url" toml:"url" xml:"url"`
User string `json:"user" toml:"user" xml:"user"`
Pass string `json:"pass" toml:"pass" xml:"pass"`
ExtraConfig
*transmissionrpc.Client `toml:"-" xml:"-" json:"-"`
*transmissionrpc.Client `json:"-" toml:"-" xml:"-"`
}

// Enabled returns true if the instance is enabled and usable.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apps/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (a *Apps) lidarrHandlers() {
type LidarrConfig struct {
ExtraConfig
*starr.Config
*lidarr.Lidarr `toml:"-" xml:"-" json:"-"`
errorf func(string, ...interface{}) `toml:"-" xml:"-" json:"-"`
*lidarr.Lidarr `json:"-" toml:"-" xml:"-"`
errorf func(string, ...interface{}) `json:"-" toml:"-" xml:"-"`
}

func getLidarr(r *http.Request) *LidarrConfig {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apps/prowlarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (a *Apps) prowlarrHandlers() {
type ProwlarrConfig struct {
ExtraConfig
*starr.Config
*prowlarr.Prowlarr `toml:"-" xml:"-" json:"-"`
errorf func(string, ...interface{}) `toml:"-" xml:"-" json:"-"`
*prowlarr.Prowlarr `json:"-" toml:"-" xml:"-"`
errorf func(string, ...interface{}) `json:"-" toml:"-" xml:"-"`
}

func getProwlarr(r *http.Request) *prowlarr.Prowlarr {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apps/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (a *Apps) radarrHandlers() {
type RadarrConfig struct {
ExtraConfig
*starr.Config
*radarr.Radarr `toml:"-" xml:"-" json:"-"`
errorf func(string, ...interface{}) `toml:"-" xml:"-" json:"-"`
*radarr.Radarr `json:"-" toml:"-" xml:"-"`
errorf func(string, ...interface{}) `json:"-" toml:"-" xml:"-"`
}

func getRadarr(r *http.Request) *RadarrConfig {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apps/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (a *Apps) readarrHandlers() {
type ReadarrConfig struct {
ExtraConfig
*starr.Config
*readarr.Readarr `toml:"-" xml:"-" json:"-"`
errorf func(string, ...interface{}) `toml:"-" xml:"-" json:"-"`
*readarr.Readarr `json:"-" toml:"-" xml:"-"`
errorf func(string, ...interface{}) `json:"-" toml:"-" xml:"-"`
}

func getReadarr(r *http.Request) *ReadarrConfig {
Expand Down
Loading

0 comments on commit cb6be3d

Please sign in to comment.