Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit cc01b41

Browse files
j2rong4cnCopilot
andauthored
perf(link): optimize concurrent response (#641)
* fix(crypt): bug caused by link cache * perf(crypt,mega,halalcloud,quark,uc): optimize concurrent response link * chore: 删除无用代码 * ftp * 修复bug;资源释放 * 添加SyncClosers * local,sftp,smb * 重构,优化,增强 * Update internal/stream/util.go Co-authored-by: Copilot <[email protected]> Signed-off-by: j2rong4cn <[email protected]> * chore * chore * 优化,修复bug * . --------- Signed-off-by: j2rong4cn <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent e5fbe72 commit cc01b41

File tree

83 files changed

+785
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+785
-740
lines changed

drivers/115/meta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var config = driver.Config{
1818
Name: "115 Cloud",
1919
DefaultRoot: "0",
2020
// OnlyProxy: true,
21-
// OnlyLocal: true,
2221
// NoOverwriteUpload: true,
2322
}
2423

drivers/115_open/meta.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@ type Addition struct {
1111
// define other
1212
OrderBy string `json:"order_by" type:"select" options:"file_name,file_size,user_utime,file_type"`
1313
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"`
14-
LimitRate float64 `json:"limit_rate" type:"float" default:"1" help:"limit all api request rate ([limit]r/1s)"`
14+
LimitRate float64 `json:"limit_rate" type:"float" default:"1" help:"limit all api request rate ([limit]r/1s)"`
1515
AccessToken string `json:"access_token" required:"true"`
1616
RefreshToken string `json:"refresh_token" required:"true"`
1717
}
1818

1919
var config = driver.Config{
20-
Name: "115 Open",
21-
LocalSort: false,
22-
OnlyLocal: false,
23-
OnlyProxy: false,
24-
NoCache: false,
25-
NoUpload: false,
26-
NeedMs: false,
27-
DefaultRoot: "0",
28-
CheckStatus: false,
29-
Alert: "",
30-
NoOverwriteUpload: false,
20+
Name: "115 Open",
21+
DefaultRoot: "0",
3122
}
3223

3324
func init() {

drivers/115_share/meta.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ type Addition struct {
1919
var config = driver.Config{
2020
Name: "115 Share",
2121
DefaultRoot: "0",
22-
// OnlyProxy: true,
23-
// OnlyLocal: true,
24-
CheckStatus: false,
25-
Alert: "",
26-
NoOverwriteUpload: true,
27-
NoUpload: true,
22+
NoUpload: true,
2823
}
2924

3025
func init() {

drivers/123_share/meta.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@ type Addition struct {
1515
}
1616

1717
var config = driver.Config{
18-
Name: "123PanShare",
19-
LocalSort: true,
20-
OnlyLocal: false,
21-
OnlyProxy: false,
22-
NoCache: false,
23-
NoUpload: true,
24-
NeedMs: false,
25-
DefaultRoot: "0",
26-
CheckStatus: false,
27-
Alert: "",
28-
NoOverwriteUpload: false,
18+
Name: "123PanShare",
19+
LocalSort: true,
20+
NoUpload: true,
21+
DefaultRoot: "0",
2922
}
3023

3124
func init() {

drivers/alias/driver.go

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package alias
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
stdpath "path"
89
"strings"
@@ -11,8 +12,10 @@ import (
1112
"github.com/OpenListTeam/OpenList/v4/internal/errs"
1213
"github.com/OpenListTeam/OpenList/v4/internal/fs"
1314
"github.com/OpenListTeam/OpenList/v4/internal/model"
15+
"github.com/OpenListTeam/OpenList/v4/internal/sign"
1416
"github.com/OpenListTeam/OpenList/v4/internal/stream"
1517
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
18+
"github.com/OpenListTeam/OpenList/v4/server/common"
1619
)
1720

1821
type Alias struct {
@@ -111,21 +114,43 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
111114
return nil, errs.ObjectNotFound
112115
}
113116
for _, dst := range dsts {
114-
link, err := d.link(ctx, dst, sub, args)
115-
if err == nil {
116-
link.Expiration = nil // 去除非必要缓存,d.link里op.Lin有缓存
117-
if !args.Redirect && len(link.URL) > 0 {
118-
// 正常情况下 多并发 仅支持返回URL的驱动
119-
// alias套娃alias 可以让crypt、mega等驱动(不返回URL的) 支持并发
120-
if d.DownloadConcurrency > 0 {
121-
link.Concurrency = d.DownloadConcurrency
122-
}
123-
if d.DownloadPartSize > 0 {
124-
link.PartSize = d.DownloadPartSize * utils.KB
117+
reqPath := stdpath.Join(dst, sub)
118+
link, file, err := d.link(ctx, reqPath, args)
119+
if err != nil {
120+
continue
121+
}
122+
var resultLink *model.Link
123+
if link != nil {
124+
resultLink = &model.Link{
125+
URL: link.URL,
126+
Header: link.Header,
127+
RangeReader: link.RangeReader,
128+
SyncClosers: utils.NewSyncClosers(link),
129+
}
130+
if link.MFile != nil {
131+
resultLink.RangeReader = &model.FileRangeReader{
132+
RangeReaderIF: stream.GetRangeReaderFromMFile(file.GetSize(), link.MFile),
125133
}
126134
}
127-
return link, nil
135+
136+
} else {
137+
resultLink = &model.Link{
138+
URL: fmt.Sprintf("%s/p%s?sign=%s",
139+
common.GetApiUrl(ctx),
140+
utils.EncodePath(reqPath, true),
141+
sign.Sign(reqPath)),
142+
}
143+
144+
}
145+
if !args.Redirect {
146+
if d.DownloadConcurrency > 0 {
147+
resultLink.Concurrency = d.DownloadConcurrency
148+
}
149+
if d.DownloadPartSize > 0 {
150+
resultLink.PartSize = d.DownloadPartSize * utils.KB
151+
}
128152
}
153+
return resultLink, nil
129154
}
130155
return nil, errs.ObjectNotFound
131156
}
@@ -251,9 +276,13 @@ func (d *Alias) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer,
251276
reqPath, err := d.getReqPath(ctx, dstDir, true)
252277
if err == nil {
253278
if len(reqPath) == 1 {
254-
return fs.PutDirectly(ctx, *reqPath[0], s)
279+
return fs.PutDirectly(ctx, *reqPath[0], &stream.FileStream{
280+
Obj: s,
281+
Mimetype: s.GetMimetype(),
282+
WebPutAsTask: s.NeedStore(),
283+
Reader: s,
284+
})
255285
} else {
256-
defer s.Close()
257286
file, err := s.CacheFullInTempFile()
258287
if err != nil {
259288
return err
@@ -338,14 +367,6 @@ func (d *Alias) Extract(ctx context.Context, obj model.Obj, args model.ArchiveIn
338367
for _, dst := range dsts {
339368
link, err := d.extract(ctx, dst, sub, args)
340369
if err == nil {
341-
if !args.Redirect && len(link.URL) > 0 {
342-
if d.DownloadConcurrency > 0 {
343-
link.Concurrency = d.DownloadConcurrency
344-
}
345-
if d.DownloadPartSize > 0 {
346-
link.PartSize = d.DownloadPartSize * utils.KB
347-
}
348-
}
349370
return link, nil
350371
}
351372
}

drivers/alias/util.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,37 +96,23 @@ func (d *Alias) list(ctx context.Context, dst, sub string, args *fs.ListArgs) ([
9696
})
9797
}
9898

99-
func (d *Alias) link(ctx context.Context, dst, sub string, args model.LinkArgs) (*model.Link, error) {
100-
reqPath := stdpath.Join(dst, sub)
101-
// 参考 crypt 驱动
99+
func (d *Alias) link(ctx context.Context, reqPath string, args model.LinkArgs) (*model.Link, model.Obj, error) {
102100
storage, reqActualPath, err := op.GetStorageAndActualPath(reqPath)
103101
if err != nil {
104-
return nil, err
105-
}
106-
useRawLink := len(common.GetApiUrl(ctx)) == 0 // ftp、s3
107-
if !useRawLink {
108-
_, ok := storage.(*Alias)
109-
useRawLink = !ok && !args.Redirect
102+
return nil, nil, err
110103
}
111-
if useRawLink {
112-
link, _, err := op.Link(ctx, storage, reqActualPath, args)
113-
return link, err
104+
// proxy || ftp,s3
105+
if !args.Redirect || len(common.GetApiUrl(ctx)) == 0 {
106+
return op.Link(ctx, storage, reqActualPath, args)
114107
}
115-
_, err = fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true})
108+
obj, err := fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true})
116109
if err != nil {
117-
return nil, err
110+
return nil, nil, err
118111
}
119-
if common.ShouldProxy(storage, stdpath.Base(sub)) {
120-
link := &model.Link{
121-
URL: fmt.Sprintf("%s/p%s?sign=%s",
122-
common.GetApiUrl(ctx),
123-
utils.EncodePath(reqPath, true),
124-
sign.Sign(reqPath)),
125-
}
126-
return link, nil
112+
if common.ShouldProxy(storage, stdpath.Base(reqPath)) {
113+
return nil, obj, nil
127114
}
128-
link, _, err := op.Link(ctx, storage, reqActualPath, args)
129-
return link, err
115+
return op.Link(ctx, storage, reqActualPath, args)
130116
}
131117

132118
func (d *Alias) getReqPath(ctx context.Context, obj model.Obj, isParent bool) ([]*string, error) {

drivers/aliyundrive/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (d *AliDrive) Remove(ctx context.Context, obj model.Obj) error {
165165
}
166166

167167
func (d *AliDrive) Put(ctx context.Context, dstDir model.Obj, streamer model.FileStreamer, up driver.UpdateProgress) error {
168-
file := stream.FileStream{
168+
file := &stream.FileStream{
169169
Obj: streamer,
170170
Reader: streamer,
171171
Mimetype: streamer.GetMimetype(),
@@ -209,7 +209,7 @@ func (d *AliDrive) Put(ctx context.Context, dstDir model.Obj, streamer model.Fil
209209
io.Closer
210210
}{
211211
Reader: io.MultiReader(buf, file),
212-
Closer: &file,
212+
Closer: file,
213213
}
214214
}
215215
} else {

drivers/aliyundrive_open/meta.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ type Addition struct {
2525

2626
var config = driver.Config{
2727
Name: "AliyundriveOpen",
28-
LocalSort: false,
29-
OnlyLocal: false,
30-
OnlyProxy: false,
31-
NoCache: false,
32-
NoUpload: false,
33-
NeedMs: false,
3428
DefaultRoot: "root",
3529
NoOverwriteUpload: true,
3630
}

drivers/chaoxing/meta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func init() {
3232
config: driver.Config{
3333
Name: "ChaoXingGroupDrive",
3434
OnlyProxy: true,
35-
OnlyLocal: false,
3635
DefaultRoot: "-1",
3736
NoOverwriteUpload: true,
3837
},

drivers/cloudreve_v4/meta.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ type Addition struct {
2626

2727
var config = driver.Config{
2828
Name: "Cloudreve V4",
29-
LocalSort: false,
30-
OnlyLocal: false,
31-
OnlyProxy: false,
32-
NoCache: false,
33-
NoUpload: false,
34-
NeedMs: false,
3529
DefaultRoot: "cloudreve://my",
3630
CheckStatus: true,
37-
Alert: "",
3831
NoOverwriteUpload: true,
3932
}
4033

0 commit comments

Comments
 (0)