@@ -6,10 +6,8 @@ import (
6
6
"github.com/alist-org/alist/v3/internal/errs"
7
7
"github.com/alist-org/alist/v3/internal/fs"
8
8
"github.com/alist-org/alist/v3/internal/model"
9
- "github.com/alist-org/alist/v3/internal/net"
10
9
"github.com/alist-org/alist/v3/internal/op"
11
- "github.com/alist-org/alist/v3/pkg/http_range"
12
- "github.com/alist-org/alist/v3/pkg/utils"
10
+ "github.com/alist-org/alist/v3/internal/stream"
13
11
"github.com/alist-org/alist/v3/server/common"
14
12
"github.com/pkg/errors"
15
13
"io"
@@ -21,8 +19,7 @@ import (
21
19
22
20
type FileDownloadProxy struct {
23
21
ftpserver.FileTransfer
24
- reader io.ReadCloser
25
- closers * utils.Closers
22
+ reader io.ReadCloser
26
23
}
27
24
28
25
func OpenDownload (ctx context.Context , reqPath string ) (* FileDownloadProxy , error ) {
@@ -47,37 +44,15 @@ func OpenDownload(ctx context.Context, reqPath string) (*FileDownloadProxy, erro
47
44
if err != nil {
48
45
return nil , err
49
46
}
50
- storage , err := fs .GetStorage (reqPath , & fs.GetStoragesArgs {})
51
- if err != nil {
52
- return nil , err
53
- }
54
- if storage .GetStorage ().ProxyRange {
55
- common .ProxyRange (link , obj .GetSize ())
47
+ fileStream := stream.FileStream {
48
+ Obj : obj ,
49
+ Ctx : ctx ,
56
50
}
57
- reader , closers , err := proxy ( link )
51
+ ss , err := stream . NewSeekableStream ( fileStream , link )
58
52
if err != nil {
59
53
return nil , err
60
54
}
61
- return & FileDownloadProxy {reader : reader , closers : closers }, nil
62
- }
63
-
64
- func proxy (link * model.Link ) (io.ReadCloser , * utils.Closers , error ) {
65
- if link .MFile != nil {
66
- return link .MFile , nil , nil
67
- } else if link .RangeReadCloser != nil {
68
- rc , err := link .RangeReadCloser .RangeRead (context .Background (), http_range.Range {Length : - 1 })
69
- if err != nil {
70
- return nil , nil , err
71
- }
72
- closers := link .RangeReadCloser .GetClosers ()
73
- return rc , & closers , nil
74
- } else {
75
- res , err := net .RequestHttp (context .Background (), http .MethodGet , link .Header , link .URL )
76
- if err != nil {
77
- return nil , nil , err
78
- }
79
- return res .Body , nil , nil
80
- }
55
+ return & FileDownloadProxy {reader : ss }, nil
81
56
}
82
57
83
58
func (f * FileDownloadProxy ) Read (p []byte ) (n int , err error ) {
@@ -93,11 +68,6 @@ func (f *FileDownloadProxy) Seek(offset int64, whence int) (int64, error) {
93
68
}
94
69
95
70
func (f * FileDownloadProxy ) Close () error {
96
- defer func () {
97
- if f .closers != nil {
98
- _ = f .closers .Close ()
99
- }
100
- }()
101
71
return f .reader .Close ()
102
72
}
103
73
0 commit comments