models

package
v0.0.0-...-bd23c5e Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermWritePage = 1 << iota
	PermDeletePage

	PermWriteUser
	PermDeleteUser

	PermWriteConfig
)

Variables

View Source
var DefaultPages = []Page{
	{
		Title:     "Anime",
		SortValue: 1,
		Providers: pq.Int64Array{int64(NYAA), int64(SUBSPLEASE)},
		Modifiers: []Modifier{
			{
				Title: "Category",
				Key:   "categories",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "anime",
						Value: "Anime",
					},
					{
						Key:   "anime-amv",
						Value: "Music Video",
					},
					{
						Key:   "anime-eng",
						Value: "English Translated",
					},
					{
						Key:   "anime-non-eng",
						Value: "Non-English Translated",
					},
				},
			},
			{
				Title: "Sort",
				Key:   "sortBys",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "downloads",
						Value: "Downloads",
					},
					{
						Key:   "date",
						Value: "Date",
					},
					{
						Key:   "size",
						Value: "Size",
					},
					{
						Key:   "seeders",
						Value: "Seeders",
					},
					{
						Key:   "leechers",
						Value: "Leechers",
					},
					{
						Key:   "comments",
						Value: "Comments",
					},
				},
			},
		},
		Dirs:          []string{"Anime"},
		CustomRootDir: "Anime",
	},
	{
		Title:     "Mangadex",
		SortValue: 2,
		Providers: pq.Int64Array{int64(MANGADEX)},
		Modifiers: []Modifier{
			{
				Title: "Include Tags",
				Key:   "includeTags",
				Type:  MULTI,
				Values: []ModifierValue{
					{
						Key:   "Romance",
						Value: "Romance",
					},
					{
						Key:   "Ninja",
						Value: "Ninja",
					},
					{
						Key:   "Comedy",
						Value: "Comedy",
					},
					{
						Key:   "Mecha",
						Value: "Mecha",
					},
					{
						Key:   "Anthology",
						Value: "Anthology",
					},
				},
			},
			{
				Title: "Exclude Tags",
				Key:   "excludeTags",
				Type:  MULTI,
				Values: []ModifierValue{
					{
						Key:   "Cooking",
						Value: "Cooking",
					},
					{
						Key:   "Supernatural",
						Value: "Supernatural",
					},
					{
						Key:   "Mystery",
						Value: "Mystery",
					},
					{
						Key:   "Adaptation",
						Value: "Adaptation",
					},
					{
						Key:   "Music",
						Value: "Music",
					},
					{
						Key:   "Full Color",
						Value: "Full Color",
					},
				},
			},
			{
				Title: "Status",
				Key:   "status",
				Type:  MULTI,
				Values: []ModifierValue{
					{
						Key:   "ongoing",
						Value: "Ongoing",
					},
					{
						Key:   "completed",
						Value: "Completed",
					},
					{
						Key:   "hiatus",
						Value: "Hiatus",
					},
					{
						Key:   "cancelled",
						Value: "Cancelled",
					},
				},
			},
			{
				Title: "Content Rating",
				Key:   "contentRating",
				Type:  MULTI,
				Values: []ModifierValue{
					{
						Key:   "safe",
						Value: "Safe",
					},
					{
						Key:   "suggestive",
						Value: "Suggestive",
					},
				},
			},
			{
				Title: "Demographic",
				Key:   "publicationDemographic",
				Type:  MULTI,
				Values: []ModifierValue{
					{
						Key:   "shounen",
						Value: "Shounen",
					},
					{
						Key:   "shoujo",
						Value: "Shoujo",
					},
					{
						Key:   "josei",
						Value: "Josei",
					},
					{
						Key:   "seinen",
						Value: "Seinen",
					},
				},
			},
		},
		Dirs:          []string{"Manga"},
		CustomRootDir: "Manga",
	},
	{
		Title:     "Manga & Light Novels",
		SortValue: 3,
		Providers: pq.Int64Array{int64(NYAA)},
		Modifiers: []Modifier{
			{
				Title: "Category",
				Key:   "categories",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "literature-eng",
						Value: "English Literature",
					},
					{
						Key:   "literature",
						Value: "Literature",
					},
					{
						Key:   "literature-non-eng",
						Value: "Non English Literature",
					},
					{
						Key:   "literature-raw",
						Value: "Raw Literature",
					},
				},
			},
			{
				Title: "Sort by",
				Key:   "sortBys",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "downloads",
						Value: "Downloads",
					},
					{
						Key:   "date",
						Value: "Date",
					},
					{
						Key:   "size",
						Value: "Size",
					},
					{
						Key:   "seeders",
						Value: "Seeders",
					},
					{
						Key:   "leechers",
						Value: "Leechers",
					},
					{
						Key:   "comments",
						Value: "Comments",
					},
				},
			},
		},
		Dirs:          []string{"Manga", "LightNovels"},
		CustomRootDir: "",
	},
	{
		Title:     "Movies",
		SortValue: 4,
		Providers: pq.Int64Array{int64(YTS)},
		Modifiers: []Modifier{
			{
				Title: "Sort By",
				Key:   "sortBys",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "title",
						Value: "Title",
					},
					{
						Key:   "year",
						Value: "Year",
					},
					{
						Key:   "rating",
						Value: "Rating",
					},
					{
						Key:   "peers",
						Value: "Peers",
					},
					{
						Key:   "seeds",
						Value: "Seeders",
					},
					{
						Key:   "download_count",
						Value: "Downloads",
					},
					{
						Key:   "like_count",
						Value: "Likes",
					},
					{
						Key:   "date_added",
						Value: "Date Added",
					},
				},
			},
		},
		Dirs:          []string{"Movies"},
		CustomRootDir: "Movies",
	},
	{
		Title:     "Lime",
		SortValue: 5,
		Providers: pq.Int64Array{int64(LIME)},
		Modifiers: []Modifier{
			{
				Title: "Category",
				Key:   "categories",
				Type:  DROPDOWN,
				Values: []ModifierValue{
					{
						Key:   "ALL",
						Value: "All categories",
					},
					{
						Key:   "MOVIES",
						Value: "Movies",
					},
					{
						Key:   "TV",
						Value: "TV",
					},
					{
						Key:   "ANIME",
						Value: "Anime",
					},
					{
						Key:   "OTHER",
						Value: "Other",
					},
				},
			},
		},
		Dirs:          []string{"Anime", "Movies", "Manga", "Series", "LightNovels"},
		CustomRootDir: "",
	},
	{
		Title:         "WebToon",
		SortValue:     6,
		Providers:     pq.Int64Array{int64(WEBTOON)},
		Modifiers:     []Modifier{},
		Dirs:          []string{"Manga"},
		CustomRootDir: "Manga",
	},
}
View Source
var (
	ErrFailedToLoadPreferences = errors.New("failed to load preferences")
)

