feat: add backend

This commit is contained in:
Ludvig Lundgren 2021-08-11 15:26:17 +02:00
parent bc418ff248
commit a838d994a6
68 changed files with 9561 additions and 0 deletions

39
internal/domain/action.go Normal file
View file

@ -0,0 +1,39 @@
package domain
type ActionRepo interface {
Store(action Action) (*Action, error)
FindByFilterID(filterID int) ([]Action, error)
List() ([]Action, error)
Delete(actionID int) error
ToggleEnabled(actionID int) error
}
type Action struct {
ID int `json:"id"`
Name string `json:"name"`
Type ActionType `json:"type"`
Enabled bool `json:"enabled"`
ExecCmd string `json:"exec_cmd,omitempty"`
ExecArgs string `json:"exec_args,omitempty"`
WatchFolder string `json:"watch_folder,omitempty"`
Category string `json:"category,omitempty"`
Tags string `json:"tags,omitempty"`
Label string `json:"label,omitempty"`
SavePath string `json:"save_path,omitempty"`
Paused bool `json:"paused,omitempty"`
IgnoreRules bool `json:"ignore_rules,omitempty"`
LimitUploadSpeed int64 `json:"limit_upload_speed,omitempty"`
LimitDownloadSpeed int64 `json:"limit_download_speed,omitempty"`
FilterID int `json:"filter_id,omitempty"`
ClientID int32 `json:"client_id,omitempty"`
}
type ActionType string
const (
ActionTypeTest ActionType = "TEST"
ActionTypeExec ActionType = "EXEC"
ActionTypeQbittorrent ActionType = "QBITTORRENT"
ActionTypeDeluge ActionType = "DELUGE"
ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
)

View file

@ -0,0 +1,51 @@
package domain
type Announce struct {
ReleaseType string
Freeleech bool
FreeleechPercent string
Origin string
ReleaseGroup string
Category string
TorrentName string
Uploader string
TorrentSize string
PreTime string
TorrentUrl string
TorrentUrlSSL string
Year int
Name1 string // artist, show, movie
Name2 string // album
Season int
Episode int
Resolution string
Source string
Encoder string
Container string
Format string
Bitrate string
Media string
Tags string
Scene bool
Log string
LogScore string
Cue bool
Line string
OrigLine string
Site string
HttpHeaders string
Filter *Filter
}
//type Announce struct {
// Channel string
// Announcer string
// Message string
// CreatedAt time.Time
//}
//
type AnnounceRepo interface {
Store(announce Announce) error
}

28
internal/domain/client.go Normal file
View file

@ -0,0 +1,28 @@
package domain
type DownloadClientRepo interface {
//FindByActionID(actionID int) ([]DownloadClient, error)
List() ([]DownloadClient, error)
FindByID(id int32) (*DownloadClient, error)
Store(client DownloadClient) (*DownloadClient, error)
Delete(clientID int) error
}
type DownloadClient struct {
ID int `json:"id"`
Name string `json:"name"`
Type DownloadClientType `json:"type"`
Enabled bool `json:"enabled"`
Host string `json:"host"`
Port int `json:"port"`
SSL bool `json:"ssl"`
Username string `json:"username"`
Password string `json:"password"`
}
type DownloadClientType string
const (
DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT"
DownloadClientTypeDeluge DownloadClientType = "DELUGE"
)

11
internal/domain/config.go Normal file
View file

@ -0,0 +1,11 @@
package domain
type Settings struct {
Host string `toml:"host"`
Debug bool
}
//type AppConfig struct {
// Settings `toml:"settings"`
// Trackers []Tracker `mapstructure:"tracker"`
//}

90
internal/domain/filter.go Normal file
View file

@ -0,0 +1,90 @@
package domain
import "time"
/*
Works the same way as for autodl-irssi
https://autodl-community.github.io/autodl-irssi/configuration/filter/
*/
type FilterRepo interface {
FindByID(filterID int) (*Filter, error)
FindFiltersForSite(site string) ([]Filter, error)
FindByIndexerIdentifier(indexer string) ([]Filter, error)
ListFilters() ([]Filter, error)
Store(filter Filter) (*Filter, error)
Update(filter Filter) (*Filter, error)
Delete(filterID int) error
StoreIndexerConnection(filterID int, indexerID int) error
DeleteIndexerConnections(filterID int) error
}
type Filter struct {
ID int `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
FilterGeneral
FilterP2P
FilterTVMovies
FilterMusic
FilterAdvanced
Actions []Action `json:"actions"`
Indexers []Indexer `json:"indexers"`
}
type FilterGeneral struct {
MinSize string `json:"min_size"`
MaxSize string `json:"max_size"`
Delay int `json:"delay"`
}
type FilterP2P struct {
MatchReleases string `json:"match_releases"`
ExceptReleases string `json:"except_releases"`
UseRegex bool `json:"use_regex"`
MatchReleaseGroups string `json:"match_release_groups"`
ExceptReleaseGroups string `json:"except_release_groups"`
Scene bool `json:"scene"`
Origins string `json:"origins"`
Freeleech bool `json:"freeleech"`
FreeleechPercent string `json:"freeleech_percent"`
}
type FilterTVMovies struct {
Shows string `json:"shows"`
Seasons string `json:"seasons"`
Episodes string `json:"episodes"`
Resolutions []string `json:"resolutions"` // SD, 480i, 480p, 576p, 720p, 810p, 1080i, 1080p.
Codecs []string `json:"codecs"` // XviD, DivX, x264, h.264 (or h264), mpeg2 (or mpeg-2), VC-1 (or VC1), WMV, Remux, h.264 Remux (or h264 Remux), VC-1 Remux (or VC1 Remux).
Sources []string `json:"sources"` // DSR, PDTV, HDTV, HR.PDTV, HR.HDTV, DVDRip, DVDScr, BDr, BD5, BD9, BDRip, BRRip, DVDR, MDVDR, HDDVD, HDDVDRip, BluRay, WEB-DL, TVRip, CAM, R5, TELESYNC, TS, TELECINE, TC. TELESYNC and TS are synonyms (you don't need both). Same for TELECINE and TC
Containers []string `json:"containers"`
Years string `json:"years"`
}
type FilterMusic struct {
Artists string `json:"artists"`
Albums string `json:"albums"`
MatchReleaseTypes string `json:"match_release_types"` // Album,Single,EP
ExceptReleaseTypes string `json:"except_release_types"`
Formats []string `json:"formats"` // MP3, FLAC, Ogg, AAC, AC3, DTS
Bitrates []string `json:"bitrates"` // 192, 320, APS (VBR), V2 (VBR), V1 (VBR), APX (VBR), V0 (VBR), q8.x (VBR), Lossless, 24bit Lossless, Other
Media []string `json:"media"` // CD, DVD, Vinyl, Soundboard, SACD, DAT, Cassette, WEB, Other
Cue bool `json:"cue"`
Log bool `json:"log"`
LogScores string `json:"log_scores"`
}
type FilterAdvanced struct {
MatchCategories string `json:"match_categories"`
ExceptCategories string `json:"except_categories"`
MatchUploaders string `json:"match_uploaders"`
ExceptUploaders string `json:"except_uploaders"`
Tags string `json:"tags"`
ExceptTags string `json:"except_tags"`
TagsAny string `json:"tags_any"`
ExceptTagsAny string `json:"except_tags_any"`
}

View file

@ -0,0 +1,68 @@
package domain
type IndexerRepo interface {
Store(indexer Indexer) (*Indexer, error)
Update(indexer Indexer) (*Indexer, error)
List() ([]Indexer, error)
Delete(id int) error
FindByFilterID(id int) ([]Indexer, error)
}
type Indexer struct {
ID int `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Enabled bool `json:"enabled"`
Type string `json:"type,omitempty"`
Settings map[string]string `json:"settings,omitempty"`
}
type IndexerDefinition struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Enabled bool `json:"enabled,omitempty"`
Description string `json:"description"`
Language string `json:"language"`
Privacy string `json:"privacy"`
Protocol string `json:"protocol"`
URLS []string `json:"urls"`
Settings []IndexerSetting `json:"settings"`
SettingsMap map[string]string `json:"-"`
IRC *IndexerIRC `json:"irc"`
Parse IndexerParse `json:"parse"`
}
type IndexerSetting struct {
Name string `json:"name"`
Required bool `json:"required,omitempty"`
Type string `json:"type"`
Value string `json:"value,omitempty"`
Label string `json:"label"`
Description string `json:"description"`
Regex string `json:"regex,omitempty"`
}
type IndexerIRC struct {
Network string
Server string
Channels []string
Announcers []string
}
type IndexerParse struct {
Type string `json:"type"`
Lines []IndexerParseExtract `json:"lines"`
Match IndexerParseMatch `json:"match"`
}
type IndexerParseExtract struct {
Test []string `json:"test"`
Pattern string `json:"pattern"`
Vars []string `json:"vars"`
}
type IndexerParseMatch struct {
TorrentURL string `json:"torrenturl"`
Encode []string `json:"encode"`
}

43
internal/domain/irc.go Normal file
View file

@ -0,0 +1,43 @@
package domain
import "context"
type IrcChannel struct {
ID int64 `json:"id"`
Enabled bool `json:"enabled"`
Detached bool `json:"detached"`
Name string `json:"name"`
Password string `json:"password"`
}
type SASL struct {
Mechanism string `json:"mechanism,omitempty"`
Plain struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
} `json:"plain,omitempty"`
}
type IrcNetwork struct {
ID int64 `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Addr string `json:"addr"`
TLS bool `json:"tls"`
Nick string `json:"nick"`
Pass string `json:"pass"`
ConnectCommands []string `json:"connect_commands"`
SASL SASL `json:"sasl,omitempty"`
Channels []IrcChannel `json:"channels"`
}
type IrcRepo interface {
Store(announce Announce) error
StoreNetwork(network *IrcNetwork) error
StoreChannel(networkID int64, channel *IrcChannel) error
ListNetworks(ctx context.Context) ([]IrcNetwork, error)
ListChannels(networkID int64) ([]IrcChannel, error)
GetNetworkByID(id int64) (*IrcNetwork, error)
DeleteNetwork(ctx context.Context, id int64) error
}