@@ -3,6 +3,7 @@ package alias
33import (
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
1821type 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 }
0 commit comments