Add resumable downloads, download paths, queue controls and history
This commit is contained in:
1 parent
434f6441da
commit
6027cfabb9
43 files changed
+2138
-291
No files matched your search
+15
-11
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"ddc/internal/files"
|
||||
"ddc/internal/libraries"
|
||||
)
|
||||
|
||||
type MoveRequest struct {
|
||||
@@ -29,19 +28,18 @@ func (manager *Manager) Move(id string, request MoveRequest) error {
|
||||
return invalid(errors.New("select at least one file or folder"))
|
||||
}
|
||||
|
||||
library, err := libraries.Resolve(manager.settings.LibraryRoots, request.Destination)
|
||||
target, err := manager.resolveTarget(request.Destination, request.Subfolder)
|
||||
if err != nil {
|
||||
return invalid(err)
|
||||
return err
|
||||
}
|
||||
subfolder, err := files.SanitizeSubfolder(request.Subfolder)
|
||||
if err != nil {
|
||||
return invalid(err)
|
||||
if target == nil {
|
||||
return invalid(errors.New("choose a destination"))
|
||||
}
|
||||
sources, err := resolveSources(job.directory, request.Paths)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destination, err := files.EnsureSubdirectory(library.Path, subfolder)
|
||||
destination, err := files.EnsureSubdirectory(target.destination, target.subfolder)
|
||||
if err != nil {
|
||||
return invalid(err)
|
||||
}
|
||||
@@ -49,12 +47,12 @@ func (manager *Manager) Move(id string, request MoveRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !job.begin(StatusReady, StatusMoving) {
|
||||
if !job.begin(StatusMoving, StatusReady) {
|
||||
return ErrJobBusy
|
||||
}
|
||||
go func() {
|
||||
defer job.workers.Done()
|
||||
manager.moveFiles(job, library, sources, destination, request.Cleanup)
|
||||
manager.moveFiles(job, sources, destination, request.Cleanup)
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
@@ -69,6 +67,9 @@ func resolveSources(root string, relativePaths []string) ([]string, error) {
|
||||
return nil, invalid(err)
|
||||
}
|
||||
name := filepath.Base(source)
|
||||
if files.IsInternal(name) {
|
||||
return nil, invalid(files.ErrUnsafePath)
|
||||
}
|
||||
if seenNames[name] {
|
||||
return nil, invalid(fmt.Errorf("more than one selected item is named %q", name))
|
||||
}
|
||||
@@ -96,7 +97,7 @@ func checkTargets(sources []string, destination string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *Manager) moveFiles(job *Job, library libraries.Destination, sources []string, destination string, cleanup bool) {
|
||||
func (manager *Manager) moveFiles(job *Job, sources []string, destination string, cleanup bool) {
|
||||
job.resetProgress()
|
||||
var totalBytes int64
|
||||
for _, source := range sources {
|
||||
@@ -106,14 +107,17 @@ func (manager *Manager) moveFiles(job *Job, library libraries.Destination, sourc
|
||||
}
|
||||
job.SetTotal(totalBytes)
|
||||
|
||||
movedNames := make([]string, 0, len(sources))
|
||||
defer func() { manager.recordHistory(job, destination, movedNames) }()
|
||||
for _, source := range sources {
|
||||
if err := files.MoveInto(source, destination, manager.reservedBytes(), job.Add); err != nil {
|
||||
job.setStatus(StatusReady, "Move failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
movedNames = append(movedNames, filepath.Base(source))
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("Moved %d item(s) to %s", len(sources), library.Path)
|
||||
message := fmt.Sprintf("Moved %d item(s) to %s", len(sources), destination)
|
||||
if !cleanup {
|
||||
job.setStatus(StatusReady, message)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user