@@ -14,10 +14,11 @@ import (
14
14
"github.com/OpenListTeam/OpenList/v4/internal/op"
15
15
"github.com/OpenListTeam/OpenList/v4/internal/stream"
16
16
"github.com/OpenListTeam/OpenList/v4/internal/task"
17
+ "github.com/OpenListTeam/OpenList/v4/pkg/http_range"
17
18
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
19
+ "github.com/OpenListTeam/tache"
18
20
"github.com/pkg/errors"
19
21
log "github.com/sirupsen/logrus"
20
- "github.com/OpenListTeam/tache"
21
22
)
22
23
23
24
type TransferTask struct {
@@ -30,6 +31,7 @@ type TransferTask struct {
30
31
SrcStorageMp string `json:"src_storage_mp"`
31
32
DstStorageMp string `json:"dst_storage_mp"`
32
33
DeletePolicy DeletePolicy `json:"delete_policy"`
34
+ Url string `json:"-"`
33
35
}
34
36
35
37
func (t * TransferTask ) Run () error {
@@ -40,13 +42,42 @@ func (t *TransferTask) Run() error {
40
42
t .SetStartTime (time .Now ())
41
43
defer func () { t .SetEndTime (time .Now ()) }()
42
44
if t .SrcStorage == nil {
45
+ if t .DeletePolicy == UploadDownloadStream {
46
+ rrc , err := stream .GetRangeReadCloserFromLink (t .GetTotalBytes (), & model.Link {URL : t .Url })
47
+ if err != nil {
48
+ return err
49
+ }
50
+ r , err := rrc .RangeRead (t .Ctx (), http_range.Range {Length : t .GetTotalBytes ()})
51
+ if err != nil {
52
+ return err
53
+ }
54
+ name := t .SrcObjPath
55
+ mimetype := utils .GetMimeType (name )
56
+ s := & stream.FileStream {
57
+ Ctx : nil ,
58
+ Obj : & model.Object {
59
+ Name : name ,
60
+ Size : t .GetTotalBytes (),
61
+ Modified : time .Now (),
62
+ IsFolder : false ,
63
+ },
64
+ Reader : r ,
65
+ Mimetype : mimetype ,
66
+ Closers : utils .NewClosers (rrc ),
67
+ }
68
+ defer s .Close ()
69
+ return op .Put (t .Ctx (), t .DstStorage , t .DstDirPath , s , t .SetProgress )
70
+ }
43
71
return transferStdPath (t )
44
72
} else {
45
73
return transferObjPath (t )
46
74
}
47
75
}
48
76
49
77
func (t * TransferTask ) GetName () string {
78
+ if t .DeletePolicy == UploadDownloadStream {
79
+ return fmt .Sprintf ("upload [%s](%s) to [%s](%s)" , t .SrcObjPath , t .Url , t .DstStorageMp , t .DstDirPath )
80
+ }
50
81
return fmt .Sprintf ("transfer [%s](%s) to [%s](%s)" , t .SrcStorageMp , t .SrcObjPath , t .DstStorageMp , t .DstDirPath )
51
82
}
52
83
0 commit comments