diff --git a/db/db.go b/db/db.go index 39ca472..8dd3ee0 100644 --- a/db/db.go +++ b/db/db.go @@ -305,6 +305,21 @@ type StorageInfo struct { Default bool `json:"default"` } +func (s *StorageInfo) ToWebDavSetting() WebdavSetting { + if s.Implementation != storage.ImplementationWebdav.String() { + 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"], + ChangeFileHash: s.Settings["change_file_hash"], + } +} + + type LocalDirSetting struct { TvPath string `json:"tv_path"` MoviePath string `json:"movie_path"` diff --git a/server/storage.go b/server/storage.go index f342784..9cd64c8 100644 --- a/server/storage.go +++ b/server/storage.go @@ -4,6 +4,7 @@ import ( "fmt" "polaris/db" "polaris/log" + "polaris/pkg/storage" "polaris/pkg/utils" "strconv" "strings" @@ -23,6 +24,21 @@ func (s *Server) AddStorage(c *gin.Context) (interface{}, error) { return nil, errors.Wrap(err, "bind json") } + if in.Implementation == "webdav" { + //test webdav + wd := in.ToWebDavSetting() + st, err := storage.NewWebdavStorage(wd.URL, wd.User, wd.Password, wd.TvPath, false) + if err != nil { + return nil, errors.Wrap(err, "new webdav") + } + fs, err := st.ReadDir(".") + if err != nil { + return nil, errors.Wrap(err, "test read") + } + for _, f := range fs { + log.Infof("file name: %v", f.Name()) + } + } log.Infof("received add storage input: %v", in) err := s.db.AddStorage(&in) return nil, err