Functions

This section is empty.

Types

type AgeRatingMap

type AgeRatingMap struct {
	Model

	PreferenceID       uint
	Tag                Tag                 `json:"tag"`
	ComicInfoAgeRating comicinfo.AgeRating `json:"comicInfoAgeRating"`
}

type AgeRatingMappings

type AgeRatingMappings []AgeRatingMap

func (AgeRatingMappings) GetAgeRating

func (arm AgeRatingMappings) GetAgeRating(tag string) (comicinfo.AgeRating, bool)

type CoverFallbackMethod

type CoverFallbackMethod int
const (
	CoverFallbackFirst CoverFallbackMethod = iota
	CoverFallbackLast
	CoverFallbackNone
)

type DownloadRequestMetadata

type DownloadRequestMetadata struct {
	StartImmediately bool                `json:"startImmediately"`
	Extra            map[string][]string `json:"extra,omitempty"`
}

type ManualMigration

type ManualMigration struct {
	Model

	Success bool
	Name    string
}

type Metadata

type Metadata interface {
	All() ([]MetadataRow, error)
	GetRow(key MetadataKey) (*MetadataRow, error)
	UpdateRow(metadata MetadataRow) error
	Update([]MetadataRow) error
}

type MetadataKey

type MetadataKey int
const (
	InstalledVersion MetadataKey = iota
	FirstInstalledVersion
	InstallDate
)

type MetadataRow

type MetadataRow struct {
	Key   MetadataKey
	Value string
}

type Model

type Model struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model is a gorm.Model but without DeletedAt

type Modifier

type Modifier struct {
	Model

	PageID uint

	Title  string          `json:"title"`
	Type   ModifierType    `json:"type"`
	Key    string          `json:"key"`
	Values []ModifierValue `json:"values"`
	Sort   int
}

type ModifierType

type ModifierType int
const (
	DROPDOWN ModifierType = iota + 1
	MULTI
)

type ModifierValue

type ModifierValue struct {
	Model

	ModifierID uint
	Key        string `json:"key"`
	Value      string `json:"value"`
	Default    bool   `json:"default"`
}

type Notification

type Notification struct {
	Model

	Title   string             `json:"title"`
	Summary string             `json:"summary"`
	Body    string             `json:"body"`
	Colour  NotificationColour `json:"colour"`
	Group   NotificationGroup  `json:"group" gorm:"index"`

	Read bool `json:"read"`
}

type NotificationColour

type NotificationColour string
const (
	Primary   NotificationColour = "primary"
	Secondary NotificationColour = "secondary"
	Warning   NotificationColour = "warning"
	Error     NotificationColour = "error"
)

type NotificationGroup

type NotificationGroup string
const (
	GroupContent  NotificationGroup = "content"
	GroupSecurity NotificationGroup = "security"
	GroupGeneral  NotificationGroup = "general"
	GroupError    NotificationGroup = "error"
)

type Notifications

type Notifications interface {
	Get(id uint) (Notification, error)
	GetMany(ids []uint) ([]Notification, error)
	All() ([]Notification, error)
	AllAfter(time.Time) ([]Notification, error)
	Recent(int, NotificationGroup) ([]Notification, error)

	New(Notification) error
	Delete(uint) error
	DeleteMany([]uint) error

	MarkRead(uint) error
	MarkReadMany([]uint) error
	MarkUnread(uint) error
	Unread() (int64, error)
}

type Option

type Option[T any] func(T) T

type Page

type Page struct {
	Model

	Title         string         `json:"title"`
	Icon          string         `json:"icon"`
	SortValue     int            `json:"sortValue"`
	Providers     pq.Int64Array  `gorm:"type:integer[]" json:"providers"`
	Modifiers     []Modifier     `json:"modifiers"`
	Dirs          pq.StringArray `gorm:"type:string[]" json:"dirs"`
	CustomRootDir string         `json:"customRootDir"`
}

type Pages

type Pages interface {
	All() ([]Page, error)
	Get(id uint) (*Page, error)

	New(page *Page) error
	Update(page *Page) error
	UpdateMany(pages []Page) error

	Delete(id uint) error
}

type PasswordReset

type PasswordReset struct {
	Model

	UserId uint
	Key    string
	Expiry time.Time
}

type Preference

type Preference struct {
	Model

	SubscriptionRefreshHour int                 `json:"subscriptionRefreshHour" validate:"min=0,max=23"`
	LogEmptyDownloads       bool                `json:"logEmptyDownloads" validate:"boolean"`
	ConvertToWebp           bool                `json:"convertToWebp" validate:"boolean"`
	CoverFallbackMethod     CoverFallbackMethod `json:"coverFallbackMethod"`
	DynastyGenreTags        []Tag               `json:"dynastyGenreTags" gorm:"many2many:preference_dynasty_genre_tags"`
	BlackListedTags         []Tag               `json:"blackListedTags" gorm:"many2many:preference_black_list_tags"`
	WhiteListedTags         []Tag               `json:"whiteListedTags" gorm:"many2many:preference_white_list_tags"`
	AgeRatingMappings       []AgeRatingMap      `json:"ageRatingMappings" gorm:"many2many:preference_age_rating_mappings"`
	TagMappings             []TagMap            `json:"tagMappings"`
}

type Preferences

type Preferences interface {
	// Get returns a pointer to Preference, with no relations loaded
	Get() (*Preference, error)
	// GetComplete returns a pointer to Preference, with all relations loaded
	GetComplete() (*Preference, error)
	Update(pref Preference) error
	// Flush set the cached value for Get and GetComplete to nil
	Flush() error
}

type Provider

type Provider int
const (
	NYAA Provider = iota + 2
	YTS
	LIME
	SUBSPLEASE
	MANGADEX
	WEBTOON
	DYNASTY
	BATO

	MinProvider = NYAA
	MaxProvider = BATO
)

func (Provider) String

func (p Provider) String() string

type RefreshFrequency

type RefreshFrequency int
const (
	Day RefreshFrequency = iota + 2
	Week
	Month
)

func (RefreshFrequency) AsDuration

func (f RefreshFrequency) AsDuration() time.Duration

type ServerSetting

type ServerSetting struct {
	Key   SettingKey `gorm:"unique"`
	Value string     `gorm:"type:text"`
}

type SettingKey

type SettingKey int
const (
	OidcAuthority SettingKey = iota
	OidcClientID
	BaseUrl
	CacheType
	RedisAddr
	MaxConcurrentTorrents
	MaxConcurrentImages
	DisableIpv6
	RootDir
	OidcAutoLogin
	OidcDisablePasswordLogin
)

type Settings

type Settings interface {
	All() ([]ServerSetting, error)
	GetById(SettingKey) (ServerSetting, error)
	Update([]ServerSetting) error
}

type Subscription

type Subscription struct {
	Model

	Provider         Provider                `json:"provider" gorm:"type:int"`
	ContentId        string                  `json:"contentId"`
	RefreshFrequency RefreshFrequency        `json:"refreshFrequency" gorm:"type:int"`
	Info             SubscriptionInfo        `json:"info"`
	Metadata         json.RawMessage         `gorm:"type:jsonb" json:"-"`
	Payload          DownloadRequestMetadata `json:"metadata" gorm:"-:all"`
}

func (*Subscription) AfterFind

func (s *Subscription) AfterFind(tx *gorm.DB) (err error)

func (*Subscription) BeforeSave

func (s *Subscription) BeforeSave(tx *gorm.DB) (err error)

func (*Subscription) NextExecution

func (s *Subscription) NextExecution(hour int) time.Time

func (*Subscription) Normalize

func (s *Subscription) Normalize(hour int)

func (*Subscription) ShouldRefresh

func (s *Subscription) ShouldRefresh(old *Subscription) bool

type SubscriptionInfo

type SubscriptionInfo struct {
	Model

	SubscriptionId int

	Title            string    `json:"title"`
	Description      string    `json:"description"`
	BaseDir          string    `json:"baseDir"`
	LastCheck        time.Time `json:"lastCheck"`
	LastCheckSuccess bool      `json:"lastCheckSuccess"`
	NextExecution    time.Time `json:"nextExecution"`
}

type Subscriptions

type Subscriptions interface {
	All() ([]Subscription, error)
	Get(uint) (*Subscription, error)
	GetByContentId(string) (*Subscription, error)

	New(Subscription) (*Subscription, error)
	Update(Subscription) error
	Delete(uint) error
}

type Tag

type Tag struct {
	Model

	PreferenceID   uint
	AgeRatingMapID uint

	Name           string `json:"name"`
	NormalizedName string `json:"normalizedName"`
}

func NewTag

func NewTag(name string) Tag

func (*Tag) BeforeSave

func (tag *Tag) BeforeSave(tx *gorm.DB) error

func (*Tag) Is

func (tag *Tag) Is(t string, nt string) bool

func (*Tag) IsNotNormalized

func (tag *Tag) IsNotNormalized(t string) bool

type TagMap

type TagMap struct {
	Model

	PreferenceID uint
	OriginID     uint
	Origin       Tag `json:"origin" gorm:"foreignKey:OriginID;references:ID"`
	DestID       uint
	Dest         Tag `json:"dest" gorm:"foreignKey:DestID;references:ID"`
}

type TagMaps

type TagMaps []TagMap

func (TagMaps) MapTag

func (tm TagMaps) MapTag(tag string) string

type Tags

type Tags []Tag

func (Tags) Contains

func (tags Tags) Contains(tag string) bool

func (Tags) ContainsTag

func (tags Tags) ContainsTag(tag Tag) bool

type User

type User struct {
	Model
	Name         string         `gorm:"unique"`
	Email        sql.NullString `gorm:"unique"`
	PasswordHash string
	ApiKey       string
	Permission   int
	// Will not be updated in the UpdateUser method, should be set on creation. And only for the first account
	Original   bool
	ExternalId sql.NullString `gorm:"unique,nullable"`
}

func (*User) HasPermission

func (u *User) HasPermission(permission UserPermission) bool

type UserPermission

type UserPermission int

type Users

type Users interface {
	All() ([]User, error)
	ExistsAny() (bool, error)

	GetById(id uint) (*User, error)
	GetByExternalId(ExternalId string) (*User, error)
	GetByEmail(email string) (*User, error)
	GetByName(name string) (*User, error)
	GetByApiKey(key string) (*User, error)

	Create(name string, opts ...Option[User]) (*User, error)
	Update(user User, opts ...Option[User]) (*User, error)
	UpdateById(id uint, opts ...Option[User]) (*User, error)

	GenerateReset(userId uint) (*PasswordReset, error)
	GetResetByUserId(userId uint) (*PasswordReset, error)
	GetReset(key string) (*PasswordReset, error)
	DeleteReset(key string) error

	Delete(id uint) error
}

Jump to

Keyboard shortcuts

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