@@ -229,6 +229,15 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
229229 for _ , obj := range objMap {
230230 objs = append (objs , obj )
231231 }
232+ if d .OrderBy == "" {
233+ sort := getAllSort (dirs )
234+ if sort .OrderBy != "" {
235+ model .SortFiles (objs , sort .OrderBy , sort .OrderDirection )
236+ }
237+ if d .ExtractFolder == "" && sort .ExtractFolder != "" {
238+ model .ExtractFolder (objs , sort .ExtractFolder )
239+ }
240+ }
232241 return objs , nil
233242}
234243
@@ -276,21 +285,38 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
276285 }, nil
277286 }
278287
279- reqPath := d .getBalancedPath (ctx , file )
280- link , fi , err := d .link (ctx , reqPath , args )
288+ var link * model.Link
289+ var fi model.Obj
290+ var err error
291+ files := file .(BalancedObjs )
292+ if d .ReadConflictPolicy == RandomBalancedRP || d .ReadConflictPolicy == AllRWP {
293+ rand .Shuffle (len (files ), func (i , j int ) {
294+ files [i ], files [j ] = files [j ], files [i ]
295+ })
296+ }
297+ for _ , f := range files {
298+ if f == nil {
299+ continue
300+ }
301+ link , fi , err = d .link (ctx , f .GetPath (), args )
302+ if err == nil {
303+ if link == nil {
304+ // 重定向且需要通过代理
305+ return & model.Link {
306+ URL : fmt .Sprintf ("%s/p%s?sign=%s" ,
307+ common .GetApiUrl (ctx ),
308+ utils .EncodePath (f .GetPath (), true ),
309+ sign .Sign (f .GetPath ())),
310+ }, nil
311+ }
312+ break
313+ }
314+ }
281315 if err != nil {
282316 return nil , err
283317 }
284- if link == nil {
285- // 重定向且需要通过代理
286- return & model.Link {
287- URL : fmt .Sprintf ("%s/p%s?sign=%s" ,
288- common .GetApiUrl (ctx ),
289- utils .EncodePath (reqPath , true ),
290- sign .Sign (reqPath )),
291- }, nil
292- }
293318 resultLink := * link // 复制一份,避免修改到原始link
319+ resultLink .Expiration = nil
294320 resultLink .SyncClosers = utils .NewSyncClosers (link )
295321 if args .Redirect {
296322 return & resultLink , nil
0 commit comments