diff --git a/doc/quick_start.md b/doc/quick_start.md new file mode 100644 index 0000000..e69de29 diff --git a/log/log.go b/log/log.go index 97fec4e..af09e9e 100644 --- a/log/log.go +++ b/log/log.go @@ -41,9 +41,9 @@ func SetLogLevel(l string) { case "info": atom.SetLevel(zap.InfoLevel) Info("set log level to info") - case "warn", "warnning": + case "warn", "warning": atom.SetLevel(zap.WarnLevel) - Warn("set log level to warnning") + Warn("set log level to warning") case "error": atom.SetLevel(zap.ErrorLevel) Error("set log level to error") diff --git a/pkg/transmission/transmission.go b/pkg/transmission/transmission.go index 85b0a29..ca9034a 100644 --- a/pkg/transmission/transmission.go +++ b/pkg/transmission/transmission.go @@ -45,6 +45,22 @@ type Client struct { cfg Config } +func (c *Client) GetAll() ([]*Torrent, error) { + all, err := c.c.TorrentGetAll(context.TODO()) + if err != nil { + return nil, errors.Wrap(err, "get all") + } + var torrents []*Torrent + for _, t := range all { + torrents = append(torrents, &Torrent{ + ID: *t.ID, + c: c.c, + Config: c.cfg, + }) + } + return torrents, nil +} + func (c *Client) Download(link, dir string) (*Torrent, error) { if strings.HasPrefix(link, "http") { client := &http.Client{ diff --git a/server/activity.go b/server/activity.go index fa9e880..08ca63d 100644 --- a/server/activity.go +++ b/server/activity.go @@ -93,3 +93,33 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) { } return his, nil } + +type TorrentInfo struct { + Name string `json:"name"` + ID int64 `json:"id"` + SeedRatio float32 `json:"seed_ratio"` + Progress int `json:"progress"` +} + +func (s *Server) GetAllTorrents(c *gin.Context) (interface{}, error) { + trc, err := s.getDownloadClient() + if err != nil { + return nil, errors.Wrap(err, "connect transmission") + } + all, err := trc.GetAll() + if err != nil { + return nil, errors.Wrap(err, "get all") + } + var infos []TorrentInfo + for _, t := range all { + if !t.Exists() { + continue + } + infos = append(infos, TorrentInfo{ + Name: t.Name(), + ID: t.ID, + Progress: t.Progress(), + }) + } + return infos, nil +} diff --git a/server/core/torrent.go b/server/core/torrent.go index 01eb647..286a22c 100644 --- a/server/core/torrent.go +++ b/server/core/torrent.go @@ -110,10 +110,6 @@ 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) diff --git a/server/server.go b/server/server.go index 73ae84c..7c5114b 100644 --- a/server/server.go +++ b/server/server.go @@ -73,6 +73,7 @@ func (s *Server) Serve() error { activity.GET("/", HttpHandler(s.GetAllActivities)) activity.DELETE("/:id", HttpHandler(s.RemoveActivity)) activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory)) + activity.GET("/torrents", HttpHandler(s.GetAllTorrents)) } tv := api.Group("/media") diff --git a/ui/lib/settings.dart b/ui/lib/settings.dart index 43ba4b8..e84cd23 100644 --- a/ui/lib/settings.dart +++ b/ui/lib/settings.dart @@ -30,84 +30,82 @@ class _SystemSettingsPageState extends ConsumerState { 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("WARNING")), - 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"); - }); - } - }), - ), - ) - ], + return 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("WARNING")), + 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());