feat: seprate tv and movie path

This commit is contained in:
Simon Ding
2024-07-17 00:00:20 +08:00
parent a87f4884bb
commit 0cd4a66f63
4 changed files with 55 additions and 31 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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")
}

View File

@@ -472,24 +472,26 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
Future<void> showStorageDetails(
AsyncSnapshot<void> snapshot, BuildContext context, Storage s) {
return showDialog<void>(
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<SystemSettingsPage> {
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<SystemSettingsPage> {
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<SystemSettingsPage> {
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