mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-23 20:20:46 +08:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e14be7322 | ||
|
|
483e1caf83 | ||
|
|
f074d38f4f | ||
|
|
9c7129660c | ||
|
|
8b11e72427 | ||
|
|
2267b0450a | ||
|
|
8973fe9d5d | ||
|
|
9d3b206762 | ||
|
|
386e5ce100 | ||
|
|
78573b71a9 | ||
|
|
62fd7e2c18 | ||
|
|
2641a5fccd | ||
|
|
98823e251b | ||
|
|
269a5bf030 | ||
|
|
502d482ea9 | ||
|
|
cff83e4d5f | ||
|
|
9b7527defe | ||
|
|
aecbc5f657 | ||
|
|
9e41a1513c | ||
|
|
0d527c22e5 | ||
|
|
0dea185077 | ||
|
|
834254b9b8 | ||
|
|
fdcf7f487c | ||
|
|
1a3807acc9 | ||
|
|
549aaf60ca | ||
|
|
2fad5ea69b | ||
|
|
3c7d7aa263 | ||
|
|
17f357e33a | ||
|
|
7ccc73e044 | ||
|
|
ff2f290641 | ||
|
|
aee32c7bbf | ||
|
|
8e9ba101c8 | ||
|
|
ec3f9b2f96 | ||
|
|
8f354fff41 | ||
|
|
d44060ff33 | ||
|
|
1ea8246cfc | ||
|
|
8aef9260a1 | ||
|
|
ef3b555036 | ||
|
|
26dc488d48 | ||
|
|
14764c7b06 | ||
|
|
951b73bc4e | ||
|
|
55c2a3c8e2 | ||
|
|
310c83a27c | ||
|
|
75ef1a42ae | ||
|
|
fa78e40baf | ||
|
|
aefc4a28c2 |
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.23 as builder
|
||||
FROM golang:1.24 as builder
|
||||
|
||||
# 启用go module
|
||||
ENV GO111MODULE=on
|
||||
|
||||
@@ -21,7 +21,14 @@
|
||||
|
||||
## 快速开始
|
||||
|
||||
使用此程序参考 [【快速开始】](./doc/quick_start.md)
|
||||
若要体验,请确保本机有docker环境,然后执行:
|
||||
|
||||
```bash
|
||||
docker run -p 8080:8080 ghcr.io/simon-ding/polaris:latest
|
||||
```
|
||||
随后访问 http://127.0.0.1:8080 ,即可快速体验Polaris的功能
|
||||
|
||||
正式部署请参考 [【快速开始】](./doc/quick_start.md)
|
||||
|
||||
## Features
|
||||
|
||||
|
||||
221
db/db.go
221
db/db.go
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"polaris/ent"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -28,19 +29,19 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
type client struct {
|
||||
ent *ent.Client
|
||||
}
|
||||
|
||||
func Open() (*Client, error) {
|
||||
func Open() (Database, error) {
|
||||
os.Mkdir(DataPath, 0777)
|
||||
client, err := ent.Open(dialect.SQLite, fmt.Sprintf("file:%v/polaris.db?cache=shared&_fk=1", DataPath))
|
||||
cl, err := ent.Open(dialect.SQLite, fmt.Sprintf("file:%v/polaris.db?cache=shared&_fk=1", DataPath))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed opening connection to sqlite")
|
||||
}
|
||||
//defer client.Close()
|
||||
c := &Client{
|
||||
ent: client,
|
||||
c := &client{
|
||||
ent: cl,
|
||||
}
|
||||
// Run the auto migration tool.
|
||||
if err := c.migrate(); err != nil {
|
||||
@@ -52,7 +53,7 @@ func Open() (*Client, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
func (c *client) init() {
|
||||
c.generateJwtSerectIfNotExist()
|
||||
if err := c.generateDefaultLocalStorage(); err != nil {
|
||||
log.Errorf("generate default storage: %v", err)
|
||||
@@ -68,17 +69,36 @@ func (c *Client) init() {
|
||||
log.Infof("set default log level")
|
||||
c.SetSetting(SettingLogLevel, "info")
|
||||
}
|
||||
if tr := c.GetAllDonloadClients(); len(tr) == 0 {
|
||||
log.Warnf("no download client, set default download client")
|
||||
c.SaveDownloader(&ent.DownloadClients{
|
||||
Name: "transmission",
|
||||
Implementation: downloadclients.ImplementationTransmission,
|
||||
URL: "http://transmission:9091",
|
||||
})
|
||||
}
|
||||
c.initBuildinClient()
|
||||
}
|
||||
|
||||
func (c *Client) generateJwtSerectIfNotExist() {
|
||||
func (c *client) initBuildinClient() {
|
||||
hasBuildin := false
|
||||
tr := c.GetAllDonloadClients()
|
||||
for _, d := range tr {
|
||||
if d.Implementation == downloadclients.ImplementationBuildin {
|
||||
hasBuildin = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasBuildin {
|
||||
log.Warnf("no buildin download client, set default download client")
|
||||
if err := c.SaveDownloader(&ent.DownloadClients{
|
||||
Enable: true,
|
||||
Name: "内建下载器",
|
||||
Implementation: downloadclients.ImplementationBuildin,
|
||||
URL: "buildin",
|
||||
Priority1: 50,
|
||||
RemoveCompletedDownloads: true,
|
||||
RemoveFailedDownloads: true,
|
||||
}); err != nil {
|
||||
log.Warnf("add buildin client error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *client) generateJwtSerectIfNotExist() {
|
||||
v := c.GetSetting(JwtSerectKey)
|
||||
if v == "" {
|
||||
log.Infof("generate jwt serect")
|
||||
@@ -87,7 +107,7 @@ func (c *Client) generateJwtSerectIfNotExist() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) generateDefaultLocalStorage() error {
|
||||
func (c *client) generateDefaultLocalStorage() error {
|
||||
n, _ := c.ent.Storage.Query().Count(context.TODO())
|
||||
if n != 0 {
|
||||
return nil
|
||||
@@ -102,7 +122,7 @@ func (c *Client) generateDefaultLocalStorage() error {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) GetSetting(key string) string {
|
||||
func (c *client) GetSetting(key string) string {
|
||||
v, err := c.ent.Settings.Query().Where(settings.Key(key)).Only(context.TODO())
|
||||
if err != nil {
|
||||
log.Debugf("get setting by key: %s error: %v", key, err)
|
||||
@@ -111,7 +131,7 @@ func (c *Client) GetSetting(key string) string {
|
||||
return v.Value
|
||||
}
|
||||
|
||||
func (c *Client) SetSetting(key, value string) error {
|
||||
func (c *client) SetSetting(key, value string) error {
|
||||
v, err := c.ent.Settings.Query().Where(settings.Key(key)).Only(context.TODO())
|
||||
if err != nil {
|
||||
log.Infof("create new setting")
|
||||
@@ -122,7 +142,7 @@ func (c *Client) SetSetting(key, value string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) GetLanguage() string {
|
||||
func (c *client) GetLanguage() string {
|
||||
lang := c.GetSetting(SettingLanguage)
|
||||
log.Infof("get application language: %s", lang)
|
||||
if lang == "" {
|
||||
@@ -131,7 +151,7 @@ func (c *Client) GetLanguage() string {
|
||||
return lang
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, error) {
|
||||
func (c *client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, error) {
|
||||
count := c.ent.Media.Query().Where(media.TmdbID(m.TmdbID)).CountX(context.Background())
|
||||
if count > 0 {
|
||||
return nil, fmt.Errorf("tv series %s already in watchlist", m.NameEn)
|
||||
@@ -166,7 +186,7 @@ func (c *Client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, er
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) GetMediaWatchlist(mediaType media.MediaType) []*ent.Media {
|
||||
func (c *client) GetMediaWatchlist(mediaType media.MediaType) []*ent.Media {
|
||||
list, err := c.ent.Media.Query().Where(media.MediaTypeEQ(mediaType)).Order(ent.Desc(media.FieldID)).All(context.TODO())
|
||||
if err != nil {
|
||||
log.Infof("query wtach list error: %v", err)
|
||||
@@ -175,19 +195,19 @@ func (c *Client) GetMediaWatchlist(mediaType media.MediaType) []*ent.Media {
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *Client) GetEpisode(seriesId, seasonNum, episodeNum int) (*ent.Episode, error) {
|
||||
func (c *client) GetEpisode(seriesId, seasonNum, episodeNum int) (*ent.Episode, error) {
|
||||
return c.ent.Episode.Query().Where(episode.MediaID(seriesId), episode.SeasonNumber(seasonNum),
|
||||
episode.EpisodeNumber(episodeNum)).First(context.TODO())
|
||||
}
|
||||
func (c *Client) GetEpisodeByID(epID int) (*ent.Episode, error) {
|
||||
func (c *client) GetEpisodeByID(epID int) (*ent.Episode, error) {
|
||||
return c.ent.Episode.Query().Where(episode.ID(epID)).First(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEpiode(episodeId int, name, overview string) error {
|
||||
func (c *client) UpdateEpiode(episodeId int, name, overview string) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEpiode2(episodeId int, name, overview, airdate string) error {
|
||||
func (c *client) UpdateEpiode2(episodeId int, name, overview, airdate string) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).SetAirDate(airdate).Exec(context.TODO())
|
||||
}
|
||||
|
||||
@@ -196,7 +216,7 @@ type MediaDetails struct {
|
||||
Episodes []*ent.Episode `json:"episodes"`
|
||||
}
|
||||
|
||||
func (c *Client) GetMediaDetails(id int) (*MediaDetails, error) {
|
||||
func (c *client) GetMediaDetails(id int) (*MediaDetails, error) {
|
||||
se, err := c.ent.Media.Query().Where(media.ID(id)).First(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("get series %d: %v", id, err)
|
||||
@@ -214,11 +234,11 @@ func (c *Client) GetMediaDetails(id int) (*MediaDetails, error) {
|
||||
return md, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetMedia(id int) (*ent.Media, error) {
|
||||
func (c *client) GetMedia(id int) (*ent.Media, error) {
|
||||
return c.ent.Media.Query().Where(media.ID(id)).First(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) DeleteMedia(id int) error {
|
||||
func (c *client) DeleteMedia(id int) error {
|
||||
_, err := c.ent.Episode.Delete().Where(episode.MediaID(id)).Exec(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -230,7 +250,7 @@ func (c *Client) DeleteMedia(id int) error {
|
||||
return c.CleanAllDanglingEpisodes()
|
||||
}
|
||||
|
||||
func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
|
||||
func (c *client) SaveEposideDetail(d *ent.Episode) (int, error) {
|
||||
ep, err := c.ent.Episode.Create().
|
||||
SetAirDate(d.AirDate).
|
||||
SetSeasonNumber(d.SeasonNumber).
|
||||
@@ -244,7 +264,7 @@ func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
|
||||
return ep.ID, nil
|
||||
}
|
||||
|
||||
func (c *Client) SaveEposideDetail2(d *ent.Episode) (int, error) {
|
||||
func (c *client) SaveEposideDetail2(d *ent.Episode) (int, error) {
|
||||
ep, err := c.ent.Episode.Create().
|
||||
SetAirDate(d.AirDate).
|
||||
SetSeasonNumber(d.SeasonNumber).
|
||||
@@ -263,13 +283,13 @@ type TorznabSetting struct {
|
||||
ApiKey string `json:"api_key"`
|
||||
}
|
||||
|
||||
func (c *Client) SaveIndexer(in *ent.Indexers) error {
|
||||
func (c *client) SaveIndexer(in *ent.Indexers) error {
|
||||
|
||||
count := c.ent.Indexers.Query().Where(indexers.Name(in.Name)).CountX(context.TODO())
|
||||
|
||||
if count > 0 || in.ID != 0 {
|
||||
if count > 0 {
|
||||
//update setting
|
||||
return c.ent.Indexers.Update().Where(indexers.ID(in.ID)).SetName(in.Name).SetImplementation(in.Implementation).
|
||||
return c.ent.Indexers.Update().Where(indexers.Name(in.Name)).SetName(in.Name).SetImplementation(in.Implementation).
|
||||
SetPriority(in.Priority).SetSeedRatio(in.SeedRatio).SetDisabled(in.Disabled).
|
||||
SetTvSearch(in.TvSearch).SetMovieSearch(in.MovieSearch).SetSettings("").SetSynced(in.Synced).
|
||||
SetAPIKey(in.APIKey).SetURL(in.URL).
|
||||
@@ -288,11 +308,11 @@ func (c *Client) SaveIndexer(in *ent.Indexers) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteIndexer(id int) {
|
||||
func (c *client) DeleteIndexer(id int) {
|
||||
c.ent.Indexers.Delete().Where(indexers.ID(id)).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetIndexer(id int) (*ent.Indexers, error) {
|
||||
func (c *client) GetIndexer(id int) (*ent.Indexers, error) {
|
||||
res, err := c.ent.Indexers.Query().Where(indexers.ID(id)).First(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -300,12 +320,12 @@ func (c *Client) GetIndexer(id int) (*ent.Indexers, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetAllIndexers() []*ent.Indexers {
|
||||
func (c *client) GetAllIndexers() []*ent.Indexers {
|
||||
res := c.ent.Indexers.Query().Where(indexers.Implementation(IndexerTorznabImpl)).Order(ent.Asc(indexers.FieldID)).AllX(context.TODO())
|
||||
return res
|
||||
}
|
||||
|
||||
func (c *Client) SaveDownloader(downloader *ent.DownloadClients) error {
|
||||
func (c *client) SaveDownloader(downloader *ent.DownloadClients) error {
|
||||
count := c.ent.DownloadClients.Query().Where(downloadclients.Name(downloader.Name)).CountX(context.TODO())
|
||||
if count != 0 {
|
||||
err := c.ent.DownloadClients.Update().Where(downloadclients.Name(downloader.Name)).SetImplementation(downloader.Implementation).
|
||||
@@ -318,23 +338,17 @@ func (c *Client) SaveDownloader(downloader *ent.DownloadClients) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) GetAllDonloadClients() []*ent.DownloadClients {
|
||||
func (c *client) GetAllDonloadClients() []*ent.DownloadClients {
|
||||
cc, err := c.ent.DownloadClients.Query().Order(ent.Asc(downloadclients.FieldPriority1)).All(context.TODO())
|
||||
if err != nil {
|
||||
log.Errorf("no download client")
|
||||
return nil
|
||||
}
|
||||
cc = append(cc, &ent.DownloadClients{
|
||||
Implementation: downloadclients.ImplementationBuildin,
|
||||
Name: "内建下载器",
|
||||
Priority1: 9999,
|
||||
Enable: true,
|
||||
})
|
||||
return cc
|
||||
}
|
||||
|
||||
func (c *Client) DeleteDownloadCLient(id int) {
|
||||
c.ent.DownloadClients.Delete().Where(downloadclients.ID(id)).Exec(context.TODO())
|
||||
func (c *client) DeleteDownloadCLient(id int) { //not delete buildin client
|
||||
c.ent.DownloadClients.Delete().Where(downloadclients.ID(id), downloadclients.ImplementationNEQ(downloadclients.ImplementationBuildin)).Exec(context.TODO())
|
||||
}
|
||||
|
||||
// Storage is the model entity for the Storage schema.
|
||||
@@ -375,7 +389,7 @@ type WebdavSetting struct {
|
||||
ChangeFileHash string `json:"change_file_hash"`
|
||||
}
|
||||
|
||||
func (c *Client) AddStorage(st *StorageInfo) error {
|
||||
func (c *client) AddStorage(st *StorageInfo) error {
|
||||
if !strings.HasSuffix(st.TvPath, "/") {
|
||||
st.TvPath += "/"
|
||||
}
|
||||
@@ -412,7 +426,7 @@ func (c *Client) AddStorage(st *StorageInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) GetAllStorage() []*ent.Storage {
|
||||
func (c *client) GetAllStorage() []*ent.Storage {
|
||||
data, err := c.ent.Storage.Query().Where(storage.Deleted(false)).All(context.TODO())
|
||||
if err != nil {
|
||||
log.Errorf("get storage: %v", err)
|
||||
@@ -434,7 +448,7 @@ func (s *Storage) ToWebDavSetting() WebdavSetting {
|
||||
return webdavSetting
|
||||
}
|
||||
|
||||
func (c *Client) GetStorage(id int) *Storage {
|
||||
func (c *client) GetStorage(id int) *Storage {
|
||||
r, err := c.ent.Storage.Query().Where(storage.ID(id)).First(context.TODO())
|
||||
if err != nil {
|
||||
//use default storage
|
||||
@@ -444,11 +458,11 @@ func (c *Client) GetStorage(id int) *Storage {
|
||||
return &Storage{*r}
|
||||
}
|
||||
|
||||
func (c *Client) DeleteStorage(id int) error {
|
||||
func (c *client) DeleteStorage(id int) error {
|
||||
return c.ent.Storage.Update().Where(storage.ID(id)).SetDeleted(true).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) SetDefaultStorage(id int) error {
|
||||
func (c *client) SetDefaultStorage(id int) error {
|
||||
err := c.ent.Storage.Update().Where(storage.ID(id)).SetDefault(true).Exec(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -457,7 +471,7 @@ func (c *Client) SetDefaultStorage(id int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) SetDefaultStorageByName(name string) error {
|
||||
func (c *client) SetDefaultStorageByName(name string) error {
|
||||
err := c.ent.Storage.Update().Where(storage.Name(name)).SetDefault(true).Exec(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -466,18 +480,18 @@ func (c *Client) SetDefaultStorageByName(name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) SaveHistoryRecord(h ent.History) (*ent.History, error) {
|
||||
func (c *client) SaveHistoryRecord(h ent.History) (*ent.History, error) {
|
||||
return c.ent.History.Create().SetMediaID(h.MediaID).SetDate(time.Now()).
|
||||
SetStatus(h.Status).SetTargetDir(h.TargetDir).SetSourceTitle(h.SourceTitle).SetIndexerID(h.IndexerID).
|
||||
SetDownloadClientID(h.DownloadClientID).SetSize(h.Size).SetSeasonNum(h.SeasonNum).
|
||||
SetEpisodeNums(h.EpisodeNums).SetHash(h.Hash).SetLink(h.Link).Save(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) SetHistoryStatus(id int, status history.Status) error {
|
||||
func (c *client) SetHistoryStatus(id int, status history.Status) error {
|
||||
return c.ent.History.Update().Where(history.ID(id)).SetStatus(status).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetHistories() ent.Histories {
|
||||
func (c *client) GetHistories() ent.Histories {
|
||||
h, err := c.ent.History.Query().Order(history.ByID(sql.OrderDesc())).All(context.TODO())
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -485,7 +499,7 @@ func (c *Client) GetHistories() ent.Histories {
|
||||
return h
|
||||
}
|
||||
|
||||
func (c *Client) GetRunningHistories() ent.Histories {
|
||||
func (c *client) GetRunningHistories() ent.Histories {
|
||||
h, err := c.ent.History.Query().Where(history.Or(history.StatusEQ(history.StatusRunning),
|
||||
history.StatusEQ(history.StatusUploading), history.StatusEQ(history.StatusSeeding))).All(context.TODO())
|
||||
if err != nil {
|
||||
@@ -494,16 +508,16 @@ func (c *Client) GetRunningHistories() ent.Histories {
|
||||
return h
|
||||
}
|
||||
|
||||
func (c *Client) GetHistory(id int) *ent.History {
|
||||
func (c *client) GetHistory(id int) *ent.History {
|
||||
return c.ent.History.Query().Where(history.ID(id)).FirstX(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) DeleteHistory(id int) error {
|
||||
err := c.ent.History.Update().Where(history.ID(id)).SetStatus(history.StatusRemoved).Exec(context.Background())
|
||||
func (c *client) DeleteHistory(id int) error {
|
||||
err := c.ent.History.Update().Where(history.ID(id)).SetStatus(history.StatusRemoved).Exec(context.Background())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) GetDownloadDir() string {
|
||||
func (c *client) GetDownloadDir() string {
|
||||
r, err := c.ent.Settings.Query().Where(settings.Key(SettingDownloadDir)).First(context.TODO())
|
||||
if err != nil {
|
||||
return "/downloads"
|
||||
@@ -511,7 +525,7 @@ func (c *Client) GetDownloadDir() string {
|
||||
return r.Value
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEpisodeStatus(mediaID int, seasonNum, episodeNum int) error {
|
||||
func (c *client) UpdateEpisodeStatus(mediaID int, seasonNum, episodeNum int) error {
|
||||
ep, err := c.ent.Episode.Query().Where(episode.MediaID(mediaID)).Where(episode.EpisodeNumber(episodeNum)).
|
||||
Where(episode.SeasonNumber(seasonNum)).First(context.TODO())
|
||||
if err != nil {
|
||||
@@ -520,37 +534,37 @@ func (c *Client) UpdateEpisodeStatus(mediaID int, seasonNum, episodeNum int) err
|
||||
return ep.Update().SetStatus(episode.StatusDownloaded).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) SetEpisodeStatus(id int, status episode.Status) error {
|
||||
func (c *client) SetEpisodeStatus(id int, status episode.Status) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(id)).SetStatus(status).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) IsEpisodeDownloadingOrDownloaded(id int) bool {
|
||||
func (c *client) IsEpisodeDownloadingOrDownloaded(id int) bool {
|
||||
ep, _ := c.GetEpisodeByID(id)
|
||||
his := c.ent.History.Query().Where(history.EpisodeNumsNotNil()).AllX(context.Background())
|
||||
his := c.ent.History.Query().Where(history.MediaID(ep.MediaID), history.SeasonNum(ep.SeasonNumber), history.StatusNEQ(history.StatusRemoved), history.StatusNEQ(history.StatusFail)).AllX(context.Background())
|
||||
for _, h := range his {
|
||||
if !slices.Contains(h.EpisodeNums, ep.EpisodeNumber) {
|
||||
continue
|
||||
if len(h.EpisodeNums) == 0 { //season pack download
|
||||
return true
|
||||
}
|
||||
if h.Status != history.StatusFail {
|
||||
if slices.Contains(h.EpisodeNums, ep.EpisodeNumber) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Client) SetSeasonAllEpisodeStatus(mediaID, seasonNum int, status episode.Status) error {
|
||||
func (c *client) SetSeasonAllEpisodeStatus(mediaID, seasonNum int, status episode.Status) error {
|
||||
return c.ent.Episode.Update().Where(episode.MediaID(mediaID), episode.SeasonNumber(seasonNum)).SetStatus(status).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) TmdbIdInWatchlist(tmdb_id int) bool {
|
||||
func (c *client) TmdbIdInWatchlist(tmdb_id int) bool {
|
||||
return c.ent.Media.Query().Where(media.TmdbID(tmdb_id)).CountX(context.TODO()) > 0
|
||||
}
|
||||
|
||||
func (c *Client) GetDownloadHistory(mediaID int) ([]*ent.History, error) {
|
||||
func (c *client) GetDownloadHistory(mediaID int) ([]*ent.History, error) {
|
||||
return c.ent.History.Query().Where(history.MediaID(mediaID)).All(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetMovieDummyEpisode(movieId int) (*ent.Episode, error) {
|
||||
func (c *client) GetMovieDummyEpisode(movieId int) (*ent.Episode, error) {
|
||||
_, err := c.ent.Media.Query().Where(media.ID(movieId), media.MediaTypeEQ(media.MediaTypeMovie)).First(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get movie")
|
||||
@@ -562,11 +576,11 @@ func (c *Client) GetMovieDummyEpisode(movieId int) (*ent.Episode, error) {
|
||||
return ep, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetDownloadClient(id int) (*ent.DownloadClients, error) {
|
||||
func (c *client) GetDownloadClient(id int) (*ent.DownloadClients, error) {
|
||||
return c.ent.DownloadClients.Query().Where(downloadclients.ID(id)).First(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) SetEpisodeMonitoring(id int, b bool) error {
|
||||
func (c *client) SetEpisodeMonitoring(id int, b bool) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(id)).SetMonitored(b).Exec(context.Background())
|
||||
}
|
||||
|
||||
@@ -577,24 +591,24 @@ type EditMediaData struct {
|
||||
Limiter schema.MediaLimiter `json:"limiter"`
|
||||
}
|
||||
|
||||
func (c *Client) EditMediaMetadata(in EditMediaData) error {
|
||||
func (c *client) EditMediaMetadata(in EditMediaData) error {
|
||||
return c.ent.Media.Update().Where(media.ID(in.ID)).SetResolution(in.Resolution).SetTargetDir(in.TargetDir).SetLimiter(in.Limiter).
|
||||
Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEpisodeTargetFile(id int, filename string) error {
|
||||
func (c *client) UpdateEpisodeTargetFile(id int, filename string) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(id)).SetTargetFile(filename).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) GetSeasonEpisodes(mediaId, seasonNum int) ([]*ent.Episode, error) {
|
||||
func (c *client) GetSeasonEpisodes(mediaId, seasonNum int) ([]*ent.Episode, error) {
|
||||
return c.ent.Episode.Query().Where(episode.MediaID(mediaId), episode.SeasonNumber(seasonNum)).All(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) GetAllImportLists() ([]*ent.ImportList, error) {
|
||||
func (c *client) GetAllImportLists() ([]*ent.ImportList, error) {
|
||||
return c.ent.ImportList.Query().All(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) AddImportlist(il *ent.ImportList) error {
|
||||
func (c *client) AddImportlist(il *ent.ImportList) error {
|
||||
count, err := c.ent.ImportList.Query().Where(importlist.Name(il.Name)).Count(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -608,11 +622,11 @@ func (c *Client) AddImportlist(il *ent.ImportList) error {
|
||||
SetType(il.Type).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) DeleteImportlist(id int) error {
|
||||
func (c *client) DeleteImportlist(id int) error {
|
||||
return c.ent.ImportList.DeleteOneID(id).Exec(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetSizeLimiter(mediaType string) (*MediaSizeLimiter, error) {
|
||||
func (c *client) GetSizeLimiter(mediaType string) (*MediaSizeLimiter, error) {
|
||||
var v string
|
||||
if mediaType == "tv" {
|
||||
v = c.GetSetting(SettingTvSizeLimiter)
|
||||
@@ -631,7 +645,7 @@ func (c *Client) GetSizeLimiter(mediaType string) (*MediaSizeLimiter, error) {
|
||||
return &limiter, err
|
||||
}
|
||||
|
||||
func (c *Client) SetSizeLimiter(mediaType string, limiter *MediaSizeLimiter) error {
|
||||
func (c *client) SetSizeLimiter(mediaType string, limiter *MediaSizeLimiter) error {
|
||||
data, err := json.Marshal(limiter)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -646,7 +660,7 @@ func (c *Client) SetSizeLimiter(mediaType string, limiter *MediaSizeLimiter) err
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) GetTvNamingFormat() string {
|
||||
func (c *client) GetTvNamingFormat() string {
|
||||
s := c.GetSetting(SettingTvNamingFormat)
|
||||
if s == "" {
|
||||
return DefaultNamingFormat
|
||||
@@ -654,7 +668,7 @@ func (c *Client) GetTvNamingFormat() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *Client) GetMovingNamingFormat() string {
|
||||
func (c *client) GetMovingNamingFormat() string {
|
||||
s := c.GetSetting(SettingMovieNamingFormat)
|
||||
if s == "" {
|
||||
return DefaultNamingFormat
|
||||
@@ -662,16 +676,11 @@ func (c *Client) GetMovingNamingFormat() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *Client) CleanAllDanglingEpisodes() error {
|
||||
func (c *client) CleanAllDanglingEpisodes() error {
|
||||
_, err := c.ent.Episode.Delete().Where(episode.Not(episode.HasMedia())).Exec(context.Background())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) AddBlacklistItem(item *ent.Blacklist) error {
|
||||
return c.ent.Blacklist.Create().SetType(item.Type).SetValue(item.Value).SetNotes(item.Notes).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) GetProwlarrSetting() (*ProwlarrSetting, error) {
|
||||
func (c *client) GetProwlarrSetting() (*ProwlarrSetting, error) {
|
||||
s := c.GetSetting(SettingProwlarrInfo)
|
||||
if s == "" {
|
||||
return nil, errors.New("prowlarr setting not set")
|
||||
@@ -683,7 +692,7 @@ func (c *Client) GetProwlarrSetting() (*ProwlarrSetting, error) {
|
||||
return &se, nil
|
||||
}
|
||||
|
||||
func (c *Client) SaveProwlarrSetting(se *ProwlarrSetting) error {
|
||||
func (c *client) SaveProwlarrSetting(se *ProwlarrSetting) error {
|
||||
data, err := json.Marshal(se)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -691,7 +700,7 @@ func (c *Client) SaveProwlarrSetting(se *ProwlarrSetting) error {
|
||||
return c.SetSetting(SettingProwlarrInfo, string(data))
|
||||
}
|
||||
|
||||
func (c *Client) getAcceptedFormats(key string) ([]string, error) {
|
||||
func (c *client) getAcceptedFormats(key string) ([]string, error) {
|
||||
v := c.GetSetting(key)
|
||||
if v == "" {
|
||||
return nil, nil
|
||||
@@ -702,7 +711,7 @@ func (c *Client) getAcceptedFormats(key string) ([]string, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (c *Client) setAcceptedFormats(key string, v []string) error {
|
||||
func (c *client) setAcceptedFormats(key string, v []string) error {
|
||||
data, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -710,7 +719,7 @@ func (c *Client) setAcceptedFormats(key string, v []string) error {
|
||||
return c.SetSetting(key, string(data))
|
||||
}
|
||||
|
||||
func (c *Client) GetAcceptedVideoFormats() ([]string, error) {
|
||||
func (c *client) GetAcceptedVideoFormats() ([]string, error) {
|
||||
res, err := c.getAcceptedFormats(SettingAcceptedVideoFormats)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -721,11 +730,11 @@ func (c *Client) GetAcceptedVideoFormats() ([]string, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetAcceptedVideoFormats(key string, v []string) error {
|
||||
func (c *client) SetAcceptedVideoFormats(key string, v []string) error {
|
||||
return c.setAcceptedFormats(SettingAcceptedVideoFormats, v)
|
||||
}
|
||||
|
||||
func (c *Client) GetAcceptedSubtitleFormats() ([]string, error) {
|
||||
func (c *client) GetAcceptedSubtitleFormats() ([]string, error) {
|
||||
res, err := c.getAcceptedFormats(SettingAcceptedSubtitleFormats)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -736,14 +745,30 @@ func (c *Client) GetAcceptedSubtitleFormats() ([]string, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetAcceptedSubtitleFormats(key string, v []string) error {
|
||||
func (c *client) SetAcceptedSubtitleFormats(key string, v []string) error {
|
||||
return c.setAcceptedFormats(SettingAcceptedSubtitleFormats, v)
|
||||
}
|
||||
|
||||
func (c *Client) GetTmdbApiKey() string {
|
||||
func (c *client) GetTmdbApiKey() string {
|
||||
k := c.GetSetting(SettingTmdbApiKey)
|
||||
if k == "" {
|
||||
return DefaultTmdbApiKey
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
func (c *client) AddTorrent2Blacklist(hash, name string, mediaId int) error {
|
||||
count := c.ent.Blacklist.Query().Where(blacklist.TorrentHash(hash), blacklist.MediaID(mediaId)).CountX(context.TODO())
|
||||
if count > 0 { //already exist
|
||||
log.Infof("torrent %s already in blacklist", hash)
|
||||
return nil
|
||||
}
|
||||
return c.ent.Blacklist.Create().SetType(blacklist.TypeTorrent).SetTorrentHash(hash).SetTorrentName(name).SetMediaID(mediaId).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *client) GetTorrentBlacklist() (ent.Blacklists, error) {
|
||||
return c.ent.Blacklist.Query().Where(blacklist.TypeEQ(blacklist.TypeTorrent)).All(context.Background())
|
||||
}
|
||||
func (c *client) DeleteTorrentBlacklist(id int) error {
|
||||
return c.ent.Blacklist.DeleteOneID(id).Exec(context.Background())
|
||||
}
|
||||
|
||||
112
db/interface.go
Normal file
112
db/interface.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/media"
|
||||
)
|
||||
|
||||
type Database interface {
|
||||
Settings
|
||||
|
||||
MediaApis
|
||||
|
||||
EpisodeApis
|
||||
|
||||
IndexerApis
|
||||
|
||||
HistoryApis
|
||||
|
||||
SaveDownloader(downloader *ent.DownloadClients) error
|
||||
GetAllDonloadClients() []*ent.DownloadClients
|
||||
DeleteDownloadCLient(id int)
|
||||
GetDownloadClient(id int) (*ent.DownloadClients, error)
|
||||
|
||||
AddStorage(st *StorageInfo) error
|
||||
GetAllStorage() []*ent.Storage
|
||||
GetStorage(id int) *Storage
|
||||
DeleteStorage(id int) error
|
||||
SetDefaultStorage(id int) error
|
||||
SetDefaultStorageByName(name string) error
|
||||
|
||||
GetAllImportLists() ([]*ent.ImportList, error)
|
||||
AddImportlist(il *ent.ImportList) error
|
||||
DeleteImportlist(id int) error
|
||||
|
||||
GetAllNotificationClients2() ([]*ent.NotificationClient, error)
|
||||
GetAllNotificationClients() ([]*NotificationClient, error)
|
||||
AddNotificationClient(name, service string, setting string, enabled bool) error
|
||||
DeleteNotificationClient(id int) error
|
||||
GetNotificationClient(id int) (*NotificationClient, error)
|
||||
|
||||
AddTorrent2Blacklist(hash, name string, mediaId int) error
|
||||
GetTorrentBlacklist() (ent.Blacklists, error)
|
||||
DeleteTorrentBlacklist(id int) error
|
||||
}
|
||||
|
||||
type Settings interface {
|
||||
GetSetting(key string) string
|
||||
SetSetting(key, value string) error
|
||||
GetLanguage() string
|
||||
GetDownloadDir() string
|
||||
GetTvNamingFormat() string
|
||||
GetMovingNamingFormat() string
|
||||
GetProwlarrSetting() (*ProwlarrSetting, error)
|
||||
SaveProwlarrSetting(se *ProwlarrSetting) error
|
||||
GetAcceptedVideoFormats() ([]string, error)
|
||||
SetAcceptedVideoFormats(key string, v []string) error
|
||||
GetAcceptedSubtitleFormats() ([]string, error)
|
||||
SetAcceptedSubtitleFormats(key string, v []string) error
|
||||
GetTmdbApiKey() string
|
||||
|
||||
}
|
||||
|
||||
type MediaApis interface {
|
||||
AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, error)
|
||||
GetMediaWatchlist(mediaType media.MediaType) []*ent.Media
|
||||
GetMediaDetails(id int) (*MediaDetails, error)
|
||||
GetMedia(id int) (*ent.Media, error)
|
||||
DeleteMedia(id int) error
|
||||
TmdbIdInWatchlist(tmdb_id int) bool
|
||||
EditMediaMetadata(in EditMediaData) error
|
||||
GetSizeLimiter(mediaType string) (*MediaSizeLimiter, error)
|
||||
SetSizeLimiter(mediaType string, limiter *MediaSizeLimiter) error
|
||||
}
|
||||
|
||||
type EpisodeApis interface {
|
||||
GetEpisode(seriesId, seasonNum, episodeNum int) (*ent.Episode, error)
|
||||
GetEpisodeByID(epID int) (*ent.Episode, error)
|
||||
UpdateEpiode(episodeId int, name, overview string) error
|
||||
UpdateEpiode2(episodeId int, name, overview, airdate string) error
|
||||
SaveEposideDetail(d *ent.Episode) (int, error)
|
||||
SaveEposideDetail2(d *ent.Episode) (int, error)
|
||||
UpdateEpisodeStatus(mediaID int, seasonNum, episodeNum int) error
|
||||
SetEpisodeStatus(id int, status episode.Status) error
|
||||
IsEpisodeDownloadingOrDownloaded(id int) bool
|
||||
SetSeasonAllEpisodeStatus(mediaID, seasonNum int, status episode.Status) error
|
||||
SetEpisodeMonitoring(id int, b bool) error
|
||||
UpdateEpisodeTargetFile(id int, filename string) error
|
||||
GetSeasonEpisodes(mediaId, seasonNum int) ([]*ent.Episode, error)
|
||||
CleanAllDanglingEpisodes() error
|
||||
|
||||
}
|
||||
|
||||
type IndexerApis interface {
|
||||
SaveIndexer(in *ent.Indexers) error
|
||||
DeleteIndexer(id int)
|
||||
GetIndexer(id int) (*ent.Indexers, error)
|
||||
GetAllIndexers() []*ent.Indexers
|
||||
|
||||
}
|
||||
|
||||
type HistoryApis interface {
|
||||
SaveHistoryRecord(h ent.History) (*ent.History, error)
|
||||
SetHistoryStatus(id int, status history.Status) error
|
||||
GetRunningHistories() ent.Histories
|
||||
GetHistory(id int) *ent.History
|
||||
GetHistories() ent.Histories
|
||||
DeleteHistory(id int) error
|
||||
GetDownloadHistory(mediaID int) ([]*ent.History, error)
|
||||
GetMovieDummyEpisode(movieId int) (*ent.Episode, error)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) migrate() error {
|
||||
func (c *client) migrate() error {
|
||||
// Run the auto migration tool.
|
||||
if err := c.ent.Schema.Create(context.Background()); err != nil {
|
||||
return errors.Wrap(err, "failed creating schema resources")
|
||||
@@ -20,7 +20,7 @@ func (c *Client) migrate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) migrateIndexerSetting() error {
|
||||
func (c *client) migrateIndexerSetting() error {
|
||||
indexers := c.GetAllIndexers()
|
||||
for _, in := range indexers {
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) GetAllNotificationClients2() ([]*ent.NotificationClient, error) {
|
||||
func (c *client) GetAllNotificationClients2() ([]*ent.NotificationClient, error) {
|
||||
return c.ent.NotificationClient.Query().All(context.TODO())
|
||||
}
|
||||
|
||||
func (c *Client) GetAllNotificationClients() ([]*NotificationClient, error) {
|
||||
func (c *client) GetAllNotificationClients() ([]*NotificationClient, error) {
|
||||
all, err := c.ent.NotificationClient.Query().All(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "query db")
|
||||
@@ -31,7 +31,7 @@ func (c *Client) GetAllNotificationClients() ([]*NotificationClient, error) {
|
||||
return all1, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddNotificationClient(name, service string, setting string, enabled bool) error {
|
||||
func (c *client) AddNotificationClient(name, service string, setting string, enabled bool) error {
|
||||
// data, err := json.Marshal(setting)
|
||||
// if err != nil {
|
||||
// return errors.Wrap(err, "json")
|
||||
@@ -48,12 +48,12 @@ func (c *Client) AddNotificationClient(name, service string, setting string, ena
|
||||
SetSettings(setting).SetEnabled(enabled).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) DeleteNotificationClient(id int) error {
|
||||
func (c *client) DeleteNotificationClient(id int) error {
|
||||
_, err := c.ent.NotificationClient.Delete().Where(notificationclient.ID(id)).Exec(context.Background())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) GetNotificationClient(id int) (*NotificationClient, error) {
|
||||
func (c *client) GetNotificationClient(id int) (*NotificationClient, error) {
|
||||
noti, err := c.ent.NotificationClient.Query().Where(notificationclient.ID(id)).First(context.Background())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "query")
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
"github.com/robfig/cron"
|
||||
)
|
||||
|
||||
func NewEngine(db *db.Client, language string) *Engine {
|
||||
func NewEngine(db db.Database, language string) *Engine {
|
||||
return &Engine{
|
||||
db: db,
|
||||
cron: cron.New(),
|
||||
tasks: utils.Map[int, *Task]{},
|
||||
db: db,
|
||||
cron: cron.New(),
|
||||
tasks: utils.Map[int, *Task]{},
|
||||
schedulers: utils.Map[string, scheduler]{},
|
||||
language: language,
|
||||
language: language,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,12 @@ type scheduler struct {
|
||||
f func() error
|
||||
}
|
||||
type Engine struct {
|
||||
db *db.Client
|
||||
db db.Database
|
||||
cron *cron.Cron
|
||||
tasks utils.Map[int, *Task]
|
||||
language string
|
||||
schedulers utils.Map[string, scheduler]
|
||||
buildin *buildin.Downloader
|
||||
}
|
||||
|
||||
func (c *Engine) registerCronJob(name string, cron string, f func() error) {
|
||||
@@ -51,8 +52,12 @@ func (c *Engine) Init() {
|
||||
go c.checkW500PosterOnStartup()
|
||||
}
|
||||
|
||||
func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error{
|
||||
cl, err := buildin.NewDownloader(c.db.GetDownloadDir())
|
||||
func (c *Engine) GetTask(id int) (*Task, bool) {
|
||||
return c.tasks.Load(id)
|
||||
}
|
||||
|
||||
func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error {
|
||||
cl, err := c.buildInDownloader()
|
||||
if err != nil {
|
||||
log.Warnf("buildin downloader error: %v", err)
|
||||
}
|
||||
@@ -60,7 +65,9 @@ func (c *Engine) reloadUsingBuildinDownloader(h *ent.History) error{
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "download torrent")
|
||||
}
|
||||
c.tasks.Store(h.ID, &Task{Torrent: t})
|
||||
t.Start()
|
||||
|
||||
c.tasks.Store(h.ID, &Task{Torrent: t})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -132,6 +139,14 @@ func (c *Engine) reloadTasks() {
|
||||
}
|
||||
c.tasks.Store(t.ID, &Task{Torrent: to})
|
||||
}
|
||||
} else if dl.Implementation == downloadclients.ImplementationBuildin {
|
||||
err := c.reloadUsingBuildinDownloader(t)
|
||||
if err != nil {
|
||||
log.Warnf("buildin downloader error: %v", err)
|
||||
} else {
|
||||
log.Infof("success reloading buildin task: %v", t.SourceTitle)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -139,8 +154,16 @@ func (c *Engine) reloadTasks() {
|
||||
}
|
||||
|
||||
func (c *Engine) buildInDownloader() (pkg.Downloader, error) {
|
||||
if c.buildin != nil {
|
||||
return c.buildin, nil
|
||||
}
|
||||
dir := c.db.GetDownloadDir()
|
||||
return buildin.NewDownloader(dir)
|
||||
d, err := buildin.NewDownloader(dir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "buildin downloader")
|
||||
}
|
||||
c.buildin = d
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, error) {
|
||||
@@ -171,7 +194,7 @@ func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, erro
|
||||
} else if d.Implementation == downloadclients.ImplementationBuildin {
|
||||
bin, err := c.buildInDownloader()
|
||||
if err != nil {
|
||||
log.Warnf("connect to download client error: %v", d.URL)
|
||||
log.Warnf("connect to download client error: %v", err)
|
||||
continue
|
||||
}
|
||||
return bin, d, nil
|
||||
@@ -210,6 +233,6 @@ func (c *Engine) RemoveTaskAndTorrent(id int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Engine) GetTasks() utils.Map[int, *Task] {
|
||||
return c.tasks
|
||||
func (c *Engine) GetTasks() *utils.Map[int, *Task] {
|
||||
return &c.tasks
|
||||
}
|
||||
|
||||
@@ -260,7 +260,11 @@ func (c *Engine) findEpisodeFilesPreMoving(historyId int) error {
|
||||
return err
|
||||
}
|
||||
for _, id := range episodeIds {
|
||||
ep, _ := c.db.GetEpisode(his.MediaID, his.SeasonNum, id)
|
||||
ep, err := c.db.GetEpisodeByID(id)
|
||||
if err != nil {
|
||||
log.Warnf("query episode error (%d): %v", id, err)
|
||||
continue
|
||||
}
|
||||
task.WalkFunc()(func(path string, info fs.FileInfo) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Engine) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum int, episodeNums ...int) (*string, error) {
|
||||
func (c *Engine) DownloadEpisodeTorrent(r1 torznab.Result, op DownloadOptions) (*string, error) {
|
||||
|
||||
series, err := c.db.GetMedia(seriesId)
|
||||
series, err := c.db.GetMedia(op.MediaId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
return nil, fmt.Errorf("no tv series of id %v", op.MediaId)
|
||||
}
|
||||
|
||||
return c.downloadTorrent(series, r1, seasonNum, episodeNums...)
|
||||
return c.downloadTorrent(series, r1, op)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -83,9 +83,14 @@ lo:
|
||||
m.ParseExtraDescription(r.Description)
|
||||
if len(episodeNums) == 0 { //want season pack
|
||||
if m.IsSeasonPack {
|
||||
name, err := c.DownloadEpisodeTorrent(r, seriesId, seasonNum)
|
||||
name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{
|
||||
SeasonNum: seasonNum,
|
||||
MediaId: seriesId,
|
||||
HashFilterFn: c.hashInBlacklist,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.Warnf("download season pack error, continue next item: %v", err)
|
||||
continue lo
|
||||
}
|
||||
torrentNames = append(torrentNames, *name)
|
||||
break lo
|
||||
@@ -98,9 +103,15 @@ lo:
|
||||
}
|
||||
torrentEpisodes = append(torrentEpisodes, i)
|
||||
}
|
||||
name, err := c.DownloadEpisodeTorrent(r, seriesId, seasonNum, torrentEpisodes...)
|
||||
name, err := c.DownloadEpisodeTorrent(r, DownloadOptions{
|
||||
SeasonNum: seasonNum,
|
||||
MediaId: seriesId,
|
||||
EpisodeNums: torrentEpisodes,
|
||||
HashFilterFn: c.hashInBlacklist,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.Warnf("download episode error, continue next item: %v", err)
|
||||
continue lo
|
||||
}
|
||||
torrentNames = append(torrentNames, *name)
|
||||
|
||||
@@ -116,10 +127,27 @@ lo:
|
||||
}
|
||||
|
||||
func (c *Engine) DownloadMovie(m *ent.Media, r1 torznab.Result) (*string, error) {
|
||||
return c.downloadTorrent(m, r1, 0)
|
||||
return c.downloadTorrent(m, r1, DownloadOptions{
|
||||
SeasonNum: 0,
|
||||
MediaId: m.ID,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int, episodeNums ...int) (*string, error) {
|
||||
func (c *Engine) hashInBlacklist(hash string) bool {
|
||||
blacklist, err := c.db.GetTorrentBlacklist()
|
||||
if err!= nil {
|
||||
log.Warnf("get torrent blacklist error: %v", err)
|
||||
return false
|
||||
}
|
||||
for _, b := range blacklist {
|
||||
if b.TorrentHash == hash {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, op DownloadOptions) (*string, error) {
|
||||
trc, dlc, err := c.GetDownloadClient()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get download client")
|
||||
@@ -137,13 +165,13 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
|
||||
var name = r1.Name
|
||||
var targetDir = m.TargetDir
|
||||
if m.MediaType == media.MediaTypeTv { //tv download
|
||||
targetDir = fmt.Sprintf("%s/Season %02d/", m.TargetDir, seasonNum)
|
||||
targetDir = fmt.Sprintf("%s/Season %02d/", m.TargetDir, op.SeasonNum)
|
||||
|
||||
if len(episodeNums) > 0 {
|
||||
for _, epNum := range episodeNums {
|
||||
ep, err := c.db.GetEpisode(m.ID, seasonNum, epNum)
|
||||
if len(op.EpisodeNums) > 0 {
|
||||
for _, epNum := range op.EpisodeNums {
|
||||
ep, err := c.db.GetEpisode(m.ID, op.SeasonNum, epNum)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("no episode of season %d episode %d", seasonNum, epNum)
|
||||
return nil, errors.Errorf("no episode of season %d episode %d", op.SeasonNum, epNum)
|
||||
|
||||
}
|
||||
if ep.Status == episode.StatusMissing {
|
||||
@@ -151,7 +179,7 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
|
||||
}
|
||||
}
|
||||
buff := &bytes.Buffer{}
|
||||
for i, ep := range episodeNums {
|
||||
for i, ep := range op.EpisodeNums {
|
||||
if i != 0 {
|
||||
buff.WriteString(",")
|
||||
|
||||
@@ -162,24 +190,32 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
|
||||
|
||||
} else { //season package download
|
||||
name = fmt.Sprintf("全集 (%s)", name)
|
||||
c.db.SetSeasonAllEpisodeStatus(m.ID, seasonNum, episode.StatusDownloading)
|
||||
c.db.SetSeasonAllEpisodeStatus(m.ID, op.SeasonNum, episode.StatusDownloading)
|
||||
}
|
||||
|
||||
} else {
|
||||
} else {//movie download
|
||||
ep, _ := c.db.GetMovieDummyEpisode(m.ID)
|
||||
if ep.Status == episode.StatusMissing {
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
}
|
||||
|
||||
}
|
||||
hash, err := utils.Link2Hash(r1.Link)
|
||||
|
||||
link, hash, err := utils.GetRealLinkAndHash(r1.Link)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get hash")
|
||||
}
|
||||
|
||||
if op.HashFilterFn != nil && op.HashFilterFn(hash) {
|
||||
return nil, errors.Errorf("hash is filtered: %s", hash)
|
||||
}
|
||||
|
||||
r1.Link = link
|
||||
|
||||
history, err := c.db.SaveHistoryRecord(ent.History{
|
||||
MediaID: m.ID,
|
||||
EpisodeNums: episodeNums,
|
||||
SeasonNum: seasonNum,
|
||||
EpisodeNums: op.EpisodeNums,
|
||||
SeasonNum: op.SeasonNum,
|
||||
SourceTitle: r1.Name,
|
||||
TargetDir: targetDir,
|
||||
Status: history.StatusRunning,
|
||||
|
||||
@@ -18,6 +18,13 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DownloadOptions struct {
|
||||
HashFilterFn func(hash string) bool
|
||||
SeasonNum int
|
||||
EpisodeNums []int
|
||||
MediaId int
|
||||
}
|
||||
|
||||
func (c *Engine) addSysCron() {
|
||||
c.registerCronJob("check_running_tasks", "@every 1m", c.checkTasks)
|
||||
c.registerCronJob("check_available_medias_to_download", "0 0 * * * *", func() error {
|
||||
@@ -204,35 +211,37 @@ func getSeasonNum(h *ent.History) int {
|
||||
}
|
||||
|
||||
func (c *Engine) GetEpisodeIds(r *ent.History) []int {
|
||||
var episodeIds []int
|
||||
seasonNum := getSeasonNum(r)
|
||||
|
||||
// if r.EpisodeID > 0 {
|
||||
// episodeIds = append(episodeIds, r.EpisodeID)
|
||||
// }
|
||||
series, err := c.db.GetMediaDetails(r.MediaID)
|
||||
if err != nil {
|
||||
log.Errorf("get media details error: %v", err)
|
||||
return []int{}
|
||||
}
|
||||
if series.MediaType == media.MediaTypeMovie { //movie
|
||||
ep, _ := c.db.GetMovieDummyEpisode(series.ID)
|
||||
return []int{ep.ID}
|
||||
} else { //tv
|
||||
var episodeIds []int
|
||||
seasonNum := getSeasonNum(r)
|
||||
|
||||
if len(r.EpisodeNums) > 0 {
|
||||
for _, epNum := range r.EpisodeNums {
|
||||
if len(r.EpisodeNums) > 0 {
|
||||
for _, epNum := range r.EpisodeNums {
|
||||
for _, ep := range series.Episodes {
|
||||
if ep.SeasonNumber == seasonNum && ep.EpisodeNumber == epNum {
|
||||
episodeIds = append(episodeIds, ep.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, ep := range series.Episodes {
|
||||
if ep.SeasonNumber == seasonNum && ep.EpisodeNumber == epNum {
|
||||
if ep.SeasonNumber == seasonNum {
|
||||
episodeIds = append(episodeIds, ep.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, ep := range series.Episodes {
|
||||
if ep.SeasonNumber == seasonNum {
|
||||
episodeIds = append(episodeIds, ep.ID)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return episodeIds
|
||||
}
|
||||
return episodeIds
|
||||
}
|
||||
|
||||
func (c *Engine) moveCompletedTask(id int) (err1 error) {
|
||||
@@ -492,7 +501,7 @@ func (c *Engine) downloadMovieSingleEpisode(m *ent.Media, ep *ent.Episode) (stri
|
||||
r1 := res[0]
|
||||
log.Infof("begin download torrent resource: %v", r1.Name)
|
||||
|
||||
s, err := c.downloadTorrent(m, r1, 0)
|
||||
s, err := c.downloadTorrent(m, r1, DownloadOptions{MediaId: m.ID, SeasonNum: 0, HashFilterFn: c.hashInBlacklist})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func names2Query(media *ent.Media) []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
func SearchTvSeries(db1 db.Database, param *SearchParam) ([]torznab.Result, error) {
|
||||
series, err := db1.GetMediaDetails(param.MediaId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v: %v", param.MediaId, err)
|
||||
@@ -234,7 +234,7 @@ func isNoSeasonSeries(detail *db.MediaDetails) bool {
|
||||
return hasSeason2 && !season2HasEpisode1 //only one 1st episode
|
||||
}
|
||||
|
||||
func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
func SearchMovie(db1 db.Database, param *SearchParam) ([]torznab.Result, error) {
|
||||
movieDetail, err := db1.GetMediaDetails(param.MediaId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -310,7 +310,7 @@ const (
|
||||
SearchTypeMovie SearchType = 2
|
||||
)
|
||||
|
||||
func searchWithTorznab(db *db.Client, t SearchType, queries ...string) []torznab.Result {
|
||||
func searchWithTorznab(db db.Database, t SearchType, queries ...string) []torznab.Result {
|
||||
|
||||
var res []torznab.Result
|
||||
allTorznab := db.GetAllIndexers()
|
||||
@@ -365,7 +365,7 @@ func searchWithTorznab(db *db.Client, t SearchType, queries ...string) []torznab
|
||||
sort.SliceStable(res, func(i, j int) bool { //再按优先级排序,优先级高的种子排前面
|
||||
var s1 = res[i]
|
||||
var s2 = res[j]
|
||||
return s1.Priority > s2.Priority
|
||||
return s1.Priority < s2.Priority
|
||||
})
|
||||
|
||||
//pt资源中,同一indexer内部,优先下载free的资源
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/schema"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -20,8 +19,14 @@ type Blacklist struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type blacklist.Type `json:"type,omitempty"`
|
||||
// Value holds the value of the "value" field.
|
||||
Value schema.BlacklistValue `json:"value,omitempty"`
|
||||
// TorrentHash holds the value of the "torrent_hash" field.
|
||||
TorrentHash string `json:"torrent_hash,omitempty"`
|
||||
// TorrentName holds the value of the "torrent_name" field.
|
||||
TorrentName string `json:"torrent_name,omitempty"`
|
||||
// MediaID holds the value of the "media_id" field.
|
||||
MediaID int `json:"media_id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Notes holds the value of the "notes" field.
|
||||
Notes string `json:"notes,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
@@ -32,12 +37,12 @@ func (*Blacklist) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blacklist.FieldValue:
|
||||
values[i] = new([]byte)
|
||||
case blacklist.FieldID:
|
||||
case blacklist.FieldID, blacklist.FieldMediaID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case blacklist.FieldType, blacklist.FieldNotes:
|
||||
case blacklist.FieldType, blacklist.FieldTorrentHash, blacklist.FieldTorrentName, blacklist.FieldNotes:
|
||||
values[i] = new(sql.NullString)
|
||||
case blacklist.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -65,13 +70,29 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
b.Type = blacklist.Type(value.String)
|
||||
}
|
||||
case blacklist.FieldValue:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &b.Value); err != nil {
|
||||
return fmt.Errorf("unmarshal field value: %w", err)
|
||||
}
|
||||
case blacklist.FieldTorrentHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field torrent_hash", values[i])
|
||||
} else if value.Valid {
|
||||
b.TorrentHash = value.String
|
||||
}
|
||||
case blacklist.FieldTorrentName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field torrent_name", values[i])
|
||||
} else if value.Valid {
|
||||
b.TorrentName = value.String
|
||||
}
|
||||
case blacklist.FieldMediaID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field media_id", values[i])
|
||||
} else if value.Valid {
|
||||
b.MediaID = int(value.Int64)
|
||||
}
|
||||
case blacklist.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
b.CreateTime = value.Time
|
||||
}
|
||||
case blacklist.FieldNotes:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
@@ -86,9 +107,9 @@ func (b *Blacklist) assignValues(columns []string, values []any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the Blacklist.
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Blacklist.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (b *Blacklist) GetValue(name string) (ent.Value, error) {
|
||||
func (b *Blacklist) Value(name string) (ent.Value, error) {
|
||||
return b.selectValues.Get(name)
|
||||
}
|
||||
|
||||
@@ -118,8 +139,17 @@ func (b *Blacklist) String() string {
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Value))
|
||||
builder.WriteString("torrent_hash=")
|
||||
builder.WriteString(b.TorrentHash)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("torrent_name=")
|
||||
builder.WriteString(b.TorrentName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("media_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.MediaID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(b.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("notes=")
|
||||
builder.WriteString(b.Notes)
|
||||
|
||||
@@ -4,7 +4,7 @@ package blacklist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/ent/schema"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -16,8 +16,14 @@ const (
|
||||
FieldID = "id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// FieldTorrentHash holds the string denoting the torrent_hash field in the database.
|
||||
FieldTorrentHash = "torrent_hash"
|
||||
// FieldTorrentName holds the string denoting the torrent_name field in the database.
|
||||
FieldTorrentName = "torrent_name"
|
||||
// FieldMediaID holds the string denoting the media_id field in the database.
|
||||
FieldMediaID = "media_id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldNotes holds the string denoting the notes field in the database.
|
||||
FieldNotes = "notes"
|
||||
// Table holds the table name of the blacklist in the database.
|
||||
@@ -28,7 +34,10 @@ const (
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldType,
|
||||
FieldValue,
|
||||
FieldTorrentHash,
|
||||
FieldTorrentName,
|
||||
FieldMediaID,
|
||||
FieldCreateTime,
|
||||
FieldNotes,
|
||||
}
|
||||
|
||||
@@ -43,13 +52,16 @@ func ValidColumn(column string) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultValue holds the default value on creation for the "value" field.
|
||||
DefaultValue schema.BlacklistValue
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// TypeTorrent is the default value of the Type enum.
|
||||
const DefaultType = TypeTorrent
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeMedia Type = "media"
|
||||
@@ -83,6 +95,26 @@ func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTorrentHash orders the results by the torrent_hash field.
|
||||
func ByTorrentHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTorrentHash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTorrentName orders the results by the torrent_name field.
|
||||
func ByTorrentName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTorrentName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMediaID orders the results by the media_id field.
|
||||
func ByMediaID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMediaID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNotes orders the results by the notes field.
|
||||
func ByNotes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNotes, opts...).ToFunc()
|
||||
|
||||
@@ -4,6 +4,7 @@ package blacklist
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -53,6 +54,26 @@ func IDLTE(id int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// TorrentHash applies equality check predicate on the "torrent_hash" field. It's identical to TorrentHashEQ.
|
||||
func TorrentHash(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentName applies equality check predicate on the "torrent_name" field. It's identical to TorrentNameEQ.
|
||||
func TorrentName(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// MediaID applies equality check predicate on the "media_id" field. It's identical to MediaIDEQ.
|
||||
func MediaID(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
|
||||
func Notes(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))
|
||||
@@ -78,6 +99,256 @@ func TypeNotIn(vs ...Type) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashEQ applies the EQ predicate on the "torrent_hash" field.
|
||||
func TorrentHashEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashNEQ applies the NEQ predicate on the "torrent_hash" field.
|
||||
func TorrentHashNEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashIn applies the In predicate on the "torrent_hash" field.
|
||||
func TorrentHashIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldTorrentHash, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashNotIn applies the NotIn predicate on the "torrent_hash" field.
|
||||
func TorrentHashNotIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentHash, vs...))
|
||||
}
|
||||
|
||||
// TorrentHashGT applies the GT predicate on the "torrent_hash" field.
|
||||
func TorrentHashGT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashGTE applies the GTE predicate on the "torrent_hash" field.
|
||||
func TorrentHashGTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashLT applies the LT predicate on the "torrent_hash" field.
|
||||
func TorrentHashLT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashLTE applies the LTE predicate on the "torrent_hash" field.
|
||||
func TorrentHashLTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashContains applies the Contains predicate on the "torrent_hash" field.
|
||||
func TorrentHashContains(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContains(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashHasPrefix applies the HasPrefix predicate on the "torrent_hash" field.
|
||||
func TorrentHashHasPrefix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashHasSuffix applies the HasSuffix predicate on the "torrent_hash" field.
|
||||
func TorrentHashHasSuffix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashIsNil applies the IsNil predicate on the "torrent_hash" field.
|
||||
func TorrentHashIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentHash))
|
||||
}
|
||||
|
||||
// TorrentHashNotNil applies the NotNil predicate on the "torrent_hash" field.
|
||||
func TorrentHashNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentHash))
|
||||
}
|
||||
|
||||
// TorrentHashEqualFold applies the EqualFold predicate on the "torrent_hash" field.
|
||||
func TorrentHashEqualFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentHashContainsFold applies the ContainsFold predicate on the "torrent_hash" field.
|
||||
func TorrentHashContainsFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentHash, v))
|
||||
}
|
||||
|
||||
// TorrentNameEQ applies the EQ predicate on the "torrent_name" field.
|
||||
func TorrentNameEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameNEQ applies the NEQ predicate on the "torrent_name" field.
|
||||
func TorrentNameNEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameIn applies the In predicate on the "torrent_name" field.
|
||||
func TorrentNameIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldTorrentName, vs...))
|
||||
}
|
||||
|
||||
// TorrentNameNotIn applies the NotIn predicate on the "torrent_name" field.
|
||||
func TorrentNameNotIn(vs ...string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldTorrentName, vs...))
|
||||
}
|
||||
|
||||
// TorrentNameGT applies the GT predicate on the "torrent_name" field.
|
||||
func TorrentNameGT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameGTE applies the GTE predicate on the "torrent_name" field.
|
||||
func TorrentNameGTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameLT applies the LT predicate on the "torrent_name" field.
|
||||
func TorrentNameLT(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameLTE applies the LTE predicate on the "torrent_name" field.
|
||||
func TorrentNameLTE(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameContains applies the Contains predicate on the "torrent_name" field.
|
||||
func TorrentNameContains(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContains(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameHasPrefix applies the HasPrefix predicate on the "torrent_name" field.
|
||||
func TorrentNameHasPrefix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasPrefix(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameHasSuffix applies the HasSuffix predicate on the "torrent_name" field.
|
||||
func TorrentNameHasSuffix(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldHasSuffix(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameIsNil applies the IsNil predicate on the "torrent_name" field.
|
||||
func TorrentNameIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldTorrentName))
|
||||
}
|
||||
|
||||
// TorrentNameNotNil applies the NotNil predicate on the "torrent_name" field.
|
||||
func TorrentNameNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldTorrentName))
|
||||
}
|
||||
|
||||
// TorrentNameEqualFold applies the EqualFold predicate on the "torrent_name" field.
|
||||
func TorrentNameEqualFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEqualFold(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// TorrentNameContainsFold applies the ContainsFold predicate on the "torrent_name" field.
|
||||
func TorrentNameContainsFold(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldContainsFold(FieldTorrentName, v))
|
||||
}
|
||||
|
||||
// MediaIDEQ applies the EQ predicate on the "media_id" field.
|
||||
func MediaIDEQ(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDNEQ applies the NEQ predicate on the "media_id" field.
|
||||
func MediaIDNEQ(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDIn applies the In predicate on the "media_id" field.
|
||||
func MediaIDIn(vs ...int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldMediaID, vs...))
|
||||
}
|
||||
|
||||
// MediaIDNotIn applies the NotIn predicate on the "media_id" field.
|
||||
func MediaIDNotIn(vs ...int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldMediaID, vs...))
|
||||
}
|
||||
|
||||
// MediaIDGT applies the GT predicate on the "media_id" field.
|
||||
func MediaIDGT(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDGTE applies the GTE predicate on the "media_id" field.
|
||||
func MediaIDGTE(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDLT applies the LT predicate on the "media_id" field.
|
||||
func MediaIDLT(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDLTE applies the LTE predicate on the "media_id" field.
|
||||
func MediaIDLTE(v int) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldMediaID, v))
|
||||
}
|
||||
|
||||
// MediaIDIsNil applies the IsNil predicate on the "media_id" field.
|
||||
func MediaIDIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldMediaID))
|
||||
}
|
||||
|
||||
// MediaIDNotNil applies the NotNil predicate on the "media_id" field.
|
||||
func MediaIDNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldMediaID))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// NotesEQ applies the EQ predicate on the "notes" field.
|
||||
func NotesEQ(v string) predicate.Blacklist {
|
||||
return predicate.Blacklist(sql.FieldEQ(FieldNotes, v))
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/schema"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -26,16 +26,66 @@ func (bc *BlacklistCreate) SetType(b blacklist.Type) *BlacklistCreate {
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bc *BlacklistCreate) SetValue(sv schema.BlacklistValue) *BlacklistCreate {
|
||||
bc.mutation.SetValue(sv)
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableType(b *blacklist.Type) *BlacklistCreate {
|
||||
if b != nil {
|
||||
bc.SetType(*b)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistCreate {
|
||||
if sv != nil {
|
||||
bc.SetValue(*sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (bc *BlacklistCreate) SetTorrentHash(s string) *BlacklistCreate {
|
||||
bc.mutation.SetTorrentHash(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableTorrentHash(s *string) *BlacklistCreate {
|
||||
if s != nil {
|
||||
bc.SetTorrentHash(*s)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (bc *BlacklistCreate) SetTorrentName(s string) *BlacklistCreate {
|
||||
bc.mutation.SetTorrentName(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableTorrentName(s *string) *BlacklistCreate {
|
||||
if s != nil {
|
||||
bc.SetTorrentName(*s)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (bc *BlacklistCreate) SetMediaID(i int) *BlacklistCreate {
|
||||
bc.mutation.SetMediaID(i)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableMediaID(i *int) *BlacklistCreate {
|
||||
if i != nil {
|
||||
bc.SetMediaID(*i)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (bc *BlacklistCreate) SetCreateTime(t time.Time) *BlacklistCreate {
|
||||
bc.mutation.SetCreateTime(t)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (bc *BlacklistCreate) SetNillableCreateTime(t *time.Time) *BlacklistCreate {
|
||||
if t != nil {
|
||||
bc.SetCreateTime(*t)
|
||||
}
|
||||
return bc
|
||||
}
|
||||
@@ -89,9 +139,13 @@ func (bc *BlacklistCreate) ExecX(ctx context.Context) {
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (bc *BlacklistCreate) defaults() {
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
v := blacklist.DefaultValue
|
||||
bc.mutation.SetValue(v)
|
||||
if _, ok := bc.mutation.GetType(); !ok {
|
||||
v := blacklist.DefaultType
|
||||
bc.mutation.SetType(v)
|
||||
}
|
||||
if _, ok := bc.mutation.CreateTime(); !ok {
|
||||
v := blacklist.DefaultCreateTime()
|
||||
bc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +159,6 @@ func (bc *BlacklistCreate) check() error {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blacklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Blacklist.value"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -138,9 +189,21 @@ func (bc *BlacklistCreate) createSpec() (*Blacklist, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := bc.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
_node.Value = value
|
||||
if value, ok := bc.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
_node.TorrentHash = value
|
||||
}
|
||||
if value, ok := bc.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
_node.TorrentName = value
|
||||
}
|
||||
if value, ok := bc.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
_node.MediaID = value
|
||||
}
|
||||
if value, ok := bc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(blacklist.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := bc.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/predicate"
|
||||
"polaris/ent/schema"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
@@ -42,20 +41,73 @@ func (bu *BlacklistUpdate) SetNillableType(b *blacklist.Type) *BlacklistUpdate {
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bu *BlacklistUpdate) SetValue(sv schema.BlacklistValue) *BlacklistUpdate {
|
||||
bu.mutation.SetValue(sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (bu *BlacklistUpdate) SetTorrentHash(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetTorrentHash(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdate {
|
||||
if sv != nil {
|
||||
bu.SetValue(*sv)
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableTorrentHash(s *string) *BlacklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetTorrentHash(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearTorrentHash clears the value of the "torrent_hash" field.
|
||||
func (bu *BlacklistUpdate) ClearTorrentHash() *BlacklistUpdate {
|
||||
bu.mutation.ClearTorrentHash()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (bu *BlacklistUpdate) SetTorrentName(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetTorrentName(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableTorrentName(s *string) *BlacklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetTorrentName(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearTorrentName clears the value of the "torrent_name" field.
|
||||
func (bu *BlacklistUpdate) ClearTorrentName() *BlacklistUpdate {
|
||||
bu.mutation.ClearTorrentName()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (bu *BlacklistUpdate) SetMediaID(i int) *BlacklistUpdate {
|
||||
bu.mutation.ResetMediaID()
|
||||
bu.mutation.SetMediaID(i)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (bu *BlacklistUpdate) SetNillableMediaID(i *int) *BlacklistUpdate {
|
||||
if i != nil {
|
||||
bu.SetMediaID(*i)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// AddMediaID adds i to the "media_id" field.
|
||||
func (bu *BlacklistUpdate) AddMediaID(i int) *BlacklistUpdate {
|
||||
bu.mutation.AddMediaID(i)
|
||||
return bu
|
||||
}
|
||||
|
||||
// ClearMediaID clears the value of the "media_id" field.
|
||||
func (bu *BlacklistUpdate) ClearMediaID() *BlacklistUpdate {
|
||||
bu.mutation.ClearMediaID()
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNotes sets the "notes" field.
|
||||
func (bu *BlacklistUpdate) SetNotes(s string) *BlacklistUpdate {
|
||||
bu.mutation.SetNotes(s)
|
||||
@@ -133,8 +185,29 @@ func (bu *BlacklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := bu.mutation.GetType(); ok {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := bu.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
if value, ok := bu.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
}
|
||||
if bu.mutation.TorrentHashCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
|
||||
}
|
||||
if value, ok := bu.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
}
|
||||
if bu.mutation.TorrentNameCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
|
||||
}
|
||||
if value, ok := bu.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := bu.mutation.AddedMediaID(); ok {
|
||||
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if bu.mutation.MediaIDCleared() {
|
||||
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
|
||||
}
|
||||
if bu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := bu.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
@@ -176,20 +249,73 @@ func (buo *BlacklistUpdateOne) SetNillableType(b *blacklist.Type) *BlacklistUpda
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (buo *BlacklistUpdateOne) SetValue(sv schema.BlacklistValue) *BlacklistUpdateOne {
|
||||
buo.mutation.SetValue(sv)
|
||||
// SetTorrentHash sets the "torrent_hash" field.
|
||||
func (buo *BlacklistUpdateOne) SetTorrentHash(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetTorrentHash(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableValue(sv *schema.BlacklistValue) *BlacklistUpdateOne {
|
||||
if sv != nil {
|
||||
buo.SetValue(*sv)
|
||||
// SetNillableTorrentHash sets the "torrent_hash" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableTorrentHash(s *string) *BlacklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetTorrentHash(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearTorrentHash clears the value of the "torrent_hash" field.
|
||||
func (buo *BlacklistUpdateOne) ClearTorrentHash() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearTorrentHash()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetTorrentName sets the "torrent_name" field.
|
||||
func (buo *BlacklistUpdateOne) SetTorrentName(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetTorrentName(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableTorrentName sets the "torrent_name" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableTorrentName(s *string) *BlacklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetTorrentName(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearTorrentName clears the value of the "torrent_name" field.
|
||||
func (buo *BlacklistUpdateOne) ClearTorrentName() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearTorrentName()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetMediaID sets the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) SetMediaID(i int) *BlacklistUpdateOne {
|
||||
buo.mutation.ResetMediaID()
|
||||
buo.mutation.SetMediaID(i)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableMediaID sets the "media_id" field if the given value is not nil.
|
||||
func (buo *BlacklistUpdateOne) SetNillableMediaID(i *int) *BlacklistUpdateOne {
|
||||
if i != nil {
|
||||
buo.SetMediaID(*i)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// AddMediaID adds i to the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) AddMediaID(i int) *BlacklistUpdateOne {
|
||||
buo.mutation.AddMediaID(i)
|
||||
return buo
|
||||
}
|
||||
|
||||
// ClearMediaID clears the value of the "media_id" field.
|
||||
func (buo *BlacklistUpdateOne) ClearMediaID() *BlacklistUpdateOne {
|
||||
buo.mutation.ClearMediaID()
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNotes sets the "notes" field.
|
||||
func (buo *BlacklistUpdateOne) SetNotes(s string) *BlacklistUpdateOne {
|
||||
buo.mutation.SetNotes(s)
|
||||
@@ -297,8 +423,29 @@ func (buo *BlacklistUpdateOne) sqlSave(ctx context.Context) (_node *Blacklist, e
|
||||
if value, ok := buo.mutation.GetType(); ok {
|
||||
_spec.SetField(blacklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := buo.mutation.Value(); ok {
|
||||
_spec.SetField(blacklist.FieldValue, field.TypeJSON, value)
|
||||
if value, ok := buo.mutation.TorrentHash(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentHash, field.TypeString, value)
|
||||
}
|
||||
if buo.mutation.TorrentHashCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentHash, field.TypeString)
|
||||
}
|
||||
if value, ok := buo.mutation.TorrentName(); ok {
|
||||
_spec.SetField(blacklist.FieldTorrentName, field.TypeString, value)
|
||||
}
|
||||
if buo.mutation.TorrentNameCleared() {
|
||||
_spec.ClearField(blacklist.FieldTorrentName, field.TypeString)
|
||||
}
|
||||
if value, ok := buo.mutation.MediaID(); ok {
|
||||
_spec.SetField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := buo.mutation.AddedMediaID(); ok {
|
||||
_spec.AddField(blacklist.FieldMediaID, field.TypeInt, value)
|
||||
}
|
||||
if buo.mutation.MediaIDCleared() {
|
||||
_spec.ClearField(blacklist.FieldMediaID, field.TypeInt)
|
||||
}
|
||||
if buo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(blacklist.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := buo.mutation.Notes(); ok {
|
||||
_spec.SetField(blacklist.FieldNotes, field.TypeString, value)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/downloadclients"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -37,7 +38,9 @@ type DownloadClients struct {
|
||||
// RemoveFailedDownloads holds the value of the "remove_failed_downloads" field.
|
||||
RemoveFailedDownloads bool `json:"remove_failed_downloads,omitempty"`
|
||||
// Tags holds the value of the "tags" field.
|
||||
Tags string `json:"tags,omitempty"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -52,6 +55,8 @@ func (*DownloadClients) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case downloadclients.FieldName, downloadclients.FieldImplementation, downloadclients.FieldURL, downloadclients.FieldUser, downloadclients.FieldPassword, downloadclients.FieldSettings, downloadclients.FieldTags:
|
||||
values[i] = new(sql.NullString)
|
||||
case downloadclients.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -139,6 +144,12 @@ func (dc *DownloadClients) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
dc.Tags = value.String
|
||||
}
|
||||
case downloadclients.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
dc.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
dc.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -207,6 +218,9 @@ func (dc *DownloadClients) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("tags=")
|
||||
builder.WriteString(dc.Tags)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(dc.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package downloadclients
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -35,6 +36,8 @@ const (
|
||||
FieldRemoveFailedDownloads = "remove_failed_downloads"
|
||||
// FieldTags holds the string denoting the tags field in the database.
|
||||
FieldTags = "tags"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// Table holds the table name of the downloadclients in the database.
|
||||
Table = "download_clients"
|
||||
)
|
||||
@@ -53,6 +56,7 @@ var Columns = []string{
|
||||
FieldRemoveCompletedDownloads,
|
||||
FieldRemoveFailedDownloads,
|
||||
FieldTags,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -82,6 +86,8 @@ var (
|
||||
DefaultRemoveFailedDownloads bool
|
||||
// DefaultTags holds the default value on creation for the "tags" field.
|
||||
DefaultTags string
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Implementation defines the type for the "implementation" enum field.
|
||||
@@ -170,3 +176,8 @@ func ByRemoveFailedDownloads(opts ...sql.OrderTermOption) OrderOption {
|
||||
func ByTags(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTags, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package downloadclients
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -103,6 +104,11 @@ func Tags(v string) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldEQ(FieldTags, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// EnableEQ applies the EQ predicate on the "enable" field.
|
||||
func EnableEQ(v bool) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldEQ(FieldEnable, v))
|
||||
@@ -583,6 +589,56 @@ func TagsContainsFold(v string) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldContainsFold(FieldTags, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.DownloadClients) predicate.DownloadClients {
|
||||
return predicate.DownloadClients(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/downloadclients"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -141,6 +142,20 @@ func (dcc *DownloadClientsCreate) SetNillableTags(s *string) *DownloadClientsCre
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (dcc *DownloadClientsCreate) SetCreateTime(t time.Time) *DownloadClientsCreate {
|
||||
dcc.mutation.SetCreateTime(t)
|
||||
return dcc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (dcc *DownloadClientsCreate) SetNillableCreateTime(t *time.Time) *DownloadClientsCreate {
|
||||
if t != nil {
|
||||
dcc.SetCreateTime(*t)
|
||||
}
|
||||
return dcc
|
||||
}
|
||||
|
||||
// Mutation returns the DownloadClientsMutation object of the builder.
|
||||
func (dcc *DownloadClientsCreate) Mutation() *DownloadClientsMutation {
|
||||
return dcc.mutation
|
||||
@@ -204,6 +219,10 @@ func (dcc *DownloadClientsCreate) defaults() {
|
||||
v := downloadclients.DefaultTags
|
||||
dcc.mutation.SetTags(v)
|
||||
}
|
||||
if _, ok := dcc.mutation.CreateTime(); !ok {
|
||||
v := downloadclients.DefaultCreateTime()
|
||||
dcc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -321,6 +340,10 @@ func (dcc *DownloadClientsCreate) createSpec() (*DownloadClients, *sqlgraph.Crea
|
||||
_spec.SetField(downloadclients.FieldTags, field.TypeString, value)
|
||||
_node.Tags = value
|
||||
}
|
||||
if value, ok := dcc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(downloadclients.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -283,6 +283,9 @@ func (dcu *DownloadClientsUpdate) sqlSave(ctx context.Context) (n int, err error
|
||||
if value, ok := dcu.mutation.Tags(); ok {
|
||||
_spec.SetField(downloadclients.FieldTags, field.TypeString, value)
|
||||
}
|
||||
if dcu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(downloadclients.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, dcu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{downloadclients.Label}
|
||||
@@ -589,6 +592,9 @@ func (dcuo *DownloadClientsUpdateOne) sqlSave(ctx context.Context) (_node *Downl
|
||||
if value, ok := dcuo.mutation.Tags(); ok {
|
||||
_spec.SetField(downloadclients.FieldTags, field.TypeString, value)
|
||||
}
|
||||
if dcuo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(downloadclients.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
_node = &DownloadClients{config: dcuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/media"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -35,6 +36,8 @@ type Episode struct {
|
||||
Monitored bool `json:"monitored"`
|
||||
// TargetFile holds the value of the "target_file" field.
|
||||
TargetFile string `json:"target_file,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the EpisodeQuery when eager-loading is set.
|
||||
Edges EpisodeEdges `json:"edges"`
|
||||
@@ -72,6 +75,8 @@ func (*Episode) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate, episode.FieldStatus, episode.FieldTargetFile:
|
||||
values[i] = new(sql.NullString)
|
||||
case episode.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -147,6 +152,12 @@ func (e *Episode) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
e.TargetFile = value.String
|
||||
}
|
||||
case episode.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
e.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
e.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -214,6 +225,9 @@ func (e *Episode) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("target_file=")
|
||||
builder.WriteString(e.TargetFile)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(e.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package episode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
@@ -32,6 +33,8 @@ const (
|
||||
FieldMonitored = "monitored"
|
||||
// FieldTargetFile holds the string denoting the target_file field in the database.
|
||||
FieldTargetFile = "target_file"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// EdgeMedia holds the string denoting the media edge name in mutations.
|
||||
EdgeMedia = "media"
|
||||
// Table holds the table name of the episode in the database.
|
||||
@@ -57,6 +60,7 @@ var Columns = []string{
|
||||
FieldStatus,
|
||||
FieldMonitored,
|
||||
FieldTargetFile,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -72,6 +76,8 @@ func ValidColumn(column string) bool {
|
||||
var (
|
||||
// DefaultMonitored holds the default value on creation for the "monitored" field.
|
||||
DefaultMonitored bool
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
@@ -154,6 +160,11 @@ func ByTargetFile(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTargetFile, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMediaField orders the results by media field.
|
||||
func ByMediaField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
|
||||
@@ -4,6 +4,7 @@ package episode
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
@@ -94,6 +95,11 @@ func TargetFile(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// MediaIDEQ applies the EQ predicate on the "media_id" field.
|
||||
func MediaIDEQ(v int) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldMediaID, v))
|
||||
@@ -504,6 +510,56 @@ func TargetFileContainsFold(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldContainsFold(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Episode {
|
||||
return predicate.Episode(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// HasMedia applies the HasEdge predicate on the "media" edge.
|
||||
func HasMedia() predicate.Episode {
|
||||
return predicate.Episode(func(s *sql.Selector) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/media"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -106,6 +107,20 @@ func (ec *EpisodeCreate) SetNillableTargetFile(s *string) *EpisodeCreate {
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (ec *EpisodeCreate) SetCreateTime(t time.Time) *EpisodeCreate {
|
||||
ec.mutation.SetCreateTime(t)
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (ec *EpisodeCreate) SetNillableCreateTime(t *time.Time) *EpisodeCreate {
|
||||
if t != nil {
|
||||
ec.SetCreateTime(*t)
|
||||
}
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetMedia sets the "media" edge to the Media entity.
|
||||
func (ec *EpisodeCreate) SetMedia(m *Media) *EpisodeCreate {
|
||||
return ec.SetMediaID(m.ID)
|
||||
@@ -154,6 +169,10 @@ func (ec *EpisodeCreate) defaults() {
|
||||
v := episode.DefaultMonitored
|
||||
ec.mutation.SetMonitored(v)
|
||||
}
|
||||
if _, ok := ec.mutation.CreateTime(); !ok {
|
||||
v := episode.DefaultCreateTime()
|
||||
ec.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -242,6 +261,10 @@ func (ec *EpisodeCreate) createSpec() (*Episode, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(episode.FieldTargetFile, field.TypeString, value)
|
||||
_node.TargetFile = value
|
||||
}
|
||||
if value, ok := ec.mutation.CreateTime(); ok {
|
||||
_spec.SetField(episode.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if nodes := ec.mutation.MediaIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
||||
@@ -278,6 +278,9 @@ func (eu *EpisodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if eu.mutation.TargetFileCleared() {
|
||||
_spec.ClearField(episode.FieldTargetFile, field.TypeString)
|
||||
}
|
||||
if eu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(episode.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if eu.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -607,6 +610,9 @@ func (euo *EpisodeUpdateOne) sqlSave(ctx context.Context) (_node *Episode, err e
|
||||
if euo.mutation.TargetFileCleared() {
|
||||
_spec.ClearField(episode.FieldTargetFile, field.TypeString)
|
||||
}
|
||||
if euo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(episode.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if euo.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
||||
@@ -36,12 +36,14 @@ type History struct {
|
||||
DownloadClientID int `json:"download_client_id,omitempty"`
|
||||
// IndexerID holds the value of the "indexer_id" field.
|
||||
IndexerID int `json:"indexer_id,omitempty"`
|
||||
// deprecated, use hash instead
|
||||
// torrent link
|
||||
Link string `json:"link,omitempty"`
|
||||
// torrent hash
|
||||
Hash string `json:"hash,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status history.Status `json:"status,omitempty"`
|
||||
Status history.Status `json:"status,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ func (*History) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldLink, history.FieldHash, history.FieldStatus:
|
||||
values[i] = new(sql.NullString)
|
||||
case history.FieldDate:
|
||||
case history.FieldDate, history.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -153,6 +155,12 @@ func (h *History) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
h.Status = history.Status(value.String)
|
||||
}
|
||||
case history.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
h.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
h.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -224,6 +232,9 @@ func (h *History) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.Status))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(h.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package history
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -37,6 +38,8 @@ const (
|
||||
FieldHash = "hash"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// Table holds the table name of the history in the database.
|
||||
Table = "histories"
|
||||
)
|
||||
@@ -56,6 +59,7 @@ var Columns = []string{
|
||||
FieldLink,
|
||||
FieldHash,
|
||||
FieldStatus,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -71,6 +75,8 @@ func ValidColumn(column string) bool {
|
||||
var (
|
||||
// DefaultSize holds the default value on creation for the "size" field.
|
||||
DefaultSize int
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
@@ -162,3 +168,8 @@ func ByHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
@@ -104,6 +104,11 @@ func Hash(v string) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldHash, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// MediaIDEQ applies the EQ predicate on the "media_id" field.
|
||||
func MediaIDEQ(v int) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldMediaID, v))
|
||||
@@ -684,6 +689,56 @@ func StatusNotIn(vs ...Status) predicate.History {
|
||||
return predicate.History(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.History {
|
||||
return predicate.History(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.History {
|
||||
return predicate.History(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.History {
|
||||
return predicate.History(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.History) predicate.History {
|
||||
return predicate.History(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -140,6 +140,20 @@ func (hc *HistoryCreate) SetStatus(h history.Status) *HistoryCreate {
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (hc *HistoryCreate) SetCreateTime(t time.Time) *HistoryCreate {
|
||||
hc.mutation.SetCreateTime(t)
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (hc *HistoryCreate) SetNillableCreateTime(t *time.Time) *HistoryCreate {
|
||||
if t != nil {
|
||||
hc.SetCreateTime(*t)
|
||||
}
|
||||
return hc
|
||||
}
|
||||
|
||||
// Mutation returns the HistoryMutation object of the builder.
|
||||
func (hc *HistoryCreate) Mutation() *HistoryMutation {
|
||||
return hc.mutation
|
||||
@@ -179,6 +193,10 @@ func (hc *HistoryCreate) defaults() {
|
||||
v := history.DefaultSize
|
||||
hc.mutation.SetSize(v)
|
||||
}
|
||||
if _, ok := hc.mutation.CreateTime(); !ok {
|
||||
v := history.DefaultCreateTime()
|
||||
hc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -280,6 +298,10 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := hc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(history.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -394,6 +394,9 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := hu.mutation.Status(); ok {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if hu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(history.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{history.Label}
|
||||
@@ -809,6 +812,9 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
|
||||
if value, ok := huo.mutation.Status(); ok {
|
||||
_spec.SetField(history.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if huo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(history.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
_node = &History{config: huo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/indexers"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -39,7 +40,9 @@ type Indexers struct {
|
||||
// URL holds the value of the "url" field.
|
||||
URL string `json:"url,omitempty"`
|
||||
// synced from prowlarr
|
||||
Synced bool `json:"synced,omitempty"`
|
||||
Synced bool `json:"synced,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -56,6 +59,8 @@ func (*Indexers) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case indexers.FieldName, indexers.FieldImplementation, indexers.FieldSettings, indexers.FieldAPIKey, indexers.FieldURL:
|
||||
values[i] = new(sql.NullString)
|
||||
case indexers.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -149,6 +154,12 @@ func (i *Indexers) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
i.Synced = value.Bool
|
||||
}
|
||||
case indexers.FieldCreateTime:
|
||||
if value, ok := values[j].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[j])
|
||||
} else if value.Valid {
|
||||
i.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
i.selectValues.Set(columns[j], values[j])
|
||||
}
|
||||
@@ -220,6 +231,9 @@ func (i *Indexers) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("synced=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Synced))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(i.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
package indexers
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
@@ -35,6 +37,8 @@ const (
|
||||
FieldURL = "url"
|
||||
// FieldSynced holds the string denoting the synced field in the database.
|
||||
FieldSynced = "synced"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// Table holds the table name of the indexers in the database.
|
||||
Table = "indexers"
|
||||
)
|
||||
@@ -54,6 +58,7 @@ var Columns = []string{
|
||||
FieldAPIKey,
|
||||
FieldURL,
|
||||
FieldSynced,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -73,6 +78,8 @@ var (
|
||||
DefaultEnableRss bool
|
||||
// DefaultPriority holds the default value on creation for the "priority" field.
|
||||
DefaultPriority int
|
||||
// PriorityValidator is a validator for the "priority" field. It is called by the builders before save.
|
||||
PriorityValidator func(int) error
|
||||
// DefaultSeedRatio holds the default value on creation for the "seed_ratio" field.
|
||||
DefaultSeedRatio float32
|
||||
// DefaultDisabled holds the default value on creation for the "disabled" field.
|
||||
@@ -83,6 +90,8 @@ var (
|
||||
DefaultMovieSearch bool
|
||||
// DefaultSynced holds the default value on creation for the "synced" field.
|
||||
DefaultSynced bool
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Indexers queries.
|
||||
@@ -152,3 +161,8 @@ func ByURL(opts ...sql.OrderTermOption) OrderOption {
|
||||
func BySynced(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSynced, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package indexers
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -113,6 +114,11 @@ func Synced(v bool) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldSynced, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldName, v))
|
||||
@@ -648,6 +654,56 @@ func SyncedNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldSynced))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Indexers {
|
||||
return predicate.Indexers(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Indexers) predicate.Indexers {
|
||||
return predicate.Indexers(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/indexers"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -171,6 +172,20 @@ func (ic *IndexersCreate) SetNillableSynced(b *bool) *IndexersCreate {
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (ic *IndexersCreate) SetCreateTime(t time.Time) *IndexersCreate {
|
||||
ic.mutation.SetCreateTime(t)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (ic *IndexersCreate) SetNillableCreateTime(t *time.Time) *IndexersCreate {
|
||||
if t != nil {
|
||||
ic.SetCreateTime(*t)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// Mutation returns the IndexersMutation object of the builder.
|
||||
func (ic *IndexersCreate) Mutation() *IndexersMutation {
|
||||
return ic.mutation
|
||||
@@ -238,6 +253,10 @@ func (ic *IndexersCreate) defaults() {
|
||||
v := indexers.DefaultSynced
|
||||
ic.mutation.SetSynced(v)
|
||||
}
|
||||
if _, ok := ic.mutation.CreateTime(); !ok {
|
||||
v := indexers.DefaultCreateTime()
|
||||
ic.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -254,6 +273,11 @@ func (ic *IndexersCreate) check() error {
|
||||
if _, ok := ic.mutation.Priority(); !ok {
|
||||
return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "Indexers.priority"`)}
|
||||
}
|
||||
if v, ok := ic.mutation.Priority(); ok {
|
||||
if err := indexers.PriorityValidator(v); err != nil {
|
||||
return &ValidationError{Name: "priority", err: fmt.Errorf(`ent: validator failed for field "Indexers.priority": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -328,6 +352,10 @@ func (ic *IndexersCreate) createSpec() (*Indexers, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(indexers.FieldSynced, field.TypeBool, value)
|
||||
_node.Synced = value
|
||||
}
|
||||
if value, ok := ic.mutation.CreateTime(); ok {
|
||||
_spec.SetField(indexers.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,20 @@ func (iu *IndexersUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (iu *IndexersUpdate) check() error {
|
||||
if v, ok := iu.mutation.Priority(); ok {
|
||||
if err := indexers.PriorityValidator(v); err != nil {
|
||||
return &ValidationError{Name: "priority", err: fmt.Errorf(`ent: validator failed for field "Indexers.priority": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := iu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(indexers.Table, indexers.Columns, sqlgraph.NewFieldSpec(indexers.FieldID, field.TypeInt))
|
||||
if ps := iu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
@@ -364,6 +377,9 @@ func (iu *IndexersUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if iu.mutation.SyncedCleared() {
|
||||
_spec.ClearField(indexers.FieldSynced, field.TypeBool)
|
||||
}
|
||||
if iu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(indexers.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{indexers.Label}
|
||||
@@ -659,7 +675,20 @@ func (iuo *IndexersUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (iuo *IndexersUpdateOne) check() error {
|
||||
if v, ok := iuo.mutation.Priority(); ok {
|
||||
if err := indexers.PriorityValidator(v); err != nil {
|
||||
return &ValidationError{Name: "priority", err: fmt.Errorf(`ent: validator failed for field "Indexers.priority": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err error) {
|
||||
if err := iuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(indexers.Table, indexers.Columns, sqlgraph.NewFieldSpec(indexers.FieldID, field.TypeInt))
|
||||
id, ok := iuo.mutation.ID()
|
||||
if !ok {
|
||||
@@ -751,6 +780,9 @@ func (iuo *IndexersUpdateOne) sqlSave(ctx context.Context) (_node *Indexers, err
|
||||
if iuo.mutation.SyncedCleared() {
|
||||
_spec.ClearField(indexers.FieldSynced, field.TypeBool)
|
||||
}
|
||||
if iuo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(indexers.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
_node = &Indexers{config: iuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
13
ent/media.go
13
ent/media.go
@@ -51,6 +51,8 @@ type Media struct {
|
||||
Extras schema.MediaExtras `json:"extras,omitempty"`
|
||||
// AlternativeTitles holds the value of the "alternative_titles" field.
|
||||
AlternativeTitles []schema.AlternativeTilte `json:"alternative_titles,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the MediaQuery when eager-loading is set.
|
||||
Edges MediaEdges `json:"edges"`
|
||||
@@ -88,7 +90,7 @@ func (*Media) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case media.FieldImdbID, media.FieldMediaType, media.FieldNameCn, media.FieldNameEn, media.FieldOriginalName, media.FieldOverview, media.FieldAirDate, media.FieldResolution, media.FieldTargetDir:
|
||||
values[i] = new(sql.NullString)
|
||||
case media.FieldCreatedAt:
|
||||
case media.FieldCreatedAt, media.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -213,6 +215,12 @@ func (m *Media) assignValues(columns []string, values []any) error {
|
||||
return fmt.Errorf("unmarshal field alternative_titles: %w", err)
|
||||
}
|
||||
}
|
||||
case media.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
m.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -301,6 +309,9 @@ func (m *Media) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("alternative_titles=")
|
||||
builder.WriteString(fmt.Sprintf("%v", m.AlternativeTitles))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(m.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ const (
|
||||
FieldExtras = "extras"
|
||||
// FieldAlternativeTitles holds the string denoting the alternative_titles field in the database.
|
||||
FieldAlternativeTitles = "alternative_titles"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
|
||||
EdgeEpisodes = "episodes"
|
||||
// Table holds the table name of the media in the database.
|
||||
@@ -79,6 +81,7 @@ var Columns = []string{
|
||||
FieldLimiter,
|
||||
FieldExtras,
|
||||
FieldAlternativeTitles,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -98,6 +101,8 @@ var (
|
||||
DefaultAirDate string
|
||||
// DefaultDownloadHistoryEpisodes holds the default value on creation for the "download_history_episodes" field.
|
||||
DefaultDownloadHistoryEpisodes bool
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// MediaType defines the type for the "media_type" enum field.
|
||||
@@ -224,6 +229,11 @@ func ByDownloadHistoryEpisodes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDownloadHistoryEpisodes, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEpisodesCount orders the results by episodes count.
|
||||
func ByEpisodesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
|
||||
@@ -110,6 +110,11 @@ func DownloadHistoryEpisodes(v bool) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldDownloadHistoryEpisodes, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// TmdbIDEQ applies the EQ predicate on the "tmdb_id" field.
|
||||
func TmdbIDEQ(v int) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldTmdbID, v))
|
||||
@@ -805,6 +810,56 @@ func AlternativeTitlesNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldAlternativeTitles))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Media {
|
||||
return predicate.Media(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
|
||||
func HasEpisodes() predicate.Media {
|
||||
return predicate.Media(func(s *sql.Selector) {
|
||||
|
||||
@@ -190,6 +190,20 @@ func (mc *MediaCreate) SetAlternativeTitles(st []schema.AlternativeTilte) *Media
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (mc *MediaCreate) SetCreateTime(t time.Time) *MediaCreate {
|
||||
mc.mutation.SetCreateTime(t)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (mc *MediaCreate) SetNillableCreateTime(t *time.Time) *MediaCreate {
|
||||
if t != nil {
|
||||
mc.SetCreateTime(*t)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate {
|
||||
mc.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -256,6 +270,10 @@ func (mc *MediaCreate) defaults() {
|
||||
v := media.DefaultDownloadHistoryEpisodes
|
||||
mc.mutation.SetDownloadHistoryEpisodes(v)
|
||||
}
|
||||
if _, ok := mc.mutation.CreateTime(); !ok {
|
||||
v := media.DefaultCreateTime()
|
||||
mc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -387,6 +405,10 @@ func (mc *MediaCreate) createSpec() (*Media, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(media.FieldAlternativeTitles, field.TypeJSON, value)
|
||||
_node.AlternativeTitles = value
|
||||
}
|
||||
if value, ok := mc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(media.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if nodes := mc.mutation.EpisodesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -484,6 +484,9 @@ func (mu *MediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if mu.mutation.AlternativeTitlesCleared() {
|
||||
_spec.ClearField(media.FieldAlternativeTitles, field.TypeJSON)
|
||||
}
|
||||
if mu.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(media.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if mu.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -1032,6 +1035,9 @@ func (muo *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error
|
||||
if muo.mutation.AlternativeTitlesCleared() {
|
||||
_spec.ClearField(media.FieldAlternativeTitles, field.TypeJSON)
|
||||
}
|
||||
if muo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(media.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if muo.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -11,8 +11,11 @@ var (
|
||||
// BlacklistsColumns holds the columns for the "blacklists" table.
|
||||
BlacklistsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}},
|
||||
{Name: "value", Type: field.TypeJSON},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}, Default: "torrent"},
|
||||
{Name: "torrent_hash", Type: field.TypeString, Nullable: true},
|
||||
{Name: "torrent_name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "media_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "notes", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
// BlacklistsTable holds the schema information for the "blacklists" table.
|
||||
@@ -35,6 +38,7 @@ var (
|
||||
{Name: "remove_completed_downloads", Type: field.TypeBool, Default: true},
|
||||
{Name: "remove_failed_downloads", Type: field.TypeBool, Default: true},
|
||||
{Name: "tags", Type: field.TypeString, Default: ""},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// DownloadClientsTable holds the schema information for the "download_clients" table.
|
||||
DownloadClientsTable = &schema.Table{
|
||||
@@ -53,6 +57,7 @@ var (
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"missing", "downloading", "downloaded"}, Default: "missing"},
|
||||
{Name: "monitored", Type: field.TypeBool, Default: false},
|
||||
{Name: "target_file", Type: field.TypeString, Nullable: true},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "media_id", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// EpisodesTable holds the schema information for the "episodes" table.
|
||||
@@ -63,7 +68,7 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "episodes_media_episodes",
|
||||
Columns: []*schema.Column{EpisodesColumns[9]},
|
||||
Columns: []*schema.Column{EpisodesColumns[10]},
|
||||
RefColumns: []*schema.Column{MediaColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -84,6 +89,7 @@ var (
|
||||
{Name: "link", Type: field.TypeString, Nullable: true},
|
||||
{Name: "hash", Type: field.TypeString, Nullable: true},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading", "seeding", "removed"}},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// HistoriesTable holds the schema information for the "histories" table.
|
||||
HistoriesTable = &schema.Table{
|
||||
@@ -114,7 +120,7 @@ var (
|
||||
{Name: "implementation", Type: field.TypeString},
|
||||
{Name: "settings", Type: field.TypeString, Nullable: true, Default: ""},
|
||||
{Name: "enable_rss", Type: field.TypeBool, Default: true},
|
||||
{Name: "priority", Type: field.TypeInt, Default: 50},
|
||||
{Name: "priority", Type: field.TypeInt, Default: 25},
|
||||
{Name: "seed_ratio", Type: field.TypeFloat32, Nullable: true, Default: 0},
|
||||
{Name: "disabled", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "tv_search", Type: field.TypeBool, Nullable: true, Default: true},
|
||||
@@ -122,6 +128,7 @@ var (
|
||||
{Name: "api_key", Type: field.TypeString, Nullable: true},
|
||||
{Name: "url", Type: field.TypeString, Nullable: true},
|
||||
{Name: "synced", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// IndexersTable holds the schema information for the "indexers" table.
|
||||
IndexersTable = &schema.Table{
|
||||
@@ -148,6 +155,7 @@ var (
|
||||
{Name: "limiter", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "extras", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "alternative_titles", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// MediaTable holds the schema information for the "media" table.
|
||||
MediaTable = &schema.Table{
|
||||
@@ -191,6 +199,7 @@ var (
|
||||
{Name: "settings", Type: field.TypeString, Nullable: true},
|
||||
{Name: "deleted", Type: field.TypeBool, Default: false},
|
||||
{Name: "default", Type: field.TypeBool, Default: false},
|
||||
{Name: "create_time", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// StoragesTable holds the schema information for the "storages" table.
|
||||
StoragesTable = &schema.Table{
|
||||
|
||||
788
ent/mutation.go
788
ent/mutation.go
File diff suppressed because it is too large
Load Diff
@@ -21,10 +21,10 @@ import (
|
||||
func init() {
|
||||
blacklistFields := schema.Blacklist{}.Fields()
|
||||
_ = blacklistFields
|
||||
// blacklistDescValue is the schema descriptor for value field.
|
||||
blacklistDescValue := blacklistFields[1].Descriptor()
|
||||
// blacklist.DefaultValue holds the default value on creation for the value field.
|
||||
blacklist.DefaultValue = blacklistDescValue.Default.(schema.BlacklistValue)
|
||||
// blacklistDescCreateTime is the schema descriptor for create_time field.
|
||||
blacklistDescCreateTime := blacklistFields[4].Descriptor()
|
||||
// blacklist.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
blacklist.DefaultCreateTime = blacklistDescCreateTime.Default.(func() time.Time)
|
||||
downloadclientsFields := schema.DownloadClients{}.Fields()
|
||||
_ = downloadclientsFields
|
||||
// downloadclientsDescUser is the schema descriptor for user field.
|
||||
@@ -57,18 +57,30 @@ func init() {
|
||||
downloadclientsDescTags := downloadclientsFields[10].Descriptor()
|
||||
// downloadclients.DefaultTags holds the default value on creation for the tags field.
|
||||
downloadclients.DefaultTags = downloadclientsDescTags.Default.(string)
|
||||
// downloadclientsDescCreateTime is the schema descriptor for create_time field.
|
||||
downloadclientsDescCreateTime := downloadclientsFields[11].Descriptor()
|
||||
// downloadclients.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
downloadclients.DefaultCreateTime = downloadclientsDescCreateTime.Default.(func() time.Time)
|
||||
episodeFields := schema.Episode{}.Fields()
|
||||
_ = episodeFields
|
||||
// episodeDescMonitored is the schema descriptor for monitored field.
|
||||
episodeDescMonitored := episodeFields[7].Descriptor()
|
||||
// episode.DefaultMonitored holds the default value on creation for the monitored field.
|
||||
episode.DefaultMonitored = episodeDescMonitored.Default.(bool)
|
||||
// episodeDescCreateTime is the schema descriptor for create_time field.
|
||||
episodeDescCreateTime := episodeFields[9].Descriptor()
|
||||
// episode.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
episode.DefaultCreateTime = episodeDescCreateTime.Default.(func() time.Time)
|
||||
historyFields := schema.History{}.Fields()
|
||||
_ = historyFields
|
||||
// historyDescSize is the schema descriptor for size field.
|
||||
historyDescSize := historyFields[6].Descriptor()
|
||||
// history.DefaultSize holds the default value on creation for the size field.
|
||||
history.DefaultSize = historyDescSize.Default.(int)
|
||||
// historyDescCreateTime is the schema descriptor for create_time field.
|
||||
historyDescCreateTime := historyFields[12].Descriptor()
|
||||
// history.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
history.DefaultCreateTime = historyDescCreateTime.Default.(func() time.Time)
|
||||
indexersFields := schema.Indexers{}.Fields()
|
||||
_ = indexersFields
|
||||
// indexersDescSettings is the schema descriptor for settings field.
|
||||
@@ -83,6 +95,8 @@ func init() {
|
||||
indexersDescPriority := indexersFields[4].Descriptor()
|
||||
// indexers.DefaultPriority holds the default value on creation for the priority field.
|
||||
indexers.DefaultPriority = indexersDescPriority.Default.(int)
|
||||
// indexers.PriorityValidator is a validator for the "priority" field. It is called by the builders before save.
|
||||
indexers.PriorityValidator = indexersDescPriority.Validators[0].(func(int) error)
|
||||
// indexersDescSeedRatio is the schema descriptor for seed_ratio field.
|
||||
indexersDescSeedRatio := indexersFields[5].Descriptor()
|
||||
// indexers.DefaultSeedRatio holds the default value on creation for the seed_ratio field.
|
||||
@@ -103,6 +117,10 @@ func init() {
|
||||
indexersDescSynced := indexersFields[11].Descriptor()
|
||||
// indexers.DefaultSynced holds the default value on creation for the synced field.
|
||||
indexers.DefaultSynced = indexersDescSynced.Default.(bool)
|
||||
// indexersDescCreateTime is the schema descriptor for create_time field.
|
||||
indexersDescCreateTime := indexersFields[12].Descriptor()
|
||||
// indexers.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
indexers.DefaultCreateTime = indexersDescCreateTime.Default.(func() time.Time)
|
||||
mediaFields := schema.Media{}.Fields()
|
||||
_ = mediaFields
|
||||
// mediaDescCreatedAt is the schema descriptor for created_at field.
|
||||
@@ -117,6 +135,10 @@ func init() {
|
||||
mediaDescDownloadHistoryEpisodes := mediaFields[12].Descriptor()
|
||||
// media.DefaultDownloadHistoryEpisodes holds the default value on creation for the download_history_episodes field.
|
||||
media.DefaultDownloadHistoryEpisodes = mediaDescDownloadHistoryEpisodes.Default.(bool)
|
||||
// mediaDescCreateTime is the schema descriptor for create_time field.
|
||||
mediaDescCreateTime := mediaFields[16].Descriptor()
|
||||
// media.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
media.DefaultCreateTime = mediaDescCreateTime.Default.(func() time.Time)
|
||||
notificationclientFields := schema.NotificationClient{}.Fields()
|
||||
_ = notificationclientFields
|
||||
// notificationclientDescEnabled is the schema descriptor for enabled field.
|
||||
@@ -133,4 +155,8 @@ func init() {
|
||||
storageDescDefault := storageFields[6].Descriptor()
|
||||
// storage.DefaultDefault holds the default value on creation for the default field.
|
||||
storage.DefaultDefault = storageDescDefault.Default.(bool)
|
||||
// storageDescCreateTime is the schema descriptor for create_time field.
|
||||
storageDescCreateTime := storageFields[7].Descriptor()
|
||||
// storage.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
storage.DefaultCreateTime = storageDescCreateTime.Default.(func() time.Time)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
@@ -13,8 +15,11 @@ type Blacklist struct {
|
||||
// Fields of the Blacklist.
|
||||
func (Blacklist) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").Values("media", "torrent"),
|
||||
field.JSON("value", BlacklistValue{}).Default(BlacklistValue{}),
|
||||
field.Enum("type").Values("media", "torrent").Default("torrent"),
|
||||
field.String("torrent_hash").Optional(),
|
||||
field.String("torrent_name").Optional(),
|
||||
field.Int("media_id").Optional(),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
field.String("notes").Optional(),
|
||||
}
|
||||
}
|
||||
@@ -23,8 +28,3 @@ func (Blacklist) Fields() []ent.Field {
|
||||
func (Blacklist) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
||||
type BlacklistValue struct {
|
||||
TmdbID int `json:"tmdb_id"`
|
||||
TorrentHash string `json:"torrent_hash"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -34,6 +35,7 @@ func (DownloadClients) Fields() []ent.Field {
|
||||
field.Bool("remove_completed_downloads").Default(true),
|
||||
field.Bool("remove_failed_downloads").Default(true),
|
||||
field.String("tags").Default(""),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -23,6 +25,7 @@ func (Episode) Fields() []ent.Field {
|
||||
field.Enum("status").Values("missing", "downloading", "downloaded").Default("missing"),
|
||||
field.Bool("monitored").Default(false).StructTag("json:\"monitored\""), //whether this episode is monitored
|
||||
field.String("target_file").Optional(),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
@@ -23,9 +25,10 @@ func (History) Fields() []ent.Field {
|
||||
field.Int("size").Default(0),
|
||||
field.Int("download_client_id").Optional(),
|
||||
field.Int("indexer_id").Optional(),
|
||||
field.String("link").Optional().Comment("deprecated, use hash instead"), //should be magnet link
|
||||
field.String("link").Optional().Comment("torrent link"), //should be magnet link
|
||||
field.String("hash").Optional().Comment("torrent hash"),
|
||||
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding", "removed"),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
//field.String("saved").Optional().Comment("deprecated"), //deprecated
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
@@ -17,7 +20,15 @@ func (Indexers) Fields() []ent.Field {
|
||||
field.String("implementation"),
|
||||
field.String("settings").Optional().Default("").Comment("deprecated, use api_key and url"),
|
||||
field.Bool("enable_rss").Default(true),
|
||||
field.Int("priority").Default(50),
|
||||
field.Int("priority").Default(25).Validate(func(i int) error {
|
||||
if i > 50 {
|
||||
return errors.ErrUnsupported
|
||||
}
|
||||
if i <= 0 {
|
||||
return errors.ErrUnsupported
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
field.Float32("seed_ratio").Optional().Default(0).Comment("minimal seed ratio requied, before removing torrent"),
|
||||
field.Bool("disabled").Optional().Default(false),
|
||||
field.Bool("tv_search").Optional().Default(true),
|
||||
@@ -25,6 +36,7 @@ func (Indexers) Fields() []ent.Field {
|
||||
field.String("api_key").Optional(),
|
||||
field.String("url").Optional(),
|
||||
field.Bool("synced").Optional().Default(false).Comment("synced from prowlarr"),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ func (Media) Fields() []ent.Field {
|
||||
field.JSON("limiter", MediaLimiter{}).Optional(),
|
||||
field.JSON("extras", MediaExtras{}).Optional(),
|
||||
field.JSON("alternative_titles", []AlternativeTilte{}).Optional(),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
@@ -20,6 +22,7 @@ func (Storage) Fields() []ent.Field {
|
||||
field.String("settings").Optional(),
|
||||
field.Bool("deleted").Default(false),
|
||||
field.Bool("default").Default(false),
|
||||
field.Time("create_time").Optional().Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"polaris/ent/storage"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -29,7 +30,9 @@ type Storage struct {
|
||||
// Deleted holds the value of the "deleted" field.
|
||||
Deleted bool `json:"deleted,omitempty"`
|
||||
// Default holds the value of the "default" field.
|
||||
Default bool `json:"default,omitempty"`
|
||||
Default bool `json:"default,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -44,6 +47,8 @@ func (*Storage) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case storage.FieldName, storage.FieldImplementation, storage.FieldTvPath, storage.FieldMoviePath, storage.FieldSettings:
|
||||
values[i] = new(sql.NullString)
|
||||
case storage.FieldCreateTime:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -107,6 +112,12 @@ func (s *Storage) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
s.Default = value.Bool
|
||||
}
|
||||
case storage.FieldCreateTime:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value.Valid {
|
||||
s.CreateTime = value.Time
|
||||
}
|
||||
default:
|
||||
s.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -163,6 +174,9 @@ func (s *Storage) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("default=")
|
||||
builder.WriteString(fmt.Sprintf("%v", s.Default))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(s.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -27,6 +28,8 @@ const (
|
||||
FieldDeleted = "deleted"
|
||||
// FieldDefault holds the string denoting the default field in the database.
|
||||
FieldDefault = "default"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// Table holds the table name of the storage in the database.
|
||||
Table = "storages"
|
||||
)
|
||||
@@ -41,6 +44,7 @@ var Columns = []string{
|
||||
FieldSettings,
|
||||
FieldDeleted,
|
||||
FieldDefault,
|
||||
FieldCreateTime,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -58,6 +62,8 @@ var (
|
||||
DefaultDeleted bool
|
||||
// DefaultDefault holds the default value on creation for the "default" field.
|
||||
DefaultDefault bool
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() time.Time
|
||||
)
|
||||
|
||||
// Implementation defines the type for the "implementation" enum field.
|
||||
@@ -126,3 +132,8 @@ func ByDeleted(opts ...sql.OrderTermOption) OrderOption {
|
||||
func ByDefault(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDefault, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package storage
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -83,6 +84,11 @@ func Default(v bool) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldEQ(FieldDefault, v))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldEQ(FieldName, v))
|
||||
@@ -413,6 +419,56 @@ func DefaultNEQ(v bool) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldNEQ(FieldDefault, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Storage {
|
||||
return predicate.Storage(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIsNil applies the IsNil predicate on the "create_time" field.
|
||||
func CreateTimeIsNil() predicate.Storage {
|
||||
return predicate.Storage(sql.FieldIsNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// CreateTimeNotNil applies the NotNil predicate on the "create_time" field.
|
||||
func CreateTimeNotNil() predicate.Storage {
|
||||
return predicate.Storage(sql.FieldNotNull(FieldCreateTime))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Storage) predicate.Storage {
|
||||
return predicate.Storage(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/storage"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -101,6 +102,20 @@ func (sc *StorageCreate) SetNillableDefault(b *bool) *StorageCreate {
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (sc *StorageCreate) SetCreateTime(t time.Time) *StorageCreate {
|
||||
sc.mutation.SetCreateTime(t)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (sc *StorageCreate) SetNillableCreateTime(t *time.Time) *StorageCreate {
|
||||
if t != nil {
|
||||
sc.SetCreateTime(*t)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// Mutation returns the StorageMutation object of the builder.
|
||||
func (sc *StorageCreate) Mutation() *StorageMutation {
|
||||
return sc.mutation
|
||||
@@ -144,6 +159,10 @@ func (sc *StorageCreate) defaults() {
|
||||
v := storage.DefaultDefault
|
||||
sc.mutation.SetDefault(v)
|
||||
}
|
||||
if _, ok := sc.mutation.CreateTime(); !ok {
|
||||
v := storage.DefaultCreateTime()
|
||||
sc.mutation.SetCreateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
@@ -219,6 +238,10 @@ func (sc *StorageCreate) createSpec() (*Storage, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
|
||||
_node.Default = value
|
||||
}
|
||||
if value, ok := sc.mutation.CreateTime(); ok {
|
||||
_spec.SetField(storage.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +227,9 @@ func (su *StorageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := su.mutation.Default(); ok {
|
||||
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
|
||||
}
|
||||
if su.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(storage.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{storage.Label}
|
||||
@@ -477,6 +480,9 @@ func (suo *StorageUpdateOne) sqlSave(ctx context.Context) (_node *Storage, err e
|
||||
if value, ok := suo.mutation.Default(); ok {
|
||||
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
|
||||
}
|
||||
if suo.mutation.CreateTimeCleared() {
|
||||
_spec.ClearField(storage.FieldCreateTime, field.TypeTime)
|
||||
}
|
||||
_node = &Storage{config: suo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
12
go.mod
12
go.mod
@@ -10,7 +10,7 @@ require (
|
||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/net v0.37.0
|
||||
golang.org/x/net v0.39.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -110,9 +110,9 @@ require (
|
||||
go.opentelemetry.io/otel v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.28.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/sync v0.13.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
golang.org/x/tools v0.32.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
@@ -166,11 +166,11 @@ require (
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.36.0
|
||||
golang.org/x/crypto v0.37.0
|
||||
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
golang.org/x/sys v0.31.0
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/sys v0.32.0
|
||||
golang.org/x/text v0.24.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
24
go.sum
24
go.sum
@@ -538,8 +538,8 @@ golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA=
|
||||
@@ -580,8 +580,8 @@ golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
||||
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -597,8 +597,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
||||
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -626,8 +626,8 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -651,8 +651,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -669,8 +669,8 @@ golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
|
||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU=
|
||||
golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"polaris/log"
|
||||
"polaris/pkg"
|
||||
"strings"
|
||||
|
||||
@@ -92,25 +91,25 @@ func (d *Downloader) Download(link, hash, dir string) (pkg.Torrent, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewTorrentFromHash(hash string, downloadDir string) (*Torrent, error) {
|
||||
cl, err := NewDownloader(downloadDir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "create downloader")
|
||||
}
|
||||
ttt := cl.cl.Torrents()
|
||||
log.Infof("all torrents: %+v", ttt)
|
||||
t, _ := cl.cl.AddTorrentInfoHash(metainfo.NewHashFromHex(hash))
|
||||
// if new {
|
||||
// return nil, fmt.Errorf("torrent not found")
|
||||
// }
|
||||
<-t.GotInfo()
|
||||
return &Torrent{
|
||||
t: t,
|
||||
cl: cl.cl,
|
||||
hash: hash,
|
||||
dir: downloadDir,
|
||||
}, nil
|
||||
}
|
||||
// func NewTorrentFromHash(hash string, downloadDir string) (*Torrent, error) {
|
||||
// cl, err := NewDownloader(downloadDir)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, "create downloader")
|
||||
// }
|
||||
// ttt := cl.cl.Torrents()
|
||||
// log.Infof("all torrents: %+v", ttt)
|
||||
// t, _ := cl.cl.AddTorrentInfoHash(metainfo.NewHashFromHex(hash))
|
||||
// // if new {
|
||||
// // return nil, fmt.Errorf("torrent not found")
|
||||
// // }
|
||||
// <-t.GotInfo()
|
||||
// return &Torrent{
|
||||
// t: t,
|
||||
// cl: cl.cl,
|
||||
// hash: hash,
|
||||
// dir: downloadDir,
|
||||
// }, nil
|
||||
// }
|
||||
|
||||
type Torrent struct {
|
||||
t *torrent.Torrent
|
||||
@@ -139,7 +138,7 @@ func (t *Torrent) Progress() (int, error) {
|
||||
if p >= 100 {
|
||||
p = 99
|
||||
}
|
||||
return 99, nil
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (t *Torrent) Stop() error {
|
||||
|
||||
@@ -66,7 +66,7 @@ func (c *Client) GetIndexers() ([]*ent.Indexers, error) {
|
||||
Disabled: !in.Enable,
|
||||
Name: in.Name,
|
||||
Implementation: "torznab",
|
||||
Priority: 128 - int(in.Priority),
|
||||
Priority: int(in.Priority),
|
||||
SeedRatio: float32(seedRatio),
|
||||
Settings: string(data),
|
||||
TvSearch: tvSearch,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"polaris/log"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/pkg/errors"
|
||||
@@ -30,6 +31,13 @@ func (l *LocalStorage) Copy(src, destDir string,walkFn WalkFn) error {
|
||||
|
||||
baseDest := filepath.Join(l.dir, destDir)
|
||||
uploadFunc := func(destPath string, destInfo fs.FileInfo, srcReader io.Reader, mimeType *mimetype.MIME) error {
|
||||
baseDir := filepath.Dir(destPath)
|
||||
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(baseDir, os.ModePerm); err != nil {
|
||||
return errors.Wrapf(err, "create dir %s", baseDir)
|
||||
}
|
||||
log.Infof("create local dir %s", baseDir)
|
||||
}
|
||||
if writer, err := os.OpenFile(destPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm); err != nil {
|
||||
return errors.Wrapf(err, "create file %s", destPath)
|
||||
} else {
|
||||
|
||||
@@ -150,7 +150,7 @@ func Search(indexer *ent.Indexers, keyWord string) ([]Result, error) {
|
||||
log.Debugf("not found in cache, need query again: %v", key)
|
||||
res, err := doRequest(req)
|
||||
if err != nil {
|
||||
cc.Set(key, nil)
|
||||
//cc.Set(key, nil)
|
||||
return nil, errors.Wrap(err, "do http request")
|
||||
}
|
||||
cacheRes = res.ToResults(indexer)
|
||||
|
||||
@@ -222,9 +222,10 @@ func isWSL() bool {
|
||||
return strings.Contains(strings.ToLower(string(releaseData)), "microsoft")
|
||||
}
|
||||
|
||||
func Link2Hash(link string) (string, error) {
|
||||
func GetRealLinkAndHash(link string) (string, string, error) {
|
||||
if strings.HasPrefix(strings.ToLower(link), "magnet:") {
|
||||
return MagnetHash(link)
|
||||
hash, err := MagnetHash(link)
|
||||
return link, hash, err
|
||||
}
|
||||
client := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
@@ -234,19 +235,19 @@ func Link2Hash(link string) (string, error) {
|
||||
|
||||
resp, err := client.Get(link)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "get link")
|
||||
return "", "", errors.Wrap(err, "get link")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 300 && resp.StatusCode < 400 {
|
||||
//redirects
|
||||
tourl := resp.Header.Get("Location")
|
||||
return Link2Hash(tourl)
|
||||
return GetRealLinkAndHash(tourl)
|
||||
}
|
||||
info, err := metainfo.Load(resp.Body)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "parse response")
|
||||
return "", "", errors.Wrap(err, "parse response")
|
||||
}
|
||||
return info.HashInfoBytes().HexString(), nil
|
||||
return link,info.HashInfoBytes().HexString(), nil
|
||||
}
|
||||
|
||||
func Link2Magnet(link string) (string, error) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"polaris/log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLink2Magnet(t *testing.T) {
|
||||
s, err := Link2Hash("https://api.m-team.io/api/rss/dlv2?useHttps=true&type=ipv6&sign=1a5174668feea2630acfd6a665f41e5c&t=1738468436&tid=901313&uid=346577")
|
||||
log.Errorf("%v", err)
|
||||
log.Infof("%v", s)
|
||||
// s, err := Link2Hash("https://api.m-team.io/api/rss/dlv2?useHttps=true&type=ipv6&sign=1a5174668feea2630acfd6a665f41e5c&t=1738468436&tid=901313&uid=346577")
|
||||
// log.Errorf("%v", err)
|
||||
// log.Infof("%v", s)
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ import (
|
||||
"fmt"
|
||||
"polaris/engine"
|
||||
"polaris/ent"
|
||||
"polaris/ent/blacklist"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/schema"
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -89,18 +86,28 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
log.Errorf("no record of id: %d", in.ID)
|
||||
return nil, nil
|
||||
}
|
||||
if in.Add2Blacklist && his.Link != "" {
|
||||
|
||||
if err := s.core.RemoveTaskAndTorrent(his.ID); err != nil {
|
||||
return nil, errors.Wrap(err, "remove torrent")
|
||||
}
|
||||
if his.Status == history.StatusSeeding {
|
||||
//seeding, will mark as complete
|
||||
log.Infof("history is now seeding, will only mark history as success: (%d) %s", his.ID, his.SourceTitle)
|
||||
if err := s.db.SetHistoryStatus(his.ID, history.StatusSuccess); err!= nil {
|
||||
return nil, errors.Wrap(err, "set status")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if in.Add2Blacklist {
|
||||
//should add to blacklist
|
||||
if err := s.addTorrent2Blacklist(his.Link); err != nil {
|
||||
if err := s.addTorrent2Blacklist(his); err != nil {
|
||||
return nil, errors.Errorf("add to blacklist: %v", err)
|
||||
} else {
|
||||
log.Infof("success add magnet link to blacklist: %v", his.Link)
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.core.RemoveTaskAndTorrent(his.ID); err != nil {
|
||||
return nil, errors.Wrap(err, "remove torrent")
|
||||
}
|
||||
err := s.db.DeleteHistory(in.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "db")
|
||||
@@ -109,9 +116,14 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
episodeIds := s.core.GetEpisodeIds(his)
|
||||
|
||||
for _, id := range episodeIds {
|
||||
ep, _ := s.db.GetEpisode(his.MediaID, his.SeasonNum, id)
|
||||
ep, err := s.db.GetEpisodeByID(id)
|
||||
if err != nil {
|
||||
log.Warnf("get episode (%d) error: %v", id, err)
|
||||
continue
|
||||
}
|
||||
if !s.db.IsEpisodeDownloadingOrDownloaded(id) && ep.Status != episode.StatusDownloaded {
|
||||
//没有正在下载中或者下载完成的任务,并且episode状态不是已经下载完成
|
||||
log.Debugf("set episode (%d) status to missing", id)
|
||||
s.db.SetEpisodeStatus(id, episode.StatusMissing)
|
||||
}
|
||||
}
|
||||
@@ -120,25 +132,33 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) addTorrent2Blacklist(link string) error {
|
||||
if link == "" {
|
||||
func (s *Server) addTorrent2Blacklist(h *ent.History) error {
|
||||
if h.Hash == "" { //没有hash,不添加
|
||||
return nil
|
||||
}
|
||||
if hash, err := utils.MagnetHash(link); err != nil {
|
||||
return err
|
||||
} else {
|
||||
item := ent.Blacklist{
|
||||
Type: blacklist.TypeTorrent,
|
||||
Value: schema.BlacklistValue{
|
||||
TorrentHash: hash,
|
||||
},
|
||||
}
|
||||
err := s.db.AddBlacklistItem(&item)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "add to db")
|
||||
}
|
||||
return s.db.AddTorrent2Blacklist(h.Hash, h.SourceTitle, h.MediaID)
|
||||
}
|
||||
|
||||
func (s *Server) GetAllBlacklistItems(c *gin.Context) (interface{}, error) {
|
||||
list, err := s.db.GetTorrentBlacklist()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "db")
|
||||
}
|
||||
return nil
|
||||
return list, nil
|
||||
}
|
||||
func (s *Server) RemoveBlacklistItem(c *gin.Context) (interface{}, error) {
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
return nil, fmt.Errorf("id is empty")
|
||||
}
|
||||
idInt, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not int: %v", id)
|
||||
}
|
||||
if err := s.db.DeleteTorrentBlacklist(idInt); err != nil {
|
||||
return nil, errors.Wrap(err, "db")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
|
||||
|
||||
@@ -28,7 +28,10 @@ func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*strin
|
||||
|
||||
r1 := res[0]
|
||||
log.Infof("found resource to download: %+v", r1)
|
||||
return s.core.DownloadEpisodeTorrent(r1, seriesId, seasonNum)
|
||||
return s.core.DownloadEpisodeTorrent(r1, engine.DownloadOptions{
|
||||
SeasonNum: seasonNum,
|
||||
MediaId: seriesId,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +123,9 @@ func (s *Server) SearchTvAndDownload(c *gin.Context) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "download")
|
||||
}
|
||||
if len(name1) == 0 {
|
||||
return nil, fmt.Errorf("no torrent found")
|
||||
}
|
||||
name = name1[0]
|
||||
}
|
||||
|
||||
@@ -154,14 +160,21 @@ func (s *Server) DownloadTorrent(c *gin.Context) (interface{}, error) {
|
||||
name = fmt.Sprintf("%v S%02d", m.OriginalName, in.Season)
|
||||
}
|
||||
res := torznab.Result{Name: name, Link: in.Link, Size: in.Size}
|
||||
return s.core.DownloadEpisodeTorrent(res, in.MediaID, in.Season)
|
||||
return s.core.DownloadEpisodeTorrent(res, engine.DownloadOptions{
|
||||
SeasonNum: in.Season,
|
||||
MediaId: in.MediaID,
|
||||
})
|
||||
}
|
||||
name := in.Name
|
||||
if name == "" {
|
||||
name = fmt.Sprintf("%v S%02dE%02d", m.OriginalName, in.Season, in.Episode)
|
||||
}
|
||||
res := torznab.Result{Name: name, Link: in.Link, Size: in.Size, IndexerId: in.IndexerId}
|
||||
return s.core.DownloadEpisodeTorrent(res, in.MediaID, in.Season, in.Episode)
|
||||
return s.core.DownloadEpisodeTorrent(res, engine.DownloadOptions{
|
||||
SeasonNum: in.Season,
|
||||
MediaId: in.MediaID,
|
||||
EpisodeNums: []int{in.Episode},
|
||||
})
|
||||
} else {
|
||||
//movie
|
||||
name := in.Name
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func NewServer(db *db.Client) *Server {
|
||||
func NewServer(db db.Database) *Server {
|
||||
r := gin.Default()
|
||||
s := &Server{
|
||||
r: r,
|
||||
@@ -36,7 +36,7 @@ func NewServer(db *db.Client) *Server {
|
||||
|
||||
type Server struct {
|
||||
r *gin.Engine
|
||||
db *db.Client
|
||||
db db.Database
|
||||
core *engine.Engine
|
||||
language string
|
||||
jwtSerect string
|
||||
@@ -86,6 +86,8 @@ func (s *Server) Serve() error {
|
||||
activity.GET("/", HttpHandler(s.GetAllActivities))
|
||||
activity.POST("/delete", HttpHandler(s.RemoveActivity))
|
||||
activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory))
|
||||
activity.GET("/blacklist", HttpHandler(s.GetAllBlacklistItems))
|
||||
activity.DELETE("/blacklist/:id", HttpHandler(s.RemoveBlacklistItem))
|
||||
//activity.GET("/torrents", HttpHandler(s.GetAllTorrents))
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nestedTabController = new TabController(length: 3, vsync: this);
|
||||
_nestedTabController = new TabController(length: 4, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -33,7 +33,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
return SelectionArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TabBar(
|
||||
@@ -54,17 +55,25 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
Tab(
|
||||
text: "历史记录",
|
||||
),
|
||||
Tab(
|
||||
text: "黑名单",
|
||||
)
|
||||
],
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
AsyncValue<List<Activity>>? activitiesWatcher;
|
||||
|
||||
if (selectedTab == 2) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.archive));
|
||||
activitiesWatcher =
|
||||
ref.watch(activitiesDataProvider(ActivityStatus.archive));
|
||||
} else if (selectedTab == 1) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.seeding));
|
||||
activitiesWatcher =
|
||||
ref.watch(activitiesDataProvider(ActivityStatus.seeding));
|
||||
} else if (selectedTab == 0) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.active));
|
||||
activitiesWatcher =
|
||||
ref.watch(activitiesDataProvider(ActivityStatus.active));
|
||||
} else if (selectedTab == 3) {
|
||||
return showBlacklistTab();
|
||||
}
|
||||
|
||||
return activitiesWatcher!.when(
|
||||
@@ -113,6 +122,14 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
color: Colors.green,
|
||||
),
|
||||
);
|
||||
} else if (ac.status == "removed") {
|
||||
return const Tooltip(
|
||||
message: "已删除",
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
//color: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double p = ac.progress == null
|
||||
@@ -134,18 +151,31 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
children: [
|
||||
Text("开始时间:${timeago.format(ac.date!)}"),
|
||||
Text("大小:${(ac.size ?? 0).readableFileSize()}"),
|
||||
ac.seedRatio > 0
|
||||
(ac.seedRatio ?? 0) > 0
|
||||
? Text("分享率:${ac.seedRatio}")
|
||||
: SizedBox()
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: selectedTab != 2
|
||||
trailing: selectedTab == 0
|
||||
? IconButton(
|
||||
tooltip: "删除任务",
|
||||
onPressed: () => onDelete()(ac.id!),
|
||||
onPressed: () =>
|
||||
showConfirmDialog(context, ac.id!),
|
||||
icon: const Icon(Icons.delete))
|
||||
: const Text("-"),
|
||||
: (selectedTab == 1
|
||||
? IconButton(
|
||||
tooltip: "完成做种",
|
||||
onPressed: () {
|
||||
var f = ref
|
||||
.read(activitiesDataProvider(
|
||||
ActivityStatus.active)
|
||||
.notifier)
|
||||
.deleteActivity(ac.id!, false);
|
||||
showLoadingWithFuture(f);
|
||||
},
|
||||
icon: const Icon(Icons.check))
|
||||
: const Text("-")),
|
||||
),
|
||||
Divider(),
|
||||
],
|
||||
@@ -157,15 +187,84 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
loading: () => const MyProgressIndicator());
|
||||
})
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
|
||||
var add2Blacklist = false;
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("确认删除"),
|
||||
content: StatefulBuilder(builder: (context, setState) {
|
||||
return CheckboxListTile(
|
||||
value: add2Blacklist,
|
||||
title: Text("加入黑名单"),
|
||||
onChanged: (v) {
|
||||
setState(
|
||||
() {
|
||||
add2Blacklist = v!;
|
||||
},
|
||||
);
|
||||
});
|
||||
}),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text("取消")),
|
||||
TextButton(
|
||||
child: const Text("确认"),
|
||||
onPressed: () {
|
||||
final f = ref
|
||||
.read(activitiesDataProvider(ActivityStatus.active)
|
||||
.notifier)
|
||||
.deleteActivity(id, add2Blacklist)
|
||||
.then((value) {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
showLoadingWithFuture(f);
|
||||
}),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Function(int) onDelete() {
|
||||
return (id) {
|
||||
final f = ref
|
||||
.read(activitiesDataProvider(ActivityStatus.active).notifier)
|
||||
.deleteActivity(id);
|
||||
showLoadingWithFuture(f);
|
||||
};
|
||||
Widget showBlacklistTab() {
|
||||
var blacklistDataWacher = ref.watch(blacklistDataProvider);
|
||||
|
||||
return blacklistDataWacher.when(
|
||||
data: (blacklists) {
|
||||
return Flexible(
|
||||
child: SelectionArea(
|
||||
child: ListView.builder(
|
||||
itemCount: blacklists.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = blacklists[index];
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: Text(item.torrentName ?? ""),
|
||||
subtitle: Opacity(
|
||||
opacity: 0.7,
|
||||
child: Text("hash: ${item.torrentHash ?? ""}")),
|
||||
trailing: IconButton(
|
||||
onPressed: () {
|
||||
final f = ref
|
||||
.read(blacklistDataProvider.notifier)
|
||||
.deleteBlacklist(item.id!)
|
||||
.then((value) {
|
||||
//Navigator.of(context).pop();
|
||||
});
|
||||
showLoadingWithFuture(f);
|
||||
},
|
||||
icon: const Icon(Icons.delete)),
|
||||
);
|
||||
})));
|
||||
},
|
||||
error: (err, trace) => PoNetworkError(err: err),
|
||||
loading: () => const MyProgressIndicator(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:ui/widgets/utils.dart' as Utils;
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
|
||||
class FFIBackend {
|
||||
final lib = DynamicLibrary.open(libname());
|
||||
|
||||
static String libname() {
|
||||
if (Utils.isDesktop()) {
|
||||
if (!kIsWeb) {
|
||||
if (Platform.isWindows) {
|
||||
return 'libpolaris.dll';
|
||||
} else if (Platform.isLinux) {
|
||||
|
||||
@@ -61,6 +61,9 @@ class APIs {
|
||||
|
||||
static final mediaSizeLimiterUrl = "$_baseUrl/api/v1/setting/limiter";
|
||||
|
||||
static final blacklistUrl = "$_baseUrl/api/v1/activity/blacklist";
|
||||
|
||||
|
||||
static const tmdbApiKey = "tmdb_api_key";
|
||||
static const downloadDirKey = "download_dir";
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import 'package:ui/providers/server_response.dart';
|
||||
var activitiesDataProvider = AsyncNotifierProvider.autoDispose
|
||||
.family<ActivityData, List<Activity>, ActivityStatus>(ActivityData.new);
|
||||
|
||||
var blacklistDataProvider = AsyncNotifierProvider.autoDispose<BlacklistData,List<Blacklist>>(BlacklistData.new);
|
||||
|
||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
(ref, arg) async {
|
||||
final dio = await APIs.getDio();
|
||||
@@ -68,11 +70,11 @@ class ActivityData
|
||||
return activities;
|
||||
}
|
||||
|
||||
Future<void> deleteActivity(int id) async {
|
||||
Future<void> deleteActivity(int id, bool add2Blacklist) async {
|
||||
final dio = APIs.getDio();
|
||||
var resp = await dio.post(APIs.activityDeleteUrl, data: {
|
||||
"id": id,
|
||||
"add_2_blacklist": false,
|
||||
"add_2_blacklist": add2Blacklist,
|
||||
});
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
@@ -82,6 +84,7 @@ class ActivityData
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Activity {
|
||||
Activity(
|
||||
{required this.id,
|
||||
@@ -107,8 +110,8 @@ class Activity {
|
||||
final String? saved;
|
||||
final int? progress;
|
||||
final int? size;
|
||||
final double seedRatio;
|
||||
final double uploadProgress;
|
||||
final double? seedRatio;
|
||||
final double? uploadProgress;
|
||||
|
||||
factory Activity.fromJson(Map<String, dynamic> json) {
|
||||
return Activity(
|
||||
@@ -116,13 +119,77 @@ class Activity {
|
||||
mediaId: json["media_id"],
|
||||
episodeId: json["episode_id"],
|
||||
sourceTitle: json["source_title"],
|
||||
date: DateTime.tryParse(json["date"] ?? ""),
|
||||
date: DateTime.tryParse(json["date"] ?? DateTime.now().toString()),
|
||||
targetDir: json["target_dir"],
|
||||
status: json["status"],
|
||||
saved: json["saved"],
|
||||
progress: json["progress"],
|
||||
seedRatio: json["seed_ratio"],
|
||||
size: json["size"],
|
||||
uploadProgress: json["upload_progress"]);
|
||||
progress: json["progress"]??0,
|
||||
seedRatio: json["seed_ratio"]??0,
|
||||
size: json["size"]??0,
|
||||
uploadProgress: json["upload_progress"]??0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BlacklistData extends AutoDisposeAsyncNotifier<List<Blacklist>> {
|
||||
@override
|
||||
FutureOr<List<Blacklist>> build() async {
|
||||
final dio = APIs.getDio();
|
||||
var resp = await dio.get(APIs.blacklistUrl);
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code!= 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
List<Blacklist> blaclklists = List.empty(growable: true);
|
||||
for (final a in sp.data as List) {
|
||||
blaclklists.add(Blacklist.fromJson(a));
|
||||
}
|
||||
return blaclklists;
|
||||
}
|
||||
|
||||
Future<void> deleteBlacklist(int id) async {
|
||||
final dio = APIs.getDio();
|
||||
var resp = await dio.delete("${APIs.blacklistUrl}/$id");
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code!= 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Blacklist {
|
||||
int? id;
|
||||
String? type;
|
||||
String? torrentHash;
|
||||
String? torrentName;
|
||||
int? mediaId;
|
||||
String? createTime;
|
||||
|
||||
Blacklist(
|
||||
{this.id,
|
||||
this.type,
|
||||
this.torrentHash,
|
||||
this.torrentName,
|
||||
this.mediaId,
|
||||
this.createTime});
|
||||
|
||||
Blacklist.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
type = json['type'];
|
||||
torrentHash = json['torrent_hash'];
|
||||
torrentName = json['torrent_name'];
|
||||
mediaId = json['media_id'];
|
||||
createTime = json['create_time'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['type'] = this.type;
|
||||
data['torrent_hash'] = this.torrentHash;
|
||||
data['torrent_name'] = this.torrentName;
|
||||
data['media_id'] = this.mediaId;
|
||||
data['create_time'] = this.createTime;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -290,6 +290,10 @@ class DownloadClient {
|
||||
data["remove_failed_downloads"] = removeFailedDownloads;
|
||||
return data;
|
||||
}
|
||||
|
||||
bool idExists() {
|
||||
return id != null && id != 0;
|
||||
}
|
||||
}
|
||||
|
||||
class StorageSettingData extends AutoDisposeAsyncNotifier<List<Storage>> {
|
||||
|
||||
@@ -68,11 +68,13 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "name",
|
||||
enabled: client.implementation != "buildin",
|
||||
decoration: const InputDecoration(labelText: "名称"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction),
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
enabled: client.implementation != "buildin",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "地址", hintText: "http://127.0.0.1:9091"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
@@ -96,6 +98,7 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
|
||||
children: [
|
||||
FormBuilderSwitch(
|
||||
name: "auth",
|
||||
enabled: client.implementation != "buildin",
|
||||
title: const Text("需要认证"),
|
||||
initialValue: _enableAuth,
|
||||
onChanged: (v) {
|
||||
@@ -162,7 +165,7 @@ class _DownloaderState extends ConsumerState<DownloaderSettings> {
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
context, title, client.id != null, body, onSubmit, onDelete);
|
||||
context, title, client.idExists() && client.implementation != "buildin", body, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showSelections() {
|
||||
|
||||
@@ -47,7 +47,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
FormBuilderTextField(
|
||||
name: "tmdb_api",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "TMDB Api Key", icon: Icon(Icons.key), helperText: "未防止被限流,可以提供自定义的 TMDB Api Key"),
|
||||
labelText: "TMDB Api Key", icon: Icon(Icons.key), helperText: "为防止被限流,可以提供自定义的 TMDB Api Key"),
|
||||
//
|
||||
),
|
||||
FormBuilderTextField(
|
||||
|
||||
@@ -178,7 +178,7 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
name: "priority",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "索引优先级",
|
||||
helperText: "取值范围1-128, 数值越大,优先级越高",
|
||||
helperText: "取值范围1-50, 数值越大,优先级越低",
|
||||
),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.positiveNumber(),
|
||||
|
||||
@@ -55,10 +55,6 @@ extension FileFormatter on num {
|
||||
}
|
||||
}
|
||||
|
||||
bool isDesktop() {
|
||||
return Platform.isLinux || Platform.isWindows || Platform.isMacOS;
|
||||
}
|
||||
|
||||
bool isSmallScreen(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return screenWidth < Breakpoints.small.endWidth!.toDouble();
|
||||
|
||||
@@ -1 +1 @@
|
||||
flutter run -d edge --no-web-resources-cdn --web-browser-flag "--disable-web-security"
|
||||
flutter run -d chrome --no-web-resources-cdn --web-browser-flag "--disable-web-security"
|
||||
Reference in New Issue
Block a user