From 0cd4a66f6362ceff36ed94ca4455f442654f1162 Mon Sep 17 00:00:00 2001 From: Simon Ding Date: Wed, 17 Jul 2024 00:00:20 +0800 Subject: [PATCH] feat: seprate tv and movie path --- db/db.go | 16 +++++++------ pkg/transmission/transmission.go | 2 +- server/scheduler.go | 27 +++++++++++++++++---- ui/lib/system_settings.dart | 41 +++++++++++++++++--------------- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/db/db.go b/db/db.go index a7f3b8c..022dd33 100644 --- a/db/db.go +++ b/db/db.go @@ -274,14 +274,16 @@ type StorageInfo struct { } type LocalDirSetting struct { - Path string `json:"path"` + TvPath string `json:"tv_path"` + MoviePath string `json:"movie_path"` } type WebdavSetting struct { - URL string `json:"url"` - Path string `json:"path"` - User string `json:"user"` - Password string `json:"password"` + URL string `json:"url"` + TvPath string `json:"tv_path"` + MoviePath string `json:"movie_path"` + User string `json:"user"` + Password string `json:"password"` } func (c *Client) AddStorage(st *StorageInfo) error { @@ -343,10 +345,10 @@ func (s *Storage) ToWebDavSetting() WebdavSetting { return webdavSetting } -func (s *Storage) GetPath() string { +func (s *Storage) GetPath() (tvPath string, moviePath string) { var m map[string]string json.Unmarshal([]byte(s.Settings), &m) - return m["path"] + return m["tv_path"], m["movie_path"] } func (c *Client) GetStorage(id int) *Storage { diff --git a/pkg/transmission/transmission.go b/pkg/transmission/transmission.go index f324b71..3c8192e 100644 --- a/pkg/transmission/transmission.go +++ b/pkg/transmission/transmission.go @@ -55,7 +55,7 @@ func (c *Client) Download(magnet, dir string) (*Torrent, error) { type Torrent struct { //t *transmissionrpc.Torrent c *transmissionrpc.Client - ID int64 `json: "id"` + ID int64 `json:"id"` Config } diff --git a/server/scheduler.go b/server/scheduler.go index e806df6..501e629 100644 --- a/server/scheduler.go +++ b/server/scheduler.go @@ -85,7 +85,11 @@ func (s *Server) moveCompletedTask(id int) (err error) { var stImpl storage.Storage if st.Implementation == storage1.ImplementationWebdav { ws := st.ToWebDavSetting() - storageImpl, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, ws.Path) + targetPath := ws.TvPath + if series.MediaType == media.MediaTypeMovie { + targetPath = ws.MoviePath + } + storageImpl, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, targetPath) if err != nil { return errors.Wrap(err, "new webdav") } @@ -93,7 +97,12 @@ func (s *Server) moveCompletedTask(id int) (err error) { } else if st.Implementation == storage1.ImplementationLocal { ls := st.ToLocalSetting() - storageImpl, err := storage.NewLocalStorage(ls.Path) + targetPath := ls.TvPath + if series.MediaType == media.MediaTypeMovie { + targetPath = ls.MoviePath + } + + storageImpl, err := storage.NewLocalStorage(targetPath) if err != nil { return errors.Wrap(err, "new storage") } @@ -130,7 +139,12 @@ func (s *Server) checkFileExists(series *ent.Media) error { switch st.Implementation { case storage1.ImplementationLocal: ls := st.ToLocalSetting() - storageImpl1, err := storage.NewLocalStorage(ls.Path) + targetPath := ls.TvPath + if series.MediaType == media.MediaTypeMovie { + targetPath = ls.MoviePath + } + + storageImpl1, err := storage.NewLocalStorage(targetPath) if err != nil { return errors.Wrap(err, "new local") } @@ -138,7 +152,12 @@ func (s *Server) checkFileExists(series *ent.Media) error { case storage1.ImplementationWebdav: ws := st.ToWebDavSetting() - storageImpl1, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, ws.Path) + targetPath := ws.TvPath + if series.MediaType == media.MediaTypeMovie { + targetPath = ws.MoviePath + } + + storageImpl1, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, targetPath) if err != nil { return errors.Wrap(err, "new webdav") } diff --git a/ui/lib/system_settings.dart b/ui/lib/system_settings.dart index a8cb60b..95ee59e 100644 --- a/ui/lib/system_settings.dart +++ b/ui/lib/system_settings.dart @@ -472,24 +472,26 @@ class _SystemSettingsPageState extends ConsumerState { Future showStorageDetails( AsyncSnapshot snapshot, BuildContext context, Storage s) { - return showDialog( context: context, barrierDismissible: true, // user must tap button! builder: (BuildContext context) { var nameController = TextEditingController(text: s.name); - var pathController = TextEditingController(); + var tvPathController = TextEditingController(); + var moviePathController = TextEditingController(); var urlController = TextEditingController(); var userController = TextEditingController(); var passController = TextEditingController(); if (s.settings != null) { - pathController.text = s.settings!["path"]; - urlController.text = s.settings!["url"]; - userController.text = s.settings!["user"]; - passController.text = s.settings!["password"]; + 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"] ?? ""; } - String _selectImpl = s.implementation == null? "local": s.implementation!; + String _selectImpl = + s.implementation == null ? "local" : s.implementation!; return StatefulBuilder(builder: (context, setState) { return AlertDialog( title: const Text('存储'), @@ -513,12 +515,9 @@ class _SystemSettingsPageState extends ConsumerState { decoration: const InputDecoration(labelText: "名称"), controller: nameController, ), - _selectImpl == "local" - ? TextField( - decoration: const InputDecoration(labelText: "路径"), - controller: pathController, - ) - : Column( + _selectImpl != "local" + ? + Column( children: [ TextField( decoration: const InputDecoration( @@ -535,12 +534,15 @@ class _SystemSettingsPageState extends ConsumerState { const InputDecoration(labelText: "密码"), controller: passController, ), - TextField( - decoration: - const InputDecoration(labelText: "路径"), - controller: pathController, - ), ], + ): Container(), + TextField( + decoration: const InputDecoration(labelText: "电视剧路径"), + controller: tvPathController, + ), + TextField( + decoration: const InputDecoration(labelText: "电影路径"), + controller: moviePathController, ) ], ), @@ -573,7 +575,8 @@ class _SystemSettingsPageState extends ConsumerState { name: nameController.text, implementation: _selectImpl, settings: { - "path": pathController.text, + "tv_path": tvPathController.text, + "movie_path": moviePathController.text, "url": urlController.text, "user": userController.text, "password": passController.text