mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
fix: moving file after complete
This commit is contained in:
@@ -73,5 +73,5 @@ func (l *LocalStorage) Move(src, dest string) error {
|
||||
|
||||
|
||||
func (l *LocalStorage) ReadDir(dir string) ([]fs.FileInfo, error) {
|
||||
return ioutil.ReadDir(dir)
|
||||
return ioutil.ReadDir(filepath.Join(l.dir, dir))
|
||||
}
|
||||
@@ -14,21 +14,23 @@ import (
|
||||
|
||||
type WebdavStorage struct {
|
||||
fs *gowebdav.Client
|
||||
dir string
|
||||
}
|
||||
|
||||
func NewWebdavStorage(url, user, password string) (*WebdavStorage, error) {
|
||||
func NewWebdavStorage(url, user, password, path string) (*WebdavStorage, error) {
|
||||
c := gowebdav.NewClient(url, user, password)
|
||||
if err := c.Connect(); err != nil {
|
||||
return nil, errors.Wrap(err, "connect webdav")
|
||||
}
|
||||
return &WebdavStorage{
|
||||
fs: c,
|
||||
dir: path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *WebdavStorage) Move(local, remote string) error {
|
||||
baseLocal := filepath.Base(local)
|
||||
remoteBase := filepath.Join(remote, baseLocal)
|
||||
remoteBase := filepath.Join(w.dir,remote, baseLocal)
|
||||
|
||||
log.Infof("remove all content in %s", remoteBase)
|
||||
w.fs.RemoveAll(remoteBase)
|
||||
@@ -79,5 +81,5 @@ func (w *WebdavStorage) Move(local, remote string) error {
|
||||
}
|
||||
|
||||
func (w *WebdavStorage) ReadDir(dir string) ([]fs.FileInfo, error) {
|
||||
return w.fs.ReadDir(dir)
|
||||
return w.fs.ReadDir(filepath.Join(w.dir, dir))
|
||||
}
|
||||
|
||||
@@ -61,27 +61,28 @@ func (s *Server) moveCompletedTask(id int) error {
|
||||
}
|
||||
st := s.db.GetStorage(series.StorageID)
|
||||
log.Infof("move task files to target dir: %v", r.TargetDir)
|
||||
var stImpl storage.Storage
|
||||
if st.Implementation == storage1.ImplementationWebdav {
|
||||
ws := st.ToWebDavSetting()
|
||||
storageImpl, err := storage.NewWebdavStorage(ws.Path, ws.User, ws.Password)
|
||||
storageImpl, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, ws.Path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new webdav")
|
||||
}
|
||||
if err := storageImpl.Move(filepath.Join(s.db.GetDownloadDir(), torrent.Name()), r.TargetDir); err != nil {
|
||||
return errors.Wrap(err, "move webdav")
|
||||
}
|
||||
stImpl = storageImpl
|
||||
|
||||
} else if st.Implementation == storage1.ImplementationLocal {
|
||||
ls := st.ToLocalSetting()
|
||||
storageImpl, err := storage.NewLocalStorage(ls.Path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new storage")
|
||||
}
|
||||
|
||||
if err := storageImpl.Move(filepath.Join(s.db.GetDownloadDir(), torrent.Name()), r.TargetDir); err != nil {
|
||||
return errors.Wrap(err, "move webdav")
|
||||
}
|
||||
stImpl = storageImpl
|
||||
|
||||
}
|
||||
if err := stImpl.Move(filepath.Join(s.db.GetDownloadDir(), torrent.Name()), r.TargetDir); err != nil {
|
||||
return errors.Wrap(err, "move file")
|
||||
}
|
||||
|
||||
log.Infof("move downloaded files to target dir success, file: %v, target dir: %v", torrent.Name(), r.TargetDir)
|
||||
torrent.Remove()
|
||||
delete(s.tasks, r.ID)
|
||||
@@ -102,11 +103,10 @@ func (s *Server) checkAllFiles() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) checkFileExists(series *ent.Series) error{
|
||||
func (s *Server) checkFileExists(series *ent.Series) error {
|
||||
log.Infof("check files in directory: %s", series.TargetDir)
|
||||
st := s.db.GetStorage(series.StorageID)
|
||||
|
||||
targetDir := filepath.Join(st.GetPath(), series.TargetDir)
|
||||
var storageImpl storage.Storage
|
||||
|
||||
switch st.Implementation {
|
||||
@@ -120,20 +120,20 @@ func (s *Server) checkFileExists(series *ent.Series) error{
|
||||
|
||||
case storage1.ImplementationWebdav:
|
||||
ws := st.ToWebDavSetting()
|
||||
storageImpl1, err := storage.NewWebdavStorage(ws.Path, ws.User, ws.Password)
|
||||
storageImpl1, err := storage.NewWebdavStorage(ws.URL, ws.User, ws.Password, ws.Path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new webdav")
|
||||
}
|
||||
storageImpl = storageImpl1
|
||||
}
|
||||
files, err := storageImpl.ReadDir(targetDir)
|
||||
}
|
||||
files, err := storageImpl.ReadDir(series.TargetDir)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "read dir %s", targetDir)
|
||||
return errors.Wrapf(err, "read dir %s", series.TargetDir)
|
||||
}
|
||||
numRe := regexp.MustCompile("[0-9]+")
|
||||
epRe := regexp.MustCompile("E[0-9]+")
|
||||
for _, in := range files {
|
||||
if !in.IsDir() {//season dir, ignore file
|
||||
if !in.IsDir() { //season dir, ignore file
|
||||
continue
|
||||
}
|
||||
nums := numRe.FindAllString(in.Name(), -1)
|
||||
@@ -170,4 +170,4 @@ func (s *Server) checkFileExists(series *ent.Series) error{
|
||||
type Task struct {
|
||||
Processing bool
|
||||
pkg.Torrent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ class MyApp extends StatelessWidget {
|
||||
final SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
await prefs.remove('token');
|
||||
context.go(LoginScreen.route);
|
||||
if (context.mounted) {
|
||||
context.go(LoginScreen.route);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.exit_to_app))
|
||||
: Container()
|
||||
@@ -115,22 +117,20 @@ class MyApp extends StatelessWidget {
|
||||
return ProviderScope(
|
||||
child: MaterialApp.router(
|
||||
title: 'Polaris',
|
||||
|
||||
theme: ThemeData(
|
||||
|
||||
// Define the default TextTheme. Use this to specify the default
|
||||
// text styling for headlines, titles, bodies of text, and more.
|
||||
// textTheme: const TextTheme(
|
||||
// bodyLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// bodyMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// bodySmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleSmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelSmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// ),
|
||||
// Define the default TextTheme. Use this to specify the default
|
||||
// text styling for headlines, titles, bodies of text, and more.
|
||||
// textTheme: const TextTheme(
|
||||
// bodyLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// bodyMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// bodySmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// titleSmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelLarge: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelMedium: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// labelSmall: TextStyle(fontFamilyFallback: ["PingFang SC", "Heiti SC"]),
|
||||
// ),
|
||||
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.blue, brightness: Brightness.dark),
|
||||
|
||||
Reference in New Issue
Block a user