website

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetries is the number of times to attempt a request to notifiarr.com.
	// 4 means 5 total tries: 1 try + 4 retries.
	DefaultRetries = 4
	// RetryDelay is how long to Sleep between retries.
	RetryDelay = 222 * time.Millisecond
	// APIKeyLength is the string length of a valid notifiarr API key.
	APIKeyLength = 36
)

Variables

View Source
var (
	ErrNon200          = fmt.Errorf("return code was not 200")
	ErrInvalidResponse = fmt.Errorf("invalid response")
	ErrNoChannel       = fmt.Errorf("the website send-data channel is closed")
	ErrInvalidAPIKey   = fmt.Errorf("configured notifiarr API key is invalid")
)

Errors returned by this library.

Functions

This section is empty.

Types

type Config

type Config struct {
	Apps       *apps.Apps
	Retries    int
	BaseURL    string
	Timeout    cnfg.Duration
	HostID     string
	BindAddr   string
	mnd.Logger // log file writer
}

Config is the input data needed to send payloads to notifiarr.

type EventType

type EventType string

EventType identifies the type of event that sent a paylaod to notifiarr.

const (
	EventCron    EventType = "cron"
	EventGUI     EventType = "gui"
	EventUser    EventType = "user"
	EventAPI     EventType = "api"
	EventHook    EventType = "webhook"
	EventStart   EventType = "start"
	EventMovie   EventType = "movie"
	EventEpisode EventType = "episode"
	EventPoll    EventType = "poll"
	EventSignal  EventType = "signal"
	EventFile    EventType = "file"
	EventSet     EventType = "setStates"
	EventGet     EventType = "getStates"
)

These are all our known event types.

type Payload

type Payload struct {
	Plex *plex.Sessions        `json:"plex,omitempty"`
	Snap *snapshot.Snapshot    `json:"snapshot,omitempty"`
	Load *plex.IncomingWebhook `json:"payload,omitempty"`
}

Payload is the outbound payload structure that is sent to Notifiarr for Plex and system snapshot data.

type Request

type Request struct {
	Route      Route
	Event      EventType
	Params     []string    // optional.
	Payload    interface{} // data to send.
	UploadFile *UploadFile // file to send (instead of payload).
	LogMsg     string      // if empty, nothing is logged.
	LogPayload bool        // debug log the sent payload.
	ErrorsOnly bool        // only log errors.
	// contains filtered or unexported fields
}

Request is used when sending data through a channel.

type Response

type Response struct {
	Result  string `json:"result"`
	Details struct {
		Response json.RawMessage `json:"response"` // can be anything. type it out later.
		Help     string          `json:"help"`
		Started  time.Time       `json:"started"`
		Finished time.Time       `json:"finished"`
		Elapsed  cnfg.Duration   `json:"elapsed"`
	} `json:"details"`
	// contains filtered or unexported fields
}

Response is what notifiarr replies to our requests with.

try this
{
    "response": "success",
    "message": {
        "response": {
            "instance": 1,
            "debug": null
        },
        "started": "23:57:03",
        "finished": "23:57:03",
        "elapsed": "0s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Service status cron processed.",
        "started": "00:04:15",
        "finished": "00:04:15",
        "elapsed": "0s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Channel stats cron processed.",
        "started": "00:04:31",
        "finished": "00:04:36",
        "elapsed": "5s"
    }
}
{
    "response": "success",
    "message": {
        "response": "Dashboard payload processed.",
        "started": "00:02:04",
        "finished": "00:02:11",
        "elapsed": "7s"
    }
}

nitsua: all responses should be that way.. but response might not always be an object.

func (*Response) String

func (r *Response) String() string

String turns the response into a log entry.

type Route

type Route string

Route is used to give us methods on our route paths.

const (
	BaseURL = "https://notifiarr.com"

	ClientRoute  Route = userRoute2 + "/client"
	CFSyncRoute  Route = userRoute1 + "/trash"
	GapsRoute    Route = userRoute1 + "/gaps"
	MdbListRoute Route = userRoute1 + "/mdblist"

	DashRoute     Route = notifiRoute + "/dashboard"
	StuckRoute    Route = notifiRoute + "/stuck"
	DownloadRoute Route = notifiRoute + "/downloads"
	PlexRoute     Route = notifiRoute + "/plex"
	SnapRoute     Route = notifiRoute + "/snapshot"
	SvcRoute      Route = notifiRoute + "/services"
	CorruptRoute  Route = notifiRoute + "/corruption"
	BackupRoute   Route = notifiRoute + "/backup"
	TestRoute     Route = notifiRoute + "/test"
	PkgRoute      Route = notifiRoute + "/packageManager"
	LogLineRoute  Route = notifiRoute + "/logWatcher"
	CommandRoute  Route = notifiRoute + "/command"

	UploadRoute Route = systemRoute + "/upload"
)

Notifiarr URLs. Data sent to these URLs:

api/v1/notification/plex?event=...

api (was plexcron)
user (was plexcron)
cron (was plexcron)
webhook (was plexhook)
movie
episode

api/v1/notification/services?event=...

api
user
cron
start (only fires on startup)

api/v1/notification/snapshot?event=...

api
user
cron

api/v1/notification/dashboard?event=... (requires interval from website/client endpoint)

api
user
cron

api/v1/notification/stuck?event=...

api
user
cron

api/v1/user/gaps?app=radarr&event=...

api
user
cron

api/v2/user/client?event=start

see description https://github.com/Notifiarr/notifiarr/pull/115

api/v1/user/trash?app=...

radarr
sonarr

func (Route) Path

func (r Route) Path(event EventType, params ...string) string

Path adds parameters to a route path and turns it into a string.

type Server

type Server struct {
	Config *Config
	// contains filtered or unexported fields
}

Server is what you get for providing a Config to New().

func New

func New(c *Config) *Server

func (*Server) DelState added in v0.4.1

func (s *Server) DelState(_ context.Context, keys ...string) error

DelState deletes a value stored in the website database.

func (*Server) GetData

func (s *Server) GetData(req *Request) (*Response, error)

GetData sends data to a notifiarr URL as JSON.

func (*Server) GetHostInfo

func (s *Server) GetHostInfo(ctx context.Context) (*host.InfoStat, error)

GetHostInfo attempts to make a unique machine identifier...

func (*Server) GetState added in v0.4.1

func (s *Server) GetState(_ context.Context, keys ...string) (map[string][]byte, error)

GetState gets a value stored in the website database.

func (*Server) RawGetData

func (s *Server) RawGetData(ctx context.Context, req *Request) (*Response, time.Duration, error)

RawGetData sends a request to the website without using a channel. Avoid this method.

func (*Server) SendData

func (s *Server) SendData(req *Request)

SendData puts a send-data request to notifiarr.com into a channel queue.

func (*Server) SetState added in v0.4.1

func (s *Server) SetState(ctx context.Context, key string, value []byte) error

SetState sets a value stored in the website database.

func (*Server) SetStates added in v0.4.1

func (s *Server) SetStates(_ context.Context, values map[string][]byte) error

SetStates sets values stored in the website database.

func (*Server) Start

func (s *Server) Start(ctx context.Context)

Start runs the website go routine.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the website go routine.

type UploadFile added in v0.7.0

type UploadFile struct {
	FileName string
	io.ReadCloser
}

UploadFile is the file upload identifier in a request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL