models

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package models contains structs and default functions used all over the application to avoid circular dependencies

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID       int
	Module   string
	Username string
	Password string
	Disabled bool
}

Account contains all required data from accounts in the application

type Cookie struct {
	ID         int
	Name       string
	Value      string
	Expiration sql.NullTime
	Module     string
	Disabled   bool
}

Cookie contains all the required details to set cookies for domains

func (*Cookie) GetDisplayExpirationDate

func (c *Cookie) GetDisplayExpirationDate() string

GetDisplayExpirationDate returns an empty string if the date is null or else an RFC822 formatted string

type DatabaseInterface

type DatabaseInterface interface {
	// tracked item storage functionality
	GetTrackedItems(module ModuleInterface, includeCompleted bool) []*TrackedItem
	GetFirstOrCreateTrackedItem(uri string, module ModuleInterface) *TrackedItem
	CreateTrackedItem(uri string, module ModuleInterface)
	ChangeTrackedItemCompleteStatus(trackedItem *TrackedItem, complete bool)

	// account storage functionality
	CreateAccount(user string, password string, module ModuleInterface)
	GetFirstOrCreateAccount(user string, password string, module ModuleInterface) *Account
	GetAccount(module ModuleInterface) *Account
	UpdateTrackedItem(trackedItem *TrackedItem, currentItem string)

	// OAuth2 client storage functionality
	CreateOAuthClient(id string, secret string, accessToken string, refreshToken string, module ModuleInterface)
	GetFirstOrCreateOAuthClient(
		id string, secret string, accessToken string, refreshToken string, module ModuleInterface,
	) *OAuthClient
	GetOAuthClient(module ModuleInterface) *OAuthClient

	// cookie storage functionality
	GetAllCookies(module ModuleInterface) (cookies []*Cookie)
	GetCookie(name string, module ModuleInterface) *Cookie
	GetFirstOrCreateCookie(name string, value string, expirationString string, module ModuleInterface) *Cookie
	CreateCookie(name string, value string, expiration sql.NullTime, module ModuleInterface)
	UpdateCookie(name string, value string, expirationString string, module ModuleInterface)
	UpdateCookieDisabledStatus(name string, disabled bool, module ModuleInterface)
}

DatabaseInterface of used functions from the application to eventually change the underlying library

type DownloadQueueItem

type DownloadQueueItem struct {
	ItemID      string
	DownloadTag string
	FileName    string
	FileURI     string
}

DownloadQueueItem is a generic struct in case the module doesn't require special actions

type Module

type Module struct {
	ModuleInterface
	DbIO           DatabaseInterface
	Session        http.SessionInterface
	Key            string
	RequiresLogin  bool
	LoggedIn       bool
	TriedLogin     bool
	URISchemas     []*regexp.Regexp
	ProxyLoopIndex int
}

Module is an implementation to the ModuleInterface to provide basic functions/variables

func (*Module) AddProxyCommands

func (t *Module) AddProxyCommands(command *cobra.Command)

AddProxyCommands adds the module specific commands for the proxy server

func (*Module) AddProxyLoopCommands

func (t *Module) AddProxyLoopCommands(command *cobra.Command)

AddProxyLoopCommands adds the proxies sub command for the passed command

func (*Module) GetFileExtension

func (t *Module) GetFileExtension(uri string) string

GetFileExtension retrieves the file extension of a passed uri

func (*Module) GetFileName

func (t *Module) GetFileName(uri string) string

GetFileName retrieves the file name of a passed uri

func (*Module) GetProxySettings

func (t *Module) GetProxySettings() (proxySettings *http.ProxySettings)

GetProxySettings returns the proxy settings for the module

func (*Module) GetViperModuleKey

func (t *Module) GetViperModuleKey() string

GetViperModuleKey returns the module key without "." characters since they'll ruin the generated tree structure

func (*Module) ModuleKey

func (t *Module) ModuleKey() string

ModuleKey returns the key of the module required to use as interface to prevent import cycles

func (*Module) ProcessDownloadQueue

func (t *Module) ProcessDownloadQueue(downloadQueue []DownloadQueueItem, trackedItem *TrackedItem) error

ProcessDownloadQueue processes the default download queue, can be used if the module doesn't require special actions

func (*Module) RegisterURISchema

func (t *Module) RegisterURISchema(uriSchemas map[string][]*regexp.Regexp)

RegisterURISchema registers the URI schemas of the module to the passed map

func (*Module) ReverseDownloadQueueItems

func (t *Module) ReverseDownloadQueueItems(downloadQueue []DownloadQueueItem) []DownloadQueueItem

ReverseDownloadQueueItems reverses the download queue items to get the oldest items first to be able to interrupt the update process anytime

func (Module) SanitizePath

func (t Module) SanitizePath(path string, allowSeparator bool) string

SanitizePath replaces reserved characters https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words and trims the result

func (*Module) SetDbIO

func (t *Module) SetDbIO(io DatabaseInterface)

SetDbIO sets the database IO implementation

type ModuleInterface

type ModuleInterface interface {
	// retrieve the module key
	ModuleKey() string
	// initializes the registered bare module
	InitializeModule()
	// option for the modules to register custom settings/commands
	AddSettingsCommand(command *cobra.Command)
	// Login logs us in for the current session if possible/account available
	Login(account *Account) (success bool)
	// Parse parses the tracked item
	Parse(item *TrackedItem) error
}

ModuleInterface of used functions from the application for all modules

type OAuthClient

type OAuthClient struct {
	ID           int
	ClientID     string
	ClientSecret string
	AccessToken  string
	RefreshToken string
	Module       string
	Disabled     bool
}

OAuthClient contains all the required details to create an OAuth client aside from URLs

func (*OAuthClient) GetClient

func (c *OAuthClient) GetClient(authURL string, tokenURL string, scopes []string) *http.Client

GetClient returns an http client implementing the OAuth2 configuration

type ProxyLoopConfiguration

type ProxyLoopConfiguration struct {
	Loop        bool                 `mapstructure:"loop"`
	Proxy       http.ProxySettings   `mapstructure:"proxy"`
	LoopProxies []http.ProxySettings `mapstructure:"loopproxies"`
}

ProxyLoopConfiguration contains the configuration for loop proxy configurations

type TrackedItem

type TrackedItem struct {
	ID          int
	URI         string
	CurrentItem string
	Module      string
	Complete    bool
}

TrackedItem contains all required data from tracked items in the application

Jump to

Keyboard shortcuts

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