mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-21 14:30:50 +08:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a2c67af04 | ||
|
|
3698170d0b | ||
|
|
6c38db5248 | ||
|
|
b597edab8a | ||
|
|
2e3b67dfce | ||
|
|
1dd61ccbca | ||
|
|
f5f8434832 | ||
|
|
2cb6a15c0b | ||
|
|
317f5655b8 | ||
|
|
00506df5a1 | ||
|
|
57de442eb9 | ||
|
|
690ce272c2 | ||
|
|
6a9f63fff6 | ||
|
|
7b9b619de6 | ||
|
|
8bc9076d90 | ||
|
|
891be34504 | ||
|
|
04df9adfdf | ||
|
|
3c47eba618 | ||
|
|
e85bd231c9 | ||
|
|
58e65b21fb | ||
|
|
520933085d | ||
|
|
5cc88986d2 | ||
|
|
d63a923589 | ||
|
|
bca68befb1 | ||
|
|
1be44bff9e | ||
|
|
3998270cbd | ||
|
|
73e76c2185 | ||
|
|
c72a460509 | ||
|
|
912293d8e8 | ||
|
|
7f2e84ad52 | ||
|
|
e52ad612c1 | ||
|
|
45a212fec5 | ||
|
|
39bfda4cda | ||
|
|
24a4d3152d | ||
|
|
6c6670a8c0 | ||
|
|
63fc4f277b | ||
|
|
45d2a4fb79 | ||
|
|
5e337871c9 | ||
|
|
803dcfeacd | ||
|
|
c26e61bbee | ||
|
|
e334acba32 |
@@ -25,6 +25,7 @@ COPY --from=flutter /app/build/web ./ui/build/web/
|
||||
RUN CGO_ENABLED=1 go build -o polaris ./cmd/
|
||||
|
||||
FROM debian:12
|
||||
ENV TZ="Asia/Shanghai"
|
||||
|
||||
WORKDIR /app
|
||||
RUN apt-get update && apt-get -y install ca-certificates
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.7 MiB After Width: | Height: | Size: 3.4 MiB |
@@ -6,6 +6,7 @@ const (
|
||||
SettingJacketUrl = "jacket_url"
|
||||
SettingJacketApiKey = "jacket_api_key"
|
||||
SettingDownloadDir = "download_dir"
|
||||
SettingLogLevel = "log_level"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,6 +19,7 @@ const (
|
||||
IndexerTorznabImpl = "torznab"
|
||||
DataPath = "./data"
|
||||
ImgPath = DataPath + "/img"
|
||||
LogPath = DataPath + "/logs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
53
db/db.go
53
db/db.go
@@ -42,6 +42,7 @@ func Open() (*Client, error) {
|
||||
c := &Client{
|
||||
ent: client,
|
||||
}
|
||||
c.init()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
@@ -57,6 +58,11 @@ func (c *Client) init() {
|
||||
log.Infof("set default download dir")
|
||||
c.SetSetting(downloadDir, "/downloads")
|
||||
}
|
||||
logLevel := c.GetSetting(SettingLogLevel)
|
||||
if logLevel == "" {
|
||||
log.Infof("set default log level")
|
||||
c.SetSetting(SettingLogLevel, "info")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) generateJwtSerectIfNotExist() {
|
||||
@@ -162,6 +168,10 @@ 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 {
|
||||
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).SetAirDate(airdate).Exec(context.TODO())
|
||||
}
|
||||
|
||||
type MediaDetails struct {
|
||||
*ent.Media
|
||||
Episodes []*ent.Episode `json:"episodes"`
|
||||
@@ -207,6 +217,19 @@ func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
|
||||
return ep.ID, err
|
||||
}
|
||||
|
||||
func (c *Client) SaveEposideDetail2(d *ent.Episode) (int, error) {
|
||||
ep, err := c.ent.Episode.Create().
|
||||
SetAirDate(d.AirDate).
|
||||
SetSeasonNumber(d.SeasonNumber).
|
||||
SetEpisodeNumber(d.EpisodeNumber).
|
||||
SetMediaID(d.MediaID).
|
||||
SetStatus(d.Status).
|
||||
SetOverview(d.Overview).
|
||||
SetTitle(d.Title).Save(context.TODO())
|
||||
|
||||
return ep.ID, err
|
||||
}
|
||||
|
||||
type TorznabSetting struct {
|
||||
URL string `json:"url"`
|
||||
ApiKey string `json:"api_key"`
|
||||
@@ -299,9 +322,9 @@ func (c *Client) DeleteDownloadCLient(id int) {
|
||||
|
||||
// Storage is the model entity for the Storage schema.
|
||||
type StorageInfo struct {
|
||||
Name string `json:"name"`
|
||||
Implementation string `json:"implementation"`
|
||||
Settings map[string]string `json:"settings"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
Implementation string `json:"implementation" binding:"required"`
|
||||
Settings map[string]string `json:"settings" binding:"required"`
|
||||
Default bool `json:"default"`
|
||||
}
|
||||
|
||||
@@ -310,16 +333,15 @@ func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
|
||||
panic("not webdav storage")
|
||||
}
|
||||
return WebdavSetting{
|
||||
URL: s.Settings["url"],
|
||||
TvPath: s.Settings["tv_path"],
|
||||
MoviePath: s.Settings["movie_path"],
|
||||
User: s.Settings["user"],
|
||||
Password: s.Settings["password"],
|
||||
URL: s.Settings["url"],
|
||||
TvPath: s.Settings["tv_path"],
|
||||
MoviePath: s.Settings["movie_path"],
|
||||
User: s.Settings["user"],
|
||||
Password: s.Settings["password"],
|
||||
ChangeFileHash: s.Settings["change_file_hash"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type LocalDirSetting struct {
|
||||
TvPath string `json:"tv_path"`
|
||||
MoviePath string `json:"movie_path"`
|
||||
@@ -501,7 +523,18 @@ 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) {
|
||||
return c.ent.History.Query().Where(history.MediaID(mediaID)).All(context.TODO())
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
ep, err := c.ent.Episode.Query().Where(episode.MediaID(movieId)).First(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "query episode")
|
||||
}
|
||||
return ep, nil
|
||||
}
|
||||
@@ -21,7 +21,6 @@ func (Episode) Fields() []ent.Field {
|
||||
field.String("overview"),
|
||||
field.String("air_date"),
|
||||
field.Enum("status").Values("missing", "downloading", "downloaded").Default("missing"),
|
||||
field.String("file_in_storage").Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
go.mod
14
go.mod
@@ -11,7 +11,12 @@ require (
|
||||
golang.org/x/net v0.25.0
|
||||
)
|
||||
|
||||
require github.com/adrg/strutil v0.3.1 // indirect
|
||||
require github.com/adrg/strutil v0.3.1
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/zap v1.1.3 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect
|
||||
@@ -56,9 +61,9 @@ require (
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.23.0
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/sys v0.21.0
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
@@ -72,7 +77,8 @@ require (
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/spf13/viper v1.19.0
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
)
|
||||
|
||||
18
go.sum
18
go.sum
@@ -34,6 +34,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-contrib/static v1.1.2 h1:c3kT4bFkUJn2aoRU3s6XnMjJT8J6nNWJkR0NglqmlZ4=
|
||||
github.com/gin-contrib/static v1.1.2/go.mod h1:Fw90ozjHCmZBWbgrsqrDvO28YbhKEKzKp8GixhR4yLw=
|
||||
github.com/gin-contrib/zap v1.1.3 h1:9e/U9fYd4/OBfmSEBs5hHZq114uACn7bpuzvCkcJySA=
|
||||
github.com/gin-contrib/zap v1.1.3/go.mod h1:+BD/6NYZKJyUpqVoJEvgeq9GLz8pINEQvak9LHNOTSE=
|
||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
|
||||
@@ -91,8 +93,6 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||
@@ -104,8 +104,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
@@ -129,8 +129,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
|
||||
@@ -161,6 +159,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
@@ -177,8 +177,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -190,8 +188,6 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
@@ -201,6 +197,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
47
log/log.go
47
log/log.go
@@ -1,18 +1,57 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var sugar *zap.SugaredLogger
|
||||
var atom zap.AtomicLevel
|
||||
|
||||
const dataPath = "./data"
|
||||
|
||||
func init() {
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
config.DisableStacktrace = true
|
||||
logger, _ := config.Build(zap.AddCallerSkip(1))
|
||||
atom = zap.NewAtomicLevel()
|
||||
atom.SetLevel(zap.DebugLevel)
|
||||
|
||||
w := zapcore.AddSync(&lumberjack.Logger{
|
||||
Filename: filepath.Join(dataPath, "logs", "polaris.log"),
|
||||
MaxSize: 50, // megabytes
|
||||
MaxBackups: 3,
|
||||
MaxAge: 30, // days
|
||||
})
|
||||
|
||||
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
|
||||
|
||||
logger := zap.New(zapcore.NewCore(consoleEncoder, w, atom), zap.AddCallerSkip(1))
|
||||
|
||||
sugar = logger.Sugar()
|
||||
|
||||
}
|
||||
|
||||
func SetLogLevel(l string) {
|
||||
switch strings.TrimSpace(strings.ToLower(l)) {
|
||||
case "debug":
|
||||
atom.SetLevel(zap.DebugLevel)
|
||||
Debug("set log level to debug")
|
||||
case "info":
|
||||
atom.SetLevel(zap.InfoLevel)
|
||||
Info("set log level to info")
|
||||
case "warn", "warnning":
|
||||
atom.SetLevel(zap.WarnLevel)
|
||||
Warn("set log level to warnning")
|
||||
case "error":
|
||||
atom.SetLevel(zap.ErrorLevel)
|
||||
Error("set log level to error")
|
||||
}
|
||||
}
|
||||
|
||||
func Logger() *zap.SugaredLogger {
|
||||
return sugar
|
||||
}
|
||||
|
||||
func Info(args ...interface{}) {
|
||||
|
||||
@@ -15,6 +15,7 @@ type MovieMetadata struct {
|
||||
}
|
||||
|
||||
func ParseMovie(name string) *MovieMetadata {
|
||||
name = strings.Join(strings.Fields(name), " ") //remove unnessary spaces
|
||||
name = strings.ToLower(strings.TrimSpace(name))
|
||||
var meta = &MovieMetadata{}
|
||||
yearRe := regexp.MustCompile(`\(\d{4}\)`)
|
||||
|
||||
@@ -19,6 +19,7 @@ type Metadata struct {
|
||||
|
||||
func ParseTv(name string) *Metadata {
|
||||
name = strings.ToLower(name)
|
||||
name = strings.ReplaceAll(name, "\u200b", "") //remove unicode hidden character
|
||||
if utils.ContainsChineseChar(name) {
|
||||
return parseChineseName(name)
|
||||
}
|
||||
@@ -27,7 +28,7 @@ func ParseTv(name string) *Metadata {
|
||||
|
||||
func parseEnglishName(name string) *Metadata {
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
name = re.ReplaceAllString(strings.ToLower(name), "")
|
||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||
|
||||
splits := strings.Split(strings.TrimSpace(name), " ")
|
||||
var newSplits []string
|
||||
@@ -68,11 +69,6 @@ func parseEnglishName(name string) *Metadata {
|
||||
}
|
||||
if seasonIndex != -1 {
|
||||
//season exists
|
||||
if seasonIndex != 0 {
|
||||
//name exists
|
||||
names := newSplits[0:seasonIndex]
|
||||
meta.NameEn = strings.Join(names, " ")
|
||||
}
|
||||
ss := seasonRe.FindAllString(newSplits[seasonIndex], -1)
|
||||
if len(ss) != 0 {
|
||||
//season info
|
||||
@@ -84,6 +80,24 @@ func parseEnglishName(name string) *Metadata {
|
||||
}
|
||||
meta.Season = n
|
||||
}
|
||||
} else { //maybe like Season 1?
|
||||
seasonRe := regexp.MustCompile(`season \d{1,2}`)
|
||||
matches := seasonRe.FindAllString(name, -1)
|
||||
if len(matches) > 0 {
|
||||
for i, s := range newSplits {
|
||||
if s == "season" {
|
||||
seasonIndex = i
|
||||
}
|
||||
}
|
||||
numRe := regexp.MustCompile(`\d{1,2}`)
|
||||
seNum := numRe.FindAllString(matches[0], -1)[0]
|
||||
n, err := strconv.Atoi(seNum)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", seNum, err))
|
||||
}
|
||||
meta.Season = n
|
||||
|
||||
}
|
||||
}
|
||||
if episodeIndex != -1 {
|
||||
ep := episodeRe.FindAllString(newSplits[episodeIndex], -1)
|
||||
@@ -96,14 +110,46 @@ func parseEnglishName(name string) *Metadata {
|
||||
}
|
||||
meta.Episode = n
|
||||
}
|
||||
} else { //no episode, maybe like One Punch Man S2 - 08 [1080p].mkv
|
||||
|
||||
numRe := regexp.MustCompile(`^\d{1,2}$`)
|
||||
for i, p := range newSplits {
|
||||
if numRe.MatchString(p) {
|
||||
if i > 0 && strings.Contains(newSplits[i-1], "season") { //last word cannot be season
|
||||
continue
|
||||
}
|
||||
if i < seasonIndex {
|
||||
//episode number most likely should comes alfter season number
|
||||
continue
|
||||
}
|
||||
//episodeIndex = i
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("convert %s error: %v", p, err))
|
||||
}
|
||||
meta.Episode = n
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if resIndex != -1 {
|
||||
//resolution exists
|
||||
meta.Resolution = newSplits[resIndex]
|
||||
}
|
||||
if meta.Episode == -1 {
|
||||
if meta.Episode == -1 || strings.Contains(name, "complete") {
|
||||
meta.Episode = -1
|
||||
meta.IsSeasonPack = true
|
||||
}
|
||||
|
||||
if seasonIndex > 0 {
|
||||
//name exists
|
||||
names := newSplits[0:seasonIndex]
|
||||
meta.NameEn = strings.TrimSpace(strings.Join(names, " "))
|
||||
} else {
|
||||
meta.NameEn = name
|
||||
}
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
@@ -141,10 +187,10 @@ func parseChineseName(name string) *Metadata {
|
||||
}
|
||||
meta.Episode = n
|
||||
} else { //【第09話】
|
||||
re2 := regexp.MustCompile(`第\d{1,2}(话|話|集)`)
|
||||
re2 := regexp.MustCompile(`第\d{1,4}(话|話|集)`)
|
||||
episodeMatches1 := re2.FindAllString(name, -1)
|
||||
if len(episodeMatches1) > 0 {
|
||||
re := regexp.MustCompile(`\d{1,2}`)
|
||||
re := regexp.MustCompile(`\d{1,4}`)
|
||||
epNum := re.FindAllString(episodeMatches1[0], -1)[0]
|
||||
n, err := strconv.Atoi(epNum)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,6 +28,9 @@ func NewClient(apiKey string) (*Client, error) {
|
||||
|
||||
func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error) {
|
||||
d, err := c.tmdbClient.GetTVDetails(id, withLangOption(language))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get tv detail")
|
||||
}
|
||||
|
||||
log.Infof("tv id %d, language %s", id, language)
|
||||
if !episodeNameUseful(d.LastEpisodeToAir.Name) {
|
||||
@@ -38,13 +41,12 @@ func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error)
|
||||
if err != nil {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
}
|
||||
if episodeNameUseful(detailEN.LastEpisodeToAir.Name) {
|
||||
d.LastEpisodeToAir.Name = detailEN.LastEpisodeToAir.Name
|
||||
d.LastEpisodeToAir.Overview = detailEN.LastEpisodeToAir.Overview
|
||||
d.NextEpisodeToAir.Name = detailEN.NextEpisodeToAir.Name
|
||||
d.NextEpisodeToAir.Overview = detailEN.NextEpisodeToAir.Overview
|
||||
if episodeNameUseful(detailEN.LastEpisodeToAir.Name) {
|
||||
d.LastEpisodeToAir.Name = detailEN.LastEpisodeToAir.Name
|
||||
d.LastEpisodeToAir.Overview = detailEN.LastEpisodeToAir.Overview
|
||||
d.NextEpisodeToAir.Name = detailEN.NextEpisodeToAir.Name
|
||||
d.NextEpisodeToAir.Overview = detailEN.NextEpisodeToAir.Overview
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ func NewClient(c Config) (*Client, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
_, err = tbt.TorrentGetAll(context.TODO())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "transmission cannot connect")
|
||||
}
|
||||
return &Client{c: tbt, cfg: c}, nil
|
||||
}
|
||||
|
||||
|
||||
13
pkg/uptime/uptime.go
Normal file
13
pkg/uptime/uptime.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package uptime
|
||||
|
||||
import "time"
|
||||
|
||||
var startTime time.Time
|
||||
|
||||
func Uptime() time.Duration {
|
||||
return time.Since(startTime)
|
||||
}
|
||||
|
||||
func init() {
|
||||
startTime = time.Now()
|
||||
}
|
||||
@@ -57,10 +57,14 @@ func RandString(n int) string {
|
||||
}
|
||||
|
||||
func IsNameAcceptable(name1, name2 string) bool {
|
||||
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
name1 = re.ReplaceAllString(strings.ToLower(name1), "")
|
||||
name2 = re.ReplaceAllString(strings.ToLower(name2), "")
|
||||
name1 = re.ReplaceAllString(strings.ToLower(name1), " ")
|
||||
name2 = re.ReplaceAllString(strings.ToLower(name2), " ")
|
||||
name1 = strings.Join(strings.Fields(name1), " ")
|
||||
name2 = strings.Join(strings.Fields(name2), " ")
|
||||
if strings.Contains(name1, name2) || strings.Contains(name2, name1) {
|
||||
return true
|
||||
}
|
||||
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.4
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func HttpHandler(f func(*gin.Context) (interface{}, error)) gin.HandlerFunc {
|
||||
})
|
||||
return
|
||||
}
|
||||
//log.Infof("url %v return: %+v", ctx.Request.URL, r)
|
||||
log.Debug("url %v return: %+v", ctx.Request.URL, r)
|
||||
|
||||
ctx.JSON(200, Response{
|
||||
Code: 0,
|
||||
|
||||
@@ -19,6 +19,21 @@ func SearchSeasonPackage(db1 *db.Client, seriesId, seasonNum int, checkResolutio
|
||||
return SearchEpisode(db1, seriesId, seasonNum, -1, checkResolution)
|
||||
}
|
||||
|
||||
func isNumberedSeries(detail *db.MediaDetails) bool {
|
||||
hasSeason2 := false
|
||||
season2HasEpisode1 := false
|
||||
for _, ep := range detail.Episodes {
|
||||
if ep.SeasonNumber == 2 {
|
||||
hasSeason2 = true
|
||||
if ep.EpisodeNumber == 1 {
|
||||
season2HasEpisode1 = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return hasSeason2 && !season2HasEpisode1//only one 1st episode
|
||||
}
|
||||
|
||||
func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(seriesId)
|
||||
if series == nil {
|
||||
@@ -36,10 +51,19 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
|
||||
if meta == nil { //cannot parse name
|
||||
continue
|
||||
}
|
||||
if meta.Season != seasonNum {
|
||||
if !isNumberedSeries(series) { //do not check season on series that only rely on episode number
|
||||
if meta.Season != seasonNum {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if isNumberedSeries(series) && episodeNum == -1 {
|
||||
//should not want season
|
||||
continue
|
||||
}
|
||||
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack
|
||||
|
||||
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack, episode number equals
|
||||
continue
|
||||
} else if seasonNum == -1 && !meta.IsSeasonPack { //want season pack, but not season pack
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != series.Resolution.String() {
|
||||
@@ -86,6 +110,10 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
|
||||
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
|
||||
continue
|
||||
}
|
||||
if utils.ContainsIgnoreCase(r.Name, "soundtrack") {
|
||||
//ignore soundtracks
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
"polaris/log"
|
||||
"polaris/pkg/transmission"
|
||||
"polaris/pkg/utils"
|
||||
"polaris/server/core"
|
||||
"strconv"
|
||||
@@ -16,58 +14,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type addTorznabIn struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
ApiKey string `json:"api_key"`
|
||||
}
|
||||
|
||||
func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
var in addTorznabIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
err := s.db.SaveTorznabInfo(in.Name, db.TorznabSetting{
|
||||
URL: in.URL,
|
||||
ApiKey: in.ApiKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add ")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) DeleteTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
var ids = c.Param("id")
|
||||
id, err := strconv.Atoi(ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not correct: %v", ids)
|
||||
}
|
||||
s.db.DeleteTorznab(id)
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
func (s *Server) GetAllIndexers(c *gin.Context) (interface{}, error) {
|
||||
indexers := s.db.GetAllTorznabInfo()
|
||||
if len(indexers) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return indexers, nil
|
||||
}
|
||||
|
||||
func (s *Server) getDownloadClient() (*transmission.Client, error) {
|
||||
tr := s.db.GetTransmission()
|
||||
trc, err := transmission.NewClient(transmission.Config{
|
||||
URL: tr.URL,
|
||||
User: tr.User,
|
||||
Password: tr.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
return trc, nil
|
||||
}
|
||||
|
||||
func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*string, error) {
|
||||
trc, err := s.getDownloadClient()
|
||||
if err != nil {
|
||||
@@ -239,6 +185,7 @@ type TorznabSearchResult struct {
|
||||
Link string `json:"link"`
|
||||
Seeders int `json:"seeders"`
|
||||
Peers int `json:"peers"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
@@ -248,11 +195,6 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "convert")
|
||||
}
|
||||
|
||||
movieDetail := s.db.GetMediaDetails(id)
|
||||
if movieDetail == nil {
|
||||
return nil, errors.New("no media found of id " + ids)
|
||||
}
|
||||
|
||||
res, err := core.SearchMovie(s.db, id, false)
|
||||
if err != nil {
|
||||
if err.Error() == "no resource found" {
|
||||
@@ -269,6 +211,7 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
Seeders: r.Seeders,
|
||||
Peers: r.Peers,
|
||||
Link: r.Link,
|
||||
Source: r.Source,
|
||||
})
|
||||
}
|
||||
if len(searchResults) == 0 {
|
||||
@@ -278,7 +221,7 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
|
||||
type downloadTorrentIn struct {
|
||||
MediaID int `json:"media_id" binding:"required"`
|
||||
MediaID int `json:"media_id" binding:"required"`
|
||||
TorznabSearchResult
|
||||
}
|
||||
|
||||
@@ -303,13 +246,16 @@ func (s *Server) DownloadMovieTorrent(c *gin.Context) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "downloading")
|
||||
}
|
||||
torrent.Start()
|
||||
|
||||
name := in.Name
|
||||
if name == "" {
|
||||
name = media.OriginalName
|
||||
}
|
||||
go func() {
|
||||
ep := media.Episodes[0]
|
||||
history, err := s.db.SaveHistoryRecord(ent.History{
|
||||
MediaID: media.ID,
|
||||
EpisodeID: ep.ID,
|
||||
SourceTitle: media.NameCn,
|
||||
SourceTitle: name,
|
||||
TargetDir: "./",
|
||||
Status: history.StatusRunning,
|
||||
Size: in.Size,
|
||||
@@ -328,40 +274,3 @@ func (s *Server) DownloadMovieTorrent(c *gin.Context) (interface{}, error) {
|
||||
return media.NameEn, nil
|
||||
|
||||
}
|
||||
|
||||
type downloadClientIn struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Implementation string `json:"implementation"`
|
||||
}
|
||||
|
||||
func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
|
||||
var in downloadClientIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
if err := s.db.SaveTransmission(in.Name, in.URL, in.User, in.Password); err != nil {
|
||||
return nil, errors.Wrap(err, "save transmission")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetAllDonloadClients(c *gin.Context) (interface{}, error) {
|
||||
res := s.db.GetAllDonloadClients()
|
||||
if len(res) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Server) DeleteDownloadCLient(c *gin.Context) (interface{}, error) {
|
||||
var ids = c.Param("id")
|
||||
id, err := strconv.Atoi(ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not correct: %v", ids)
|
||||
}
|
||||
s.db.DeleteDownloadCLient(id)
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ func (s *Server) scheduler() {
|
||||
s.downloadTvSeries()
|
||||
s.downloadMovie()
|
||||
})
|
||||
s.mustAddCron("@every 12h", s.checkAllSeriesNewSeason)
|
||||
s.cron.Start()
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ func (s *Server) mustAddCron(spec string, cmd func()) {
|
||||
}
|
||||
|
||||
func (s *Server) checkTasks() {
|
||||
log.Infof("begin check tasks...")
|
||||
log.Debug("begin check tasks...")
|
||||
for id, t := range s.tasks {
|
||||
if !t.Exists() {
|
||||
log.Infof("task no longer exists: %v", id)
|
||||
@@ -212,50 +213,27 @@ func (s *Server) downloadTvSeries() {
|
||||
log.Infof("begin check all tv series resources")
|
||||
allSeries := s.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||
for _, series := range allSeries {
|
||||
detail, err := s.MustTMDB().GetTvDetails(series.TmdbID, s.language)
|
||||
if err != nil {
|
||||
log.Errorf("get tv details error: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
lastEpisode, err := s.db.GetEpisode(series.ID, detail.LastEpisodeToAir.SeasonNumber, detail.LastEpisodeToAir.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Errorf("get last episode error: %v", err)
|
||||
continue
|
||||
}
|
||||
if lastEpisode.Title != detail.LastEpisodeToAir.Name {
|
||||
s.db.UpdateEpiode(lastEpisode.ID, detail.LastEpisodeToAir.Name, detail.LastEpisodeToAir.Overview)
|
||||
}
|
||||
|
||||
nextEpisode, err := s.db.GetEpisode(series.ID, detail.NextEpisodeToAir.SeasonNumber, detail.NextEpisodeToAir.EpisodeNumber)
|
||||
if err == nil {
|
||||
if nextEpisode.Title != detail.NextEpisodeToAir.Name {
|
||||
s.db.UpdateEpiode(nextEpisode.ID, detail.NextEpisodeToAir.Name, detail.NextEpisodeToAir.Overview)
|
||||
log.Errorf("updated next episode name to %v", detail.NextEpisodeToAir.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if lastEpisode.Status == episode.StatusMissing {
|
||||
if lastEpisode.AirDate != "" {
|
||||
t, err := time.ParseInLocation("2006-01-02", lastEpisode.AirDate, time.Local)
|
||||
if err != nil {
|
||||
log.Errorf("parse air date error: airdate %v, error %v",lastEpisode.AirDate, err)
|
||||
} else {
|
||||
if series.CreatedAt.Sub(t) > 24*time.Hour { //24h容错时间
|
||||
log.Infof("episode were aired 24h before monitoring, skipping: %v", lastEpisode.Title)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
name, err := s.searchAndDownload(series.ID, lastEpisode.SeasonNumber, lastEpisode.EpisodeNumber)
|
||||
tvDetail := s.db.GetMediaDetails(series.ID)
|
||||
for _, ep := range tvDetail.Episodes {
|
||||
t, err := time.Parse("2006-01-02", ep.AirDate)
|
||||
if err != nil {
|
||||
log.Infof("cannot find resource to download for %s: %v", lastEpisode.Title, err)
|
||||
log.Error("air date not known, skip: %v", ep.Title)
|
||||
continue
|
||||
}
|
||||
if series.CreatedAt.Sub(t) > 24*time.Hour { //剧集在加入watchlist之前,不去下载
|
||||
continue
|
||||
}
|
||||
if ep.Status != episode.StatusMissing { //已经下载的不去下载
|
||||
continue
|
||||
}
|
||||
name, err := s.searchAndDownload(series.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Infof("cannot find resource to download for %s: %v", ep.Title, err)
|
||||
} else {
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -318,3 +296,51 @@ func (s *Server) downloadMovieSingleEpisode(ep *ent.Episode) error {
|
||||
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) checkAllSeriesNewSeason() {
|
||||
log.Infof("begin checking series all new season")
|
||||
allSeries := s.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||
for _, series := range allSeries {
|
||||
err := s.checkSeiesNewSeason(series)
|
||||
if err != nil {
|
||||
log.Errorf("check series new season error: series name %v, error: %v", series.NameEn, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) checkSeiesNewSeason(media *ent.Media) error{
|
||||
d, err := s.MustTMDB().GetTvDetails(media.TmdbID, s.language)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tmdb")
|
||||
}
|
||||
lastsSason := d.NumberOfSeasons
|
||||
seasonDetail, err := s.MustTMDB().GetSeasonDetails(media.TmdbID, lastsSason, s.language)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tmdb season")
|
||||
}
|
||||
|
||||
for _, ep := range seasonDetail.Episodes {
|
||||
epDb, err := s.db.GetEpisode(media.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
log.Infof("add new episode: %+v", ep)
|
||||
episode := &ent.Episode{
|
||||
MediaID: media.ID,
|
||||
SeasonNumber: ep.SeasonNumber,
|
||||
EpisodeNumber: ep.EpisodeNumber,
|
||||
Title: ep.Name,
|
||||
Overview: ep.Overview,
|
||||
AirDate: ep.AirDate,
|
||||
Status: episode.StatusMissing,
|
||||
}
|
||||
s.db.SaveEposideDetail2(episode)
|
||||
}
|
||||
} else {//update episode
|
||||
if ep.Name != epDb.Title || ep.Overview != epDb.Overview || ep.AirDate != epDb.AirDate {
|
||||
log.Infof("update new episode: %+v", ep)
|
||||
s.db.UpdateEpiode2(epDb.ID, ep.Name, ep.Overview, ep.AirDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -10,6 +10,9 @@ import (
|
||||
"polaris/pkg/tmdb"
|
||||
"polaris/pkg/transmission"
|
||||
"polaris/ui"
|
||||
"time"
|
||||
|
||||
ginzap "github.com/gin-contrib/zap"
|
||||
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/robfig/cron"
|
||||
@@ -43,12 +46,17 @@ func (s *Server) Serve() error {
|
||||
s.jwtSerect = s.db.GetSetting(db.JwtSerectKey)
|
||||
//st, _ := fs.Sub(ui.Web, "build/web")
|
||||
s.r.Use(static.Serve("/", static.EmbedFolder(ui.Web, "build/web")))
|
||||
s.r.Use(ginzap.Ginzap(log.Logger().Desugar(), time.RFC3339, false))
|
||||
s.r.Use(ginzap.RecoveryWithZap(log.Logger().Desugar(), true))
|
||||
|
||||
log.SetLogLevel(s.db.GetSetting(db.SettingLogLevel)) //restore log level
|
||||
|
||||
s.r.POST("/api/login", HttpHandler(s.Login))
|
||||
|
||||
api := s.r.Group("/api/v1")
|
||||
api.Use(s.authModdleware)
|
||||
api.StaticFS("/img", http.Dir(db.ImgPath))
|
||||
api.StaticFS("/logs", http.Dir(db.LogPath))
|
||||
api.Any("/posters/*proxyPath", s.proxyPosters)
|
||||
|
||||
setting := api.Group("/setting")
|
||||
@@ -57,6 +65,8 @@ func (s *Server) Serve() error {
|
||||
setting.GET("/general", HttpHandler(s.GetSetting))
|
||||
setting.POST("/auth", HttpHandler(s.EnableAuth))
|
||||
setting.GET("/auth", HttpHandler(s.GetAuthSetting))
|
||||
setting.GET("/logfiles", HttpHandler(s.GetAllLogs))
|
||||
setting.GET("/about", HttpHandler(s.About))
|
||||
}
|
||||
activity := api.Group("/activity")
|
||||
{
|
||||
@@ -146,7 +156,7 @@ func (s *Server) proxyPosters(c *gin.Context) {
|
||||
req.Host = remote.Host
|
||||
req.URL.Scheme = remote.Scheme
|
||||
req.URL.Host = remote.Host
|
||||
req.URL.Path = fmt.Sprintf("/t/p/w500/%v", c.Param("proxyPath"))
|
||||
req.URL.Path = fmt.Sprintf("/t/p/w500/%v", c.Param("proxyPath"))
|
||||
}
|
||||
proxy.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/transmission"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
||||
type GeneralSettings struct {
|
||||
TmdbApiKey string `json:"tmdb_api_key"`
|
||||
TmdbApiKey string `json:"tmdb_api_key"`
|
||||
DownloadDir string `json:"download_dir"`
|
||||
LogLevel string `json:"log_level"`
|
||||
}
|
||||
|
||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
var in GeneralSettings
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
@@ -29,15 +33,121 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "save download dir")
|
||||
}
|
||||
}
|
||||
if in.LogLevel != "" {
|
||||
log.SetLogLevel(in.LogLevel)
|
||||
if err := s.db.SetSetting(db.SettingLogLevel, in.LogLevel); err != nil {
|
||||
return nil, errors.Wrap(err, "save log level")
|
||||
}
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
tmdb := s.db.GetSetting(db.SettingTmdbApiKey)
|
||||
downloadDir := s.db.GetSetting(db.SettingDownloadDir)
|
||||
|
||||
logLevel := s.db.GetSetting(db.SettingLogLevel)
|
||||
return &GeneralSettings{
|
||||
TmdbApiKey: tmdb,
|
||||
TmdbApiKey: tmdb,
|
||||
DownloadDir: downloadDir,
|
||||
LogLevel: logLevel,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type addTorznabIn struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
URL string `json:"url" binding:"required"`
|
||||
ApiKey string `json:"api_key" binding:"required"`
|
||||
}
|
||||
|
||||
func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
var in addTorznabIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
err := s.db.SaveTorznabInfo(in.Name, db.TorznabSetting{
|
||||
URL: in.URL,
|
||||
ApiKey: in.ApiKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add ")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) DeleteTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
var ids = c.Param("id")
|
||||
id, err := strconv.Atoi(ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not correct: %v", ids)
|
||||
}
|
||||
s.db.DeleteTorznab(id)
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
func (s *Server) GetAllIndexers(c *gin.Context) (interface{}, error) {
|
||||
indexers := s.db.GetAllTorznabInfo()
|
||||
if len(indexers) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return indexers, nil
|
||||
}
|
||||
|
||||
func (s *Server) getDownloadClient() (*transmission.Client, error) {
|
||||
tr := s.db.GetTransmission()
|
||||
trc, err := transmission.NewClient(transmission.Config{
|
||||
URL: tr.URL,
|
||||
User: tr.User,
|
||||
Password: tr.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
return trc, nil
|
||||
}
|
||||
|
||||
type downloadClientIn struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
URL string `json:"url" binding:"required"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Implementation string `json:"implementation" binding:"required"`
|
||||
}
|
||||
|
||||
func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
|
||||
var in downloadClientIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
//test connection
|
||||
_, err := transmission.NewClient(transmission.Config{
|
||||
URL: in.URL,
|
||||
User: in.User,
|
||||
Password: in.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "tranmission setting")
|
||||
}
|
||||
if err := s.db.SaveTransmission(in.Name, in.URL, in.User, in.Password); err != nil {
|
||||
return nil, errors.Wrap(err, "save transmission")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetAllDonloadClients(c *gin.Context) (interface{}, error) {
|
||||
res := s.db.GetAllDonloadClients()
|
||||
if len(res) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Server) DeleteDownloadCLient(c *gin.Context) (interface{}, error) {
|
||||
var ids = c.Param("id")
|
||||
id, err := strconv.Atoi(ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("id is not correct: %v", ids)
|
||||
}
|
||||
s.db.DeleteDownloadCLient(id)
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
52
server/systems.go
Normal file
52
server/systems.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"os"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/uptime"
|
||||
"runtime"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type LogFile struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func (s *Server) GetAllLogs(c *gin.Context) (interface{}, error) {
|
||||
fs, err := os.ReadDir(db.LogPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "read log dir")
|
||||
}
|
||||
var logs []LogFile
|
||||
for _, f := range fs {
|
||||
if f.IsDir() {
|
||||
continue
|
||||
}
|
||||
info, err := f.Info()
|
||||
if err != nil {
|
||||
log.Warnf("get log file error: %v", err)
|
||||
continue
|
||||
}
|
||||
l := LogFile{
|
||||
Name: f.Name(),
|
||||
Size: info.Size(),
|
||||
}
|
||||
logs = append(logs, l)
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
func (s *Server) About(c *gin.Context) (interface{}, error) {
|
||||
|
||||
return gin.H{
|
||||
"intro": "Polaris © Simon Ding",
|
||||
"homepage": "https://github.com/simon-ding/polaris",
|
||||
"uptime": uptime.Uptime(),
|
||||
"chat_group": "https://t.me/+8R2nzrlSs2JhMDgx",
|
||||
"go_version": runtime.Version(),
|
||||
}, nil
|
||||
}
|
||||
@@ -8,9 +8,11 @@ import (
|
||||
"path/filepath"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
tmdb "github.com/cyruzin/golang-tmdb"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -66,7 +68,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind query")
|
||||
}
|
||||
if (in.Folder == "") {
|
||||
if in.Folder == "" {
|
||||
return nil, errors.New("folder should be provided")
|
||||
}
|
||||
detailCn, err := s.MustTMDB().GetTvDetails(in.TmdbID, db.LanguageCN)
|
||||
@@ -118,7 +120,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
AirDate: detail.FirstAirDate,
|
||||
Resolution: media.Resolution(in.Resolution),
|
||||
StorageID: in.StorageID,
|
||||
TargetDir: in.Folder,
|
||||
TargetDir: in.Folder,
|
||||
}, epIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add to list")
|
||||
@@ -183,7 +185,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
AirDate: detail.ReleaseDate,
|
||||
Resolution: media.Resolution(in.Resolution),
|
||||
StorageID: in.StorageID,
|
||||
TargetDir: "./",
|
||||
TargetDir: "./",
|
||||
}, []int{epid})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add to list")
|
||||
@@ -238,14 +240,66 @@ func (s *Server) downloadImage(url string, mediaID int, name string) error {
|
||||
|
||||
}
|
||||
|
||||
type MediaWithStatus struct {
|
||||
*ent.Media
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
//missing: episode aired missing
|
||||
//downloaded: all monitored episode downloaded
|
||||
//monitoring: episode aired downloaded, but still has not aired episode
|
||||
//for movie, only monitoring/downloaded
|
||||
|
||||
func (s *Server) GetTvWatchlist(c *gin.Context) (interface{}, error) {
|
||||
list := s.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||
return list, nil
|
||||
res := make([]MediaWithStatus, len(list))
|
||||
for i, item := range list {
|
||||
var ms = MediaWithStatus{
|
||||
Media: item,
|
||||
Status: "downloaded",
|
||||
}
|
||||
|
||||
details := s.db.GetMediaDetails(item.ID)
|
||||
for _, ep := range details.Episodes {
|
||||
if ep.SeasonNumber == 0 {
|
||||
continue
|
||||
}
|
||||
t, err := time.Parse("2006-01-02", ep.AirDate)
|
||||
if err != nil { //airdate not exist
|
||||
ms.Status = "monitoring"
|
||||
} else {
|
||||
if item.CreatedAt.Sub(t) > 24*time.Hour { //剧集在加入watchlist之前,不去下载
|
||||
continue
|
||||
}
|
||||
if ep.Status == episode.StatusMissing {
|
||||
ms.Status = "monitoring"
|
||||
}
|
||||
}
|
||||
}
|
||||
res[i] = ms
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetMovieWatchlist(c *gin.Context) (interface{}, error) {
|
||||
list := s.db.GetMediaWatchlist(media.MediaTypeMovie)
|
||||
return list, nil
|
||||
res := make([]MediaWithStatus, len(list))
|
||||
for i, item := range list {
|
||||
var ms = MediaWithStatus{
|
||||
Media: item,
|
||||
Status: "monitoring",
|
||||
}
|
||||
dummyEp, err := s.db.GetMovieDummyEpisode(item.ID)
|
||||
if err != nil {
|
||||
log.Errorf("get dummy episode: %v", err)
|
||||
} else {
|
||||
if dummyEp.Status != episode.StatusMissing {
|
||||
ms.Status = "downloaded"
|
||||
}
|
||||
}
|
||||
res[i] = ms
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetMediaDetails(c *gin.Context) (interface{}, error) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
ref
|
||||
.read(activitiesDataProvider("active").notifier)
|
||||
.deleteActivity(id)
|
||||
.whenComplete(() => Utils.showSnakeBar("删除成功"))
|
||||
.then((v) => Utils.showSnakeBar("删除成功"))
|
||||
.onError((error, trace) => Utils.showSnakeBar("删除失败:$error"));
|
||||
};
|
||||
}
|
||||
|
||||
169
ui/lib/main.dart
169
ui/lib/main.dart
@@ -8,7 +8,8 @@ import 'package:ui/login_page.dart';
|
||||
import 'package:ui/movie_watchlist.dart';
|
||||
import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/search.dart';
|
||||
import 'package:ui/system_settings.dart';
|
||||
import 'package:ui/settings.dart';
|
||||
import 'package:ui/system_page.dart';
|
||||
import 'package:ui/tv_details.dart';
|
||||
import 'package:ui/welcome_page.dart';
|
||||
|
||||
@@ -26,8 +27,6 @@ class MyApp extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends ConsumerState<MyApp> {
|
||||
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -35,8 +34,9 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||
final shellRoute = ShellRoute(
|
||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
return SelectionArea(
|
||||
child: MainSkeleton(body: Padding(padding: const EdgeInsets.all(20), child: child),
|
||||
),
|
||||
child: MainSkeleton(
|
||||
body: Padding(padding: const EdgeInsets.all(20), child: child),
|
||||
),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
@@ -74,6 +74,10 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||
GoRoute(
|
||||
path: ActivityPage.route,
|
||||
builder: (context, state) => const ActivityPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: SystemPage.route,
|
||||
builder: (context, state) => const SystemPage(),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -95,7 +99,9 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||
theme: ThemeData(
|
||||
fontFamily: "NotoSansSC",
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.blueAccent, brightness: Brightness.dark, surface: Colors.black54),
|
||||
seedColor: Colors.blueAccent,
|
||||
brightness: Brightness.dark,
|
||||
surface: Colors.black54),
|
||||
useMaterial3: true,
|
||||
//scaffoldBackgroundColor: Color.fromARGB(255, 26, 24, 24)
|
||||
),
|
||||
@@ -103,7 +109,6 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MainSkeleton extends StatefulWidget {
|
||||
@@ -130,85 +135,85 @@ class _MainSkeletonState extends State<MainSkeleton> {
|
||||
_selectedTab = 2;
|
||||
} else if (uri.contains(SystemSettingsPage.route)) {
|
||||
_selectedTab = 3;
|
||||
} else if (uri.contains(SystemPage.route)) {
|
||||
_selectedTab = 4;
|
||||
}
|
||||
|
||||
return AdaptiveScaffold(
|
||||
appBarBreakpoint: Breakpoints.standard,
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: const Row(
|
||||
children: [
|
||||
Text("Polaris"),
|
||||
],
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: const Row(
|
||||
children: [
|
||||
Text("Polaris"),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
SearchAnchor(
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxWidth: 300, maxHeight: 40),
|
||||
child: Opacity(
|
||||
opacity: 0.8,
|
||||
child: SearchBar(
|
||||
hintText: "搜索...",
|
||||
leading: const Icon(Icons.search),
|
||||
controller: controller,
|
||||
shadowColor: WidgetStateColor.transparent,
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.primaryContainer),
|
||||
onSubmitted: (value) => context.go(Uri(
|
||||
path: SearchPage.route,
|
||||
queryParameters: {'query': value}).toString()),
|
||||
),
|
||||
actions: [
|
||||
SearchAnchor(builder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return Container(
|
||||
constraints:
|
||||
const BoxConstraints(maxWidth: 300, maxHeight: 40),
|
||||
child: Opacity(
|
||||
opacity: 0.8,
|
||||
child: SearchBar(
|
||||
hintText: "搜索...",
|
||||
leading: const Icon(Icons.search),
|
||||
controller: controller,
|
||||
shadowColor: WidgetStateColor.transparent,
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.primaryContainer
|
||||
),
|
||||
onSubmitted: (value) => context.go(Uri(
|
||||
path: SearchPage.route,
|
||||
queryParameters: {'query': value}).toString()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}, suggestionsBuilder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return [Text("dadada")];
|
||||
}),
|
||||
FutureBuilder(
|
||||
future: APIs.isLoggedIn(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && snapshot.data == true) {
|
||||
return MenuAnchor(
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(Icons.exit_to_app),
|
||||
child: const Text("登出"),
|
||||
onPressed: () async {
|
||||
final SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
await prefs.remove('token');
|
||||
if (context.mounted) {
|
||||
context.go(LoginScreen.route);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
builder: (context, controller, child) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Icon(Icons.account_circle),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
})
|
||||
],
|
||||
),
|
||||
);
|
||||
}, suggestionsBuilder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return [Text("dadada")];
|
||||
}),
|
||||
FutureBuilder(
|
||||
future: APIs.isLoggedIn(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && snapshot.data == true) {
|
||||
return MenuAnchor(
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(Icons.exit_to_app),
|
||||
child: const Text("登出"),
|
||||
onPressed: () async {
|
||||
final SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
await prefs.remove('token');
|
||||
if (context.mounted) {
|
||||
context.go(LoginScreen.route);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
builder: (context, controller, child) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Icon(Icons.account_circle),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
})
|
||||
],
|
||||
),
|
||||
useDrawer: false,
|
||||
selectedIndex: _selectedTab,
|
||||
onSelectedIndexChange: (int index) {
|
||||
@@ -223,6 +228,8 @@ class _MainSkeletonState extends State<MainSkeleton> {
|
||||
context.go(ActivityPage.route);
|
||||
} else if (index == 3) {
|
||||
context.go(SystemSettingsPage.route);
|
||||
} else if (index == 4) {
|
||||
context.go(SystemPage.route);
|
||||
}
|
||||
},
|
||||
destinations: const <NavigationDestination>[
|
||||
@@ -242,6 +249,10 @@ class _MainSkeletonState extends State<MainSkeleton> {
|
||||
icon: Icon(Icons.settings),
|
||||
label: '设置',
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.computer_rounded),
|
||||
label: '系统',
|
||||
),
|
||||
],
|
||||
body: (context) => widget.body,
|
||||
// Define a default secondaryBody.
|
||||
|
||||
@@ -115,7 +115,7 @@ class _MovieDetailsPageState extends ConsumerState<MovieDetailsPage> {
|
||||
widget.id)
|
||||
.notifier)
|
||||
.delete()
|
||||
.whenComplete(() => context
|
||||
.then((v) => context
|
||||
.go(WelcomePage.routeMoivie))
|
||||
.onError((error, trace) =>
|
||||
Utils.showSnakeBar(
|
||||
@@ -252,8 +252,8 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
||||
ref
|
||||
.read(movieTorrentsDataProvider(widget.id)
|
||||
.notifier)
|
||||
.download(torrent.link!)
|
||||
.whenComplete(() =>
|
||||
.download(torrent)
|
||||
.then((v) =>
|
||||
Utils.showSnakeBar("开始下载:${torrent.name}"))
|
||||
.onError((error, trace) =>
|
||||
Utils.showSnakeBar("操作失败: $error"));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ui/activity.dart';
|
||||
import 'package:ui/system_settings.dart';
|
||||
import 'package:ui/settings.dart';
|
||||
import 'package:ui/welcome_page.dart';
|
||||
|
||||
class NavDrawer extends StatefulWidget {
|
||||
|
||||
@@ -29,6 +29,9 @@ class APIs {
|
||||
static final activityUrl = "$_baseUrl/api/v1/activity/";
|
||||
static final activityMediaUrl = "$_baseUrl/api/v1/activity/media/";
|
||||
static final imagesUrl = "$_baseUrl/api/v1/img";
|
||||
static final logsBaseUrl = "$_baseUrl/api/v1/logs/";
|
||||
static final logFilesUrl = "$_baseUrl/api/v1/setting/logfiles";
|
||||
static final aboutUrl = "$_baseUrl/api/v1/setting/about";
|
||||
|
||||
static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/server_response.dart';
|
||||
|
||||
var activitiesDataProvider =
|
||||
AsyncNotifierProvider.autoDispose.family<ActivityData, List<Activity>, String>(
|
||||
AsyncNotifierProvider.family<ActivityData, List<Activity>, String>(
|
||||
ActivityData.new);
|
||||
|
||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
@@ -24,8 +24,7 @@ var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
},
|
||||
);
|
||||
|
||||
class ActivityData
|
||||
extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String> {
|
||||
class ActivityData extends FamilyAsyncNotifier<List<Activity>, String> {
|
||||
@override
|
||||
FutureOr<List<Activity>> build(String arg) async {
|
||||
if (arg == "active") {
|
||||
@@ -35,7 +34,8 @@ class ActivityData
|
||||
}
|
||||
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.get(APIs.activityUrl, queryParameters: {"status": arg});
|
||||
var resp =
|
||||
await dio.get(APIs.activityUrl, queryParameters: {"status": arg});
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
|
||||
@@ -41,10 +41,11 @@ class AuthSettingData extends AutoDisposeAsyncNotifier<AuthSetting> {
|
||||
class AuthSetting {
|
||||
bool enable;
|
||||
String user;
|
||||
String password;
|
||||
|
||||
AuthSetting({required this.enable, required this.user});
|
||||
AuthSetting({required this.enable, required this.user, required this.password});
|
||||
|
||||
factory AuthSetting.fromJson(Map<String, dynamic> json) {
|
||||
return AuthSetting(enable: json["enable"], user: json["user"]);
|
||||
return AuthSetting(enable: json["enable"], user: json["user"], password: json["password"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,18 +49,22 @@ class EditSettingData extends AutoDisposeAsyncNotifier<GeneralSetting> {
|
||||
class GeneralSetting {
|
||||
String? tmdbApiKey;
|
||||
String? downloadDIr;
|
||||
String? logLevel;
|
||||
|
||||
GeneralSetting({this.tmdbApiKey, this.downloadDIr});
|
||||
GeneralSetting({this.tmdbApiKey, this.downloadDIr, this.logLevel});
|
||||
|
||||
factory GeneralSetting.fromJson(Map<String, dynamic> json) {
|
||||
return GeneralSetting(
|
||||
tmdbApiKey: json["tmdb_api_key"], downloadDIr: json["download_dir"]);
|
||||
tmdbApiKey: json["tmdb_api_key"],
|
||||
downloadDIr: json["download_dir"],
|
||||
logLevel: json["log_level"]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['tmdb_api_key'] = tmdbApiKey;
|
||||
data['download_dir'] = downloadDIr;
|
||||
data["log_level"] = logLevel;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -257,13 +261,13 @@ class StorageSettingData extends AutoDisposeAsyncNotifier<List<Storage>> {
|
||||
}
|
||||
|
||||
class Storage {
|
||||
Storage(
|
||||
{this.id,
|
||||
this.name,
|
||||
this.implementation,
|
||||
this.settings,
|
||||
this.isDefault,
|
||||
});
|
||||
Storage({
|
||||
this.id,
|
||||
this.name,
|
||||
this.implementation,
|
||||
this.settings,
|
||||
this.isDefault,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String? name;
|
||||
@@ -288,3 +292,65 @@ class Storage {
|
||||
"default": isDefault,
|
||||
};
|
||||
}
|
||||
|
||||
final logFileDataProvider = FutureProvider.autoDispose((ref) async {
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.get(APIs.logFilesUrl);
|
||||
var sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
List<LogFile> favList = List.empty(growable: true);
|
||||
for (var item in sp.data as List) {
|
||||
var tv = LogFile.fromJson(item);
|
||||
favList.add(tv);
|
||||
}
|
||||
return favList;
|
||||
});
|
||||
|
||||
final aboutDataProvider = FutureProvider.autoDispose((ref) async {
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.get(APIs.aboutUrl);
|
||||
var sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
return About.fromJson(sp.data);
|
||||
});
|
||||
|
||||
class LogFile {
|
||||
String? name;
|
||||
int? size;
|
||||
|
||||
LogFile({this.name, this.size});
|
||||
|
||||
factory LogFile.fromJson(Map<String, dynamic> json1) {
|
||||
return LogFile(name: json1["name"], size: json1["size"]);
|
||||
}
|
||||
}
|
||||
|
||||
class About {
|
||||
About({
|
||||
required this.chatGroup,
|
||||
required this.goVersion,
|
||||
required this.homepage,
|
||||
required this.intro,
|
||||
required this.uptime,
|
||||
});
|
||||
|
||||
final String? chatGroup;
|
||||
final String? goVersion;
|
||||
final String? homepage;
|
||||
final String? intro;
|
||||
final Duration? uptime;
|
||||
|
||||
factory About.fromJson(Map<String, dynamic> json) {
|
||||
return About(
|
||||
chatGroup: json["chat_group"],
|
||||
goVersion: json["go_version"],
|
||||
homepage: json["homepage"],
|
||||
intro: json["intro"],
|
||||
uptime: Duration(microseconds: (json["uptime"]/1000.0 as double).round()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,7 @@ class MediaDetail {
|
||||
String? resolution;
|
||||
int? storageId;
|
||||
String? airDate;
|
||||
String? status;
|
||||
|
||||
MediaDetail({
|
||||
this.id,
|
||||
@@ -163,6 +164,7 @@ class MediaDetail {
|
||||
this.resolution,
|
||||
this.storageId,
|
||||
this.airDate,
|
||||
this.status,
|
||||
});
|
||||
|
||||
MediaDetail.fromJson(Map<String, dynamic> json) {
|
||||
@@ -177,28 +179,28 @@ class MediaDetail {
|
||||
resolution = json["resolution"];
|
||||
storageId = json["storage_id"];
|
||||
airDate = json["air_date"];
|
||||
status = json["status"];
|
||||
}
|
||||
}
|
||||
|
||||
class SearchResult {
|
||||
SearchResult({
|
||||
required this.backdropPath,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.originalName,
|
||||
required this.overview,
|
||||
required this.posterPath,
|
||||
required this.mediaType,
|
||||
required this.adult,
|
||||
required this.originalLanguage,
|
||||
required this.genreIds,
|
||||
required this.popularity,
|
||||
required this.firstAirDate,
|
||||
required this.voteAverage,
|
||||
required this.voteCount,
|
||||
required this.originCountry,
|
||||
this.inWatchlist
|
||||
});
|
||||
SearchResult(
|
||||
{required this.backdropPath,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.originalName,
|
||||
required this.overview,
|
||||
required this.posterPath,
|
||||
required this.mediaType,
|
||||
required this.adult,
|
||||
required this.originalLanguage,
|
||||
required this.genreIds,
|
||||
required this.popularity,
|
||||
required this.firstAirDate,
|
||||
required this.voteAverage,
|
||||
required this.voteCount,
|
||||
required this.originCountry,
|
||||
this.inWatchlist});
|
||||
|
||||
final String? backdropPath;
|
||||
final int? id;
|
||||
@@ -258,10 +260,12 @@ class MovieTorrentResource
|
||||
return (rsp.data as List).map((v) => TorrentResource.fromJson(v)).toList();
|
||||
}
|
||||
|
||||
Future<void> download(String link) async {
|
||||
Future<void> download(TorrentResource res) async {
|
||||
var m = res.toJson();
|
||||
m["media_id"] = int.parse(mediaId!);
|
||||
|
||||
final dio = await APIs.getDio();
|
||||
var resp = await dio.post(APIs.availableMoviesUrl,
|
||||
data: {"media_id": int.parse(mediaId!), "link": link});
|
||||
var resp = await dio.post(APIs.availableMoviesUrl, data: m);
|
||||
var rsp = ServerResponse.fromJson(resp.data);
|
||||
if (rsp.code != 0) {
|
||||
throw rsp.message;
|
||||
@@ -286,4 +290,11 @@ class TorrentResource {
|
||||
peers: json["peers"],
|
||||
link: json["link"]);
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['name'] = name;
|
||||
data['size'] = size;
|
||||
data["link"] = link;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/providers/welcome_data.dart';
|
||||
import 'package:ui/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
|
||||
class SearchPage extends ConsumerStatefulWidget {
|
||||
@@ -257,13 +258,14 @@ class _SearchPageState extends ConsumerState<SearchPage> {
|
||||
ref
|
||||
.read(searchPageDataProvider(widget.query ?? "")
|
||||
.notifier)
|
||||
.submit2Watchlist(
|
||||
item.id!,
|
||||
storageSelected,
|
||||
resSelected,
|
||||
item.mediaType!,
|
||||
pathController.text);
|
||||
Navigator.of(context).pop();
|
||||
.submit2Watchlist(item.id!, storageSelected,
|
||||
resSelected, item.mediaType!, pathController.text)
|
||||
.then((v) {
|
||||
Utils.showSnakeBar("添加成功");
|
||||
Navigator.of(context).pop();
|
||||
}).onError((error, trace) {
|
||||
Utils.showSnakeBar("添加失败:$error");
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
640
ui/lib/settings.dart
Normal file
640
ui/lib/settings.dart
Normal file
@@ -0,0 +1,640 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:quiver/strings.dart';
|
||||
import 'package:ui/providers/login.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:ui/widgets/widgets.dart';
|
||||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
|
||||
class SystemSettingsPage extends ConsumerStatefulWidget {
|
||||
static const route = "/settings";
|
||||
|
||||
const SystemSettingsPage({super.key});
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() {
|
||||
return _SystemSettingsPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
final _formKey2 = GlobalKey<FormBuilderState>();
|
||||
bool? _enableAuth;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var settings = ref.watch(settingProvider);
|
||||
|
||||
var tmdbSetting = settings.when(
|
||||
data: (v) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(40, 10, 40, 0),
|
||||
child: FormBuilder(
|
||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: {
|
||||
"tmdb_api": v.tmdbApiKey,
|
||||
"download_dir": v.downloadDIr,
|
||||
"log_level": v.logLevel
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "tmdb_api",
|
||||
autofocus: true,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "TMDB Api Key", icon: const Icon(Icons.key)),
|
||||
//
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "download_dir",
|
||||
autofocus: true,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "下载路径", icon: const Icon(Icons.folder)),
|
||||
//
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderDropdown(
|
||||
name: "log_level",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "日志级别",
|
||||
icon: Icon(Icons.file_present_rounded),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: "debug", child: Text("DEBUG")),
|
||||
DropdownMenuItem(value: "info", child: Text("INFO")),
|
||||
DropdownMenuItem(
|
||||
value: "warn", child: Text("WARNNING")),
|
||||
DropdownMenuItem(
|
||||
value: "error", child: Text("ERROR")),
|
||||
],
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 28.0),
|
||||
child: ElevatedButton(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Text("保存"),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
var f = ref
|
||||
.read(settingProvider.notifier)
|
||||
.updateSettings(GeneralSetting(
|
||||
tmdbApiKey: values["tmdb_api"],
|
||||
downloadDIr: values["download_dir"],
|
||||
logLevel: values["log_level"]));
|
||||
f.then((v) {
|
||||
Utils.showSnakeBar("更新成功");
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("更新失败:$e");
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var indexers = ref.watch(indexersProvider);
|
||||
var indexerSetting = indexers.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var indexer = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(indexer),
|
||||
child: Text(indexer.name ?? ""));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(Indexer()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var downloadClients = ref.watch(dwonloadClientsProvider);
|
||||
var downloadSetting = downloadClients.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var client = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showDownloadClientDetails(client),
|
||||
child: Text(client.name ?? ""));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showDownloadClientDetails(DownloadClient()),
|
||||
child: const Icon(Icons.add));
|
||||
})),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var storageSettingData = ref.watch(storageSettingProvider);
|
||||
var storageSetting = storageSettingData.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var storage = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showStorageDetails(storage),
|
||||
child: Text(storage.name ?? ""));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showStorageDetails(Storage()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var authData = ref.watch(authSettingProvider);
|
||||
TextEditingController userController = TextEditingController();
|
||||
TextEditingController passController = TextEditingController();
|
||||
var authSetting = authData.when(
|
||||
data: (data) {
|
||||
if (_enableAuth == null) {
|
||||
setState(() {
|
||||
_enableAuth = data.enable;
|
||||
});
|
||||
}
|
||||
userController.text = data.user;
|
||||
return FormBuilder(
|
||||
key: _formKey2,
|
||||
initialValue: {
|
||||
"user": data.user,
|
||||
"password": data.password,
|
||||
"enable": data.enable
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderSwitch(
|
||||
name: "enable",
|
||||
title: const Text("开启认证"),
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_enableAuth = v;
|
||||
});
|
||||
}),
|
||||
_enableAuth!
|
||||
? Column(
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "user",
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "用户名",
|
||||
icon: const Icon(Icons.account_box),
|
||||
)),
|
||||
FormBuilderTextField(
|
||||
name: "password",
|
||||
obscureText: true,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "密码",
|
||||
icon: const Icon(Icons.password),
|
||||
))
|
||||
],
|
||||
)
|
||||
: const Column(),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
child: const Text("保存"),
|
||||
onPressed: () {
|
||||
if (_formKey2.currentState!.saveAndValidate()) {
|
||||
var values = _formKey2.currentState!.value;
|
||||
var f = ref
|
||||
.read(authSettingProvider.notifier)
|
||||
.updateAuthSetting(_enableAuth!,
|
||||
values["user"], values["password"]);
|
||||
f.then((v) {
|
||||
Utils.showSnakeBar("更新成功");
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("更新失败:$e");
|
||||
});
|
||||
}
|
||||
}))
|
||||
],
|
||||
));
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
return ListView(
|
||||
children: [
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: true,
|
||||
title: const Text("常规设置"),
|
||||
children: [tmdbSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("索引器设置"),
|
||||
children: [indexerSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("下载器设置"),
|
||||
children: [downloadSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("存储设置"),
|
||||
children: [storageSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("认证设置"),
|
||||
children: [authSetting],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showIndexerDetails(Indexer indexer) {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
var selectImpl = "torznab";
|
||||
var body = FormBuilder(
|
||||
key: _formKey,
|
||||
initialValue: {
|
||||
"name": indexer.name,
|
||||
"url": indexer.url,
|
||||
"api_key": indexer.apiKey,
|
||||
"impl": "torznab"
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderDropdown(
|
||||
name: "impl",
|
||||
decoration: const InputDecoration(labelText: "类型"),
|
||||
items: const [
|
||||
DropdownMenuItem(value: "torznab", child: Text("Torznab")),
|
||||
],
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "name",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "api_key",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
onDelete() async {
|
||||
return ref.read(indexersProvider.notifier).deleteIndexer(indexer.id!);
|
||||
}
|
||||
|
||||
onSubmit() async {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
return ref.read(indexersProvider.notifier).addIndexer(Indexer(
|
||||
name: values["name"],
|
||||
url: values["url"],
|
||||
apiKey: values["api_key"]));
|
||||
} else {
|
||||
throw "数据校验失败";
|
||||
}
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
"索引器", indexer.id != null, body, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showDownloadClientDetails(DownloadClient client) {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
var _enableAuth = isNotBlank(client.user);
|
||||
String selectImpl = "transmission";
|
||||
|
||||
final body =
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return FormBuilder(
|
||||
key: _formKey,
|
||||
initialValue: {
|
||||
"name": client.name,
|
||||
"url": client.url,
|
||||
"user": client.user,
|
||||
"password": client.password,
|
||||
"impl": "transmission"
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderDropdown<String>(
|
||||
name: "impl",
|
||||
decoration: const InputDecoration(labelText: "类型"),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectImpl = value!;
|
||||
});
|
||||
},
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: "transmission", child: Text("Transmission")),
|
||||
],
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "name",
|
||||
decoration: const InputDecoration(labelText: "名称"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction),
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "地址", hintText: "http://127.0.0.1:9091"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Column(
|
||||
children: [
|
||||
FormBuilderSwitch(
|
||||
name: "auth",
|
||||
title: const Text("需要认证"),
|
||||
initialValue: _enableAuth,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_enableAuth = v!;
|
||||
});
|
||||
}),
|
||||
_enableAuth
|
||||
? Column(
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "user",
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "用户"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction),
|
||||
FormBuilderTextField(
|
||||
name: "password",
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "密码"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
obscureText: true,
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction),
|
||||
],
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
);
|
||||
})
|
||||
],
|
||||
));
|
||||
});
|
||||
onDelete() async {
|
||||
return ref
|
||||
.read(dwonloadClientsProvider.notifier)
|
||||
.deleteDownloadClients(client.id!);
|
||||
}
|
||||
|
||||
onSubmit() async {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
return ref.read(dwonloadClientsProvider.notifier).addDownloadClients(
|
||||
DownloadClient(
|
||||
name: values["name"],
|
||||
implementation: values["impl"],
|
||||
url: values["url"],
|
||||
user: _enableAuth ? values["user"] : null,
|
||||
password: _enableAuth ? values["password"] : null));
|
||||
} else {
|
||||
throw "数据校验不通过";
|
||||
}
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
"下载器", client.id != null, body, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showStorageDetails(Storage s) {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
|
||||
String selectImpl = s.implementation == null ? "local" : s.implementation!;
|
||||
final widgets =
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return FormBuilder(
|
||||
key: _formKey,
|
||||
autovalidateMode: AutovalidateMode.disabled,
|
||||
initialValue: {
|
||||
"name": s.name,
|
||||
"impl": s.implementation == null ? "local" : s.implementation!,
|
||||
"user": s.settings != null ? s.settings!["user"] ?? "" : "",
|
||||
"password": s.settings != null ? s.settings!["password"] ?? "" : "",
|
||||
"tv_path": s.settings != null ? s.settings!["tv_path"] ?? "" : "",
|
||||
"url": s.settings != null ? s.settings!["url"] ?? "" : "",
|
||||
"movie_path":
|
||||
s.settings != null ? s.settings!["movie_path"] ?? "" : "",
|
||||
"change_file_hash": s.settings != null
|
||||
? s.settings!["change_file_hash"] == "true"
|
||||
? true
|
||||
: false
|
||||
: false,
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
FormBuilderDropdown<String>(
|
||||
name: "impl",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration: const InputDecoration(labelText: "类型"),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectImpl = value!;
|
||||
});
|
||||
},
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: "local",
|
||||
child: Text("本地存储"),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: "webdav",
|
||||
child: Text("webdav"),
|
||||
)
|
||||
],
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "name",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: s.name,
|
||||
decoration: const InputDecoration(labelText: "名称"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
selectImpl != "local"
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration:
|
||||
const InputDecoration(labelText: "Webdav地址"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "user",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration: const InputDecoration(labelText: "用户"),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "password",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration: const InputDecoration(labelText: "密码"),
|
||||
obscureText: true,
|
||||
),
|
||||
FormBuilderCheckbox(
|
||||
name: "change_file_hash",
|
||||
title: const Text(
|
||||
"上传时更改文件哈希",
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
FormBuilderTextField(
|
||||
name: "tv_path",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration: const InputDecoration(labelText: "电视剧路径"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "movie_path",
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
decoration: const InputDecoration(labelText: "电影路径"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
)
|
||||
],
|
||||
));
|
||||
});
|
||||
onSubmit() async {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
final values = _formKey.currentState!.value;
|
||||
return ref.read(storageSettingProvider.notifier).addStorage(Storage(
|
||||
name: values["name"],
|
||||
implementation: selectImpl,
|
||||
settings: {
|
||||
"tv_path": values["tv_path"],
|
||||
"movie_path": values["movie_path"],
|
||||
"url": values["url"],
|
||||
"user": values["user"],
|
||||
"password": values["password"],
|
||||
"change_file_hash":
|
||||
values["change_file_hash"] as bool ? "true" : "false"
|
||||
},
|
||||
));
|
||||
} else {
|
||||
throw "数据校验位未通过";
|
||||
}
|
||||
}
|
||||
|
||||
onDelete() async {
|
||||
return ref.read(storageSettingProvider.notifier).deleteStorage(s.id!);
|
||||
}
|
||||
|
||||
return showSettingDialog('存储', s.id != null, widgets, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showSettingDialog(String title, bool showDelete, Widget body,
|
||||
Future Function() onSubmit, Future Function() onDelete) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: SingleChildScrollView(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 200),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
showDelete
|
||||
? TextButton(
|
||||
onPressed: () {
|
||||
final f = onDelete();
|
||||
f.then((v) {
|
||||
Utils.showSnakeBar("删除成功");
|
||||
Navigator.of(context).pop();
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("删除失败:$e");
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
'删除',
|
||||
style: TextStyle(color: Colors.red),
|
||||
))
|
||||
: const Text(""),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消')),
|
||||
TextButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () {
|
||||
final f = onSubmit();
|
||||
f.then((v) {
|
||||
Utils.showSnakeBar("操作成功");
|
||||
Navigator.of(context).pop();
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("操作失败:$e");
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
136
ui/lib/system_page.dart
Normal file
136
ui/lib/system_page.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:ui/providers/APIs.dart';
|
||||
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class SystemPage extends ConsumerStatefulWidget {
|
||||
static const route = "/system";
|
||||
|
||||
const SystemPage({super.key});
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() {
|
||||
return _SystemPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SystemPageState extends ConsumerState<SystemPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logs = ref.watch(logFileDataProvider);
|
||||
final about = ref.watch(aboutDataProvider);
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
ExpansionTile(
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
initiallyExpanded: true,
|
||||
childrenPadding: EdgeInsets.all(20),
|
||||
title: Text("日志"),
|
||||
children: [
|
||||
logs.when(
|
||||
data: (list) {
|
||||
return DataTable(
|
||||
columns: const [
|
||||
DataColumn(label: Text("日志")),
|
||||
DataColumn(label: Text("大小")),
|
||||
DataColumn(label: Text("*"))
|
||||
],
|
||||
rows: List.generate(list.length, (i) {
|
||||
final item = list[i];
|
||||
final uri =
|
||||
Uri.parse("${APIs.logsBaseUrl}${item.name}");
|
||||
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(item.name ?? "")),
|
||||
DataCell(Text("${item.size ?? 0}")),
|
||||
DataCell(InkWell(
|
||||
child: Icon(Icons.download),
|
||||
onTap: () => launchUrl(uri,
|
||||
webViewConfiguration: WebViewConfiguration(
|
||||
headers: APIs.authHeaders)),
|
||||
))
|
||||
]);
|
||||
}));
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator())
|
||||
],
|
||||
),
|
||||
ExpansionTile(
|
||||
title: Text("关于"),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.center,
|
||||
initiallyExpanded: true,
|
||||
children: [
|
||||
about.when(
|
||||
data: (v) {
|
||||
final uri = Uri.parse(v.chatGroup ?? "");
|
||||
final homepage = Uri.parse(v.homepage ?? "");
|
||||
return Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Text(
|
||||
"#",
|
||||
style: TextStyle(height: 2.5),
|
||||
),
|
||||
Text("主页", style: TextStyle(height: 2.5)),
|
||||
Text("讨论组", style: TextStyle(height: 2.5)),
|
||||
Text("go version", style: TextStyle(height: 2.5)),
|
||||
Text("uptime", style: TextStyle(height: 2.5)),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Text(v.intro ?? "",
|
||||
style: const TextStyle(height: 2.5)),
|
||||
InkWell(
|
||||
child: Text(v.homepage ?? "",
|
||||
style: const TextStyle(height: 2.5)),
|
||||
onTap: () => launchUrl(homepage),
|
||||
),
|
||||
InkWell(
|
||||
child: const Text("Telegram",
|
||||
style: TextStyle(height: 2.5)),
|
||||
onTap: () => launchUrl(uri),
|
||||
),
|
||||
Text("${v.goVersion}",
|
||||
style: const TextStyle(height: 2.5)),
|
||||
Text("${v.uptime}",
|
||||
style: const TextStyle(height: 2.5)),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator())
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,539 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:quiver/strings.dart';
|
||||
import 'package:ui/providers/login.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:ui/widgets/widgets.dart';
|
||||
|
||||
class SystemSettingsPage extends ConsumerStatefulWidget {
|
||||
static const route = "/settings";
|
||||
|
||||
const SystemSettingsPage({super.key});
|
||||
@override
|
||||
ConsumerState<ConsumerStatefulWidget> createState() {
|
||||
return _SystemSettingsPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
||||
final GlobalKey _formKey = GlobalKey<FormState>();
|
||||
|
||||
final _tmdbApiController = TextEditingController();
|
||||
final _downloadDirController = TextEditingController();
|
||||
bool? _enableAuth;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var settings = ref.watch(settingProvider);
|
||||
|
||||
var tmdbSetting = settings.when(
|
||||
data: (v) {
|
||||
_tmdbApiController.text = v.tmdbApiKey!;
|
||||
_downloadDirController.text = v.downloadDIr!;
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(40, 10, 40, 0),
|
||||
child: Form(
|
||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
controller: _tmdbApiController,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "TMDB Api Key", icon: const Icon(Icons.key)),
|
||||
//
|
||||
validator: (v) {
|
||||
return v!.trim().isNotEmpty ? null : "ApiKey 不能为空";
|
||||
},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
controller: _downloadDirController,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "下载路径", icon: const Icon(Icons.folder)),
|
||||
//
|
||||
validator: (v) {
|
||||
return v!.trim().isNotEmpty ? null : "下载路径不能为空";
|
||||
},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 28.0),
|
||||
child: ElevatedButton(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Text("保存"),
|
||||
),
|
||||
onPressed: () {
|
||||
if ((_formKey.currentState as FormState)
|
||||
.validate()) {
|
||||
var f = ref
|
||||
.read(settingProvider.notifier)
|
||||
.updateSettings(GeneralSetting(
|
||||
tmdbApiKey: _tmdbApiController.text,
|
||||
downloadDIr:
|
||||
_downloadDirController.text));
|
||||
f.whenComplete(() {
|
||||
Utils.showSnakeBar("更新成功");
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("更新失败:$e");
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var indexers = ref.watch(indexersProvider);
|
||||
var indexerSetting = indexers.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var indexer = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(indexer),
|
||||
child: Text(indexer.name!));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(Indexer()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var downloadClients = ref.watch(dwonloadClientsProvider);
|
||||
var downloadSetting = downloadClients.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var client = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showDownloadClientDetails(client),
|
||||
child: Text(client.name!));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showDownloadClientDetails(DownloadClient()),
|
||||
child: const Icon(Icons.add));
|
||||
})),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var storageSettingData = ref.watch(storageSettingProvider);
|
||||
var storageSetting = storageSettingData.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var storage = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showStorageDetails(storage),
|
||||
child: Text(storage.name!));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showStorageDetails(Storage()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
),
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
var authData = ref.watch(authSettingProvider);
|
||||
TextEditingController userController = TextEditingController();
|
||||
TextEditingController passController = TextEditingController();
|
||||
var authSetting = authData.when(
|
||||
data: (data) {
|
||||
if (_enableAuth == null) {
|
||||
setState(() {
|
||||
_enableAuth = data.enable;
|
||||
});
|
||||
}
|
||||
userController.text = data.user;
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text("开启认证"),
|
||||
value: _enableAuth!,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_enableAuth = v;
|
||||
});
|
||||
}),
|
||||
_enableAuth!
|
||||
? Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: userController,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "用户名",
|
||||
icon: const Icon(Icons.account_box),
|
||||
)),
|
||||
TextFormField(
|
||||
obscureText: true,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
controller: passController,
|
||||
decoration: Commons.requiredTextFieldStyle(
|
||||
text: "密码",
|
||||
icon: const Icon(Icons.password),
|
||||
))
|
||||
],
|
||||
)
|
||||
: const Column(),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
child: const Text("保存"),
|
||||
onPressed: () {
|
||||
var f = ref
|
||||
.read(authSettingProvider.notifier)
|
||||
.updateAuthSetting(_enableAuth!,
|
||||
userController.text, passController.text);
|
||||
f.whenComplete(() {
|
||||
Utils.showSnakeBar("更新成功");
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("更新失败:$e");
|
||||
});
|
||||
}))
|
||||
],
|
||||
);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator());
|
||||
|
||||
return ListView(
|
||||
children: [
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: true,
|
||||
title: const Text("常规设置"),
|
||||
children: [tmdbSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("索引器设置"),
|
||||
children: [indexerSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("下载器设置"),
|
||||
children: [downloadSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
expandedAlignment: Alignment.centerLeft,
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("存储设置"),
|
||||
children: [storageSetting],
|
||||
),
|
||||
ExpansionTile(
|
||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
initiallyExpanded: false,
|
||||
title: const Text("认证设置"),
|
||||
children: [authSetting],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showIndexerDetails(Indexer indexer) {
|
||||
var nameController = TextEditingController(text: indexer.name);
|
||||
var urlController = TextEditingController(text: indexer.url);
|
||||
var apiKeyController = TextEditingController(text: indexer.apiKey);
|
||||
var selectImpl = "torznab";
|
||||
final children = <Widget>[
|
||||
DropdownMenu(
|
||||
label: const Text("类型"),
|
||||
onSelected: (value) {
|
||||
setState(() {
|
||||
selectImpl = value!;
|
||||
});
|
||||
},
|
||||
initialSelection: selectImpl,
|
||||
dropdownMenuEntries: const [
|
||||
DropdownMenuEntry(value: "torznab", label: "Torznab"),
|
||||
],
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
controller: nameController,
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||
controller: urlController,
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||
controller: apiKeyController,
|
||||
),
|
||||
];
|
||||
onDelete() async {
|
||||
return ref.read(indexersProvider.notifier).deleteIndexer(indexer.id!);
|
||||
}
|
||||
|
||||
onSubmit() async {
|
||||
return ref.read(indexersProvider.notifier).addIndexer(Indexer(
|
||||
name: nameController.text,
|
||||
url: urlController.text,
|
||||
apiKey: apiKeyController.text));
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
"索引器", indexer.id != null, children, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showDownloadClientDetails(DownloadClient client) {
|
||||
var nameController = TextEditingController(text: client.name);
|
||||
var urlController = TextEditingController(text: client.url);
|
||||
var userController = TextEditingController(text: client.user);
|
||||
var passController = TextEditingController(text: client.password);
|
||||
|
||||
var _enableAuth = isNotBlank(client.user);
|
||||
String selectImpl = "transmission";
|
||||
var body = <Widget>[
|
||||
DropdownMenu(
|
||||
label: const Text("类型"),
|
||||
onSelected: (value) {
|
||||
setState(() {
|
||||
selectImpl = value!;
|
||||
});
|
||||
},
|
||||
initialSelection: selectImpl,
|
||||
dropdownMenuEntries: const [
|
||||
DropdownMenuEntry(value: "transmission", label: "Transmission"),
|
||||
],
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
controller: nameController,
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||
controller: urlController,
|
||||
),
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text("需要认证"),
|
||||
value: _enableAuth,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_enableAuth = v;
|
||||
});
|
||||
}),
|
||||
_enableAuth
|
||||
? Column(
|
||||
children: [
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "用户"),
|
||||
controller: userController,
|
||||
),
|
||||
TextField(
|
||||
decoration: Commons.requiredTextFieldStyle(text: "密码"),
|
||||
controller: passController,
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
);
|
||||
})
|
||||
];
|
||||
onDelete() async {
|
||||
return ref
|
||||
.read(dwonloadClientsProvider.notifier)
|
||||
.deleteDownloadClients(client.id!);
|
||||
}
|
||||
|
||||
onSubmit() async {
|
||||
return ref.read(dwonloadClientsProvider.notifier).addDownloadClients(
|
||||
DownloadClient(
|
||||
name: nameController.text,
|
||||
implementation: "transmission",
|
||||
url: urlController.text,
|
||||
user: _enableAuth ? userController.text : null,
|
||||
password: _enableAuth ? passController.text : null));
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
"下载器", client.id != null, body, onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showStorageDetails(Storage s) {
|
||||
var nameController = TextEditingController(text: s.name);
|
||||
var tvPathController = TextEditingController();
|
||||
var moviePathController = TextEditingController();
|
||||
var urlController = TextEditingController();
|
||||
var userController = TextEditingController();
|
||||
var passController = TextEditingController();
|
||||
bool enablingChangeFileHash = false;
|
||||
if (s.settings != null) {
|
||||
tvPathController.text = s.settings!["tv_path"] ?? "";
|
||||
moviePathController.text = s.settings!["movie_path"] ?? "";
|
||||
urlController.text = s.settings!["url"] ?? "";
|
||||
userController.text = s.settings!["user"] ?? "";
|
||||
passController.text = s.settings!["password"] ?? "";
|
||||
enablingChangeFileHash =
|
||||
s.settings!["change_file_hash"] == "true" ? true : false;
|
||||
}
|
||||
|
||||
String selectImpl = s.implementation == null ? "local" : s.implementation!;
|
||||
final widgets =
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
DropdownMenu(
|
||||
label: const Text("类型"),
|
||||
onSelected: (value) {
|
||||
setState(() {
|
||||
selectImpl = value!;
|
||||
});
|
||||
},
|
||||
initialSelection: selectImpl,
|
||||
dropdownMenuEntries: const [
|
||||
DropdownMenuEntry(value: "local", label: "本地存储"),
|
||||
DropdownMenuEntry(value: "webdav", label: "webdav")
|
||||
],
|
||||
),
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "名称"),
|
||||
controller: nameController,
|
||||
),
|
||||
selectImpl != "local"
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "Webdav地址"),
|
||||
controller: urlController,
|
||||
),
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "用户"),
|
||||
controller: userController,
|
||||
),
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "密码"),
|
||||
controller: passController,
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text("上传时更改文件哈希", style: TextStyle(fontSize: 14),),
|
||||
value: enablingChangeFileHash,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
enablingChangeFileHash = v??false;
|
||||
});
|
||||
}),
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "电视剧路径"),
|
||||
controller: tvPathController,
|
||||
),
|
||||
TextField(
|
||||
decoration: const InputDecoration(labelText: "电影路径"),
|
||||
controller: moviePathController,
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
onSubmit() async {
|
||||
return ref.read(storageSettingProvider.notifier).addStorage(Storage(
|
||||
name: nameController.text,
|
||||
implementation: selectImpl,
|
||||
settings: {
|
||||
"tv_path": tvPathController.text,
|
||||
"movie_path": moviePathController.text,
|
||||
"url": urlController.text,
|
||||
"user": userController.text,
|
||||
"password": passController.text,
|
||||
"change_file_hash": enablingChangeFileHash ? "true" : "false"
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
onDelete() async {
|
||||
return ref.read(storageSettingProvider.notifier).deleteStorage(s.id!);
|
||||
}
|
||||
|
||||
return showSettingDialog('存储', s.id != null, [widgets], onSubmit, onDelete);
|
||||
}
|
||||
|
||||
Future<void> showSettingDialog(
|
||||
String title,
|
||||
bool showDelete,
|
||||
List<Widget> children,
|
||||
Future Function() onSubmit,
|
||||
Future Function() onDelete) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: SingleChildScrollView(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 200),
|
||||
child: ListBody(
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
showDelete
|
||||
? TextButton(
|
||||
onPressed: () {
|
||||
final f = onDelete();
|
||||
f.whenComplete(() {
|
||||
Utils.showSnakeBar("删除成功");
|
||||
Navigator.of(context).pop();
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("删除失败:$e");
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
'删除',
|
||||
style: TextStyle(color: Colors.red),
|
||||
))
|
||||
: const Text(""),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消')),
|
||||
TextButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () {
|
||||
final f = onSubmit();
|
||||
f.whenComplete(() {
|
||||
Utils.showSnakeBar("操作成功");
|
||||
Navigator.of(context).pop();
|
||||
}).onError((e, s) {
|
||||
Utils.showSnakeBar("操作失败:$e");
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
||||
widget.seriesId)
|
||||
.notifier)
|
||||
.delete()
|
||||
.whenComplete(() =>
|
||||
.then((v) =>
|
||||
context.go(WelcomePage.routeTv))
|
||||
.onError((error, trace) =>
|
||||
Utils.showSnakeBar(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:quiver/strings.dart';
|
||||
import 'package:ui/movie_watchlist.dart';
|
||||
import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/welcome_data.dart';
|
||||
@@ -27,7 +28,8 @@ class WelcomePage extends ConsumerWidget {
|
||||
return switch (data) {
|
||||
AsyncData(:final value) => SingleChildScrollView(
|
||||
child: Wrap(
|
||||
spacing: 20,
|
||||
spacing: 10,
|
||||
runSpacing: 20,
|
||||
children: List.generate(value.length, (i) {
|
||||
var item = value[i];
|
||||
return Card(
|
||||
@@ -45,15 +47,21 @@ class WelcomePage extends ConsumerWidget {
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: 160,
|
||||
height: 240,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: Image.network(
|
||||
"${APIs.imagesUrl}/${item.id}/poster.jpg",
|
||||
fit: BoxFit.fill,
|
||||
headers: APIs.authHeaders,
|
||||
),
|
||||
width: 140,
|
||||
height: 210,
|
||||
child: Image.network(
|
||||
"${APIs.imagesUrl}/${item.id}/poster.jpg",
|
||||
fit: BoxFit.fill,
|
||||
headers: APIs.authHeaders,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: LinearProgressIndicator(
|
||||
value: 1,
|
||||
color: item.status == "downloaded"
|
||||
? Colors.green
|
||||
: Colors.blue,
|
||||
)),
|
||||
Text(
|
||||
item.name!,
|
||||
|
||||
@@ -118,6 +118,14 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.1.11+1"
|
||||
flutter_form_builder:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_form_builder
|
||||
sha256: "447f8808f68070f7df968e8063aada3c9d2e90e789b5b70f3b44e4b315212656"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "9.3.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -126,6 +134,11 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
flutter_localizations:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_login:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -160,6 +173,14 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "10.7.0"
|
||||
form_builder_validators:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: form_builder_validators
|
||||
sha256: c61ed7b1deecf0e1ebe49e2fa79e3283937c5a21c7e48e3ed9856a4a14e1191a
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "11.0.0"
|
||||
go_router:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -518,7 +539,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
url_launcher:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3"
|
||||
|
||||
@@ -44,6 +44,9 @@ dependencies:
|
||||
percent_indicator: ^4.2.3
|
||||
intl: ^0.19.0
|
||||
flutter_adaptive_scaffold: ^0.1.11+1
|
||||
flutter_form_builder: ^9.3.0
|
||||
form_builder_validators: ^11.0.0
|
||||
url_launcher: ^6.3.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user