8000 fix(ftp-server): rewrite download in a more appropriate method (#7656) · AlistGo/alist@b72e85a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b72e85a

Browse files
authored
fix(ftp-server): rewrite download in a more appropriate method (#7656)
1 parent 6aaf597 commit b72e85a

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

server/ftp/fsread.go

+7-37
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import (
66
"github.com/alist-org/alist/v3/internal/errs"
77
"github.com/alist-org/alist/v3/internal/fs"
88
"github.com/alist-org/alist/v3/internal/model"
9-
"github.com/alist-org/alist/v3/internal/net"
109
"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"
1311
"github.com/alist-org/alist/v3/server/common"
1412
"github.com/pkg/errors"
1513
"io"
@@ -21,8 +19,7 @@ import (
2119

2220
type FileDownloadProxy struct {
2321
ftpserver.FileTransfer
24-
reader io.ReadCloser
25-
closers *utils.Closers
22+
reader io.ReadCloser
2623
}
2724

2825
func OpenDownload(ctx context.Context, reqPath string) (*FileDownloadProxy, error) {
@@ -47,37 +44,15 @@ func OpenDownload(ctx context.Context, reqPath string) (*FileDownloadProxy, erro
4744
if err != nil {
4845
return nil, err
4946
}
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,
5650
}
57-
reader, closers, err := proxy(link)
51+
ss, err := stream.NewSeekableStream(fileStream, link)
5852
if err != nil {
5953
return nil, err
6054
}
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
8156
}
8257

8358
func (f *FileDownloadProxy) Read(p []byte) (n int, err error) {
@@ -93,11 +68,6 @@ func (f *FileDownloadProxy) Seek(offset int64, whence int) (int64, error) {
9368
}
9469

9570
func (f *FileDownloadProxy) Close() error {
96-
defer func() {
97-
if f.closers != nil {
98-
_ = f.closers.Close()
99-
}
100-
}()
10171
return f.reader.Close()
10272
}
10373

0 commit comments

Comments
 (0)
0