@@ -2,10 +2,11 @@ package op
22
33import (
44 "context"
5- stderrors "errors"
65 stdpath "path"
6+ "strconv"
77 "time"
88
9+ "github.com/OpenListTeam/OpenList/v4/internal/conf"
910 "github.com/OpenListTeam/OpenList/v4/internal/driver"
1011 "github.com/OpenListTeam/OpenList/v4/internal/errs"
1112 "github.com/OpenListTeam/OpenList/v4/internal/model"
@@ -14,6 +15,7 @@ import (
1415 "github.com/OpenListTeam/OpenList/v4/pkg/utils"
1516 "github.com/pkg/errors"
1617 log "github.com/sirupsen/logrus"
18+ "golang.org/x/time/rate"
1719)
1820
1921var listG singleflight.Group [[]model.Obj ]
@@ -310,7 +312,7 @@ func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string
310312 srcDirPath := stdpath .Dir (srcPath )
311313 dstDirPath = utils .FixAndCleanPath (dstDirPath )
312314 if dstDirPath == srcDirPath {
313- return stderrors .New ("move in place" )
315+ return errors .New ("move in place" )
314316 }
315317 srcRawObj , err := Get (ctx , storage , srcPath )
316318 if err != nil {
@@ -343,8 +345,24 @@ func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string
343345 }
344346 }
345347 default :
346- return errs .NotImplement
348+ err = errs .NotImplement
349+ }
350+
351+ if ! utils .IsBool (lazyCache ... ) && err == nil && needHandleObjsUpdateHook () {
352+ if ! srcObj .IsDir () {
353+ go List (context .Background (), storage , dstDirPath , model.ListArgs {Refresh : true })
354+ } else {
355+ targetPath := stdpath .Join (dstDirPath , srcObj .GetName ())
356+ var limiter * rate.Limiter
357+ if l , _ := GetSettingItemByKey (conf .HandleHookRateLimit ); l != nil {
358+ if f , e := strconv .ParseFloat (l .Value , 64 ); e == nil && f > .0 {
359+ limiter = rate .NewLimiter (rate .Limit (f ), 1 )
360+ }
361+ }
362+ go RecursivelyListStorage (context .Background (), storage , targetPath , limiter , nil )
363+ }
347364 }
365+
348366 return errors .WithStack (err )
349367}
350368
@@ -397,7 +415,7 @@ func Copy(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string
397415 srcPath = utils .FixAndCleanPath (srcPath )
398416 dstDirPath = utils .FixAndCleanPath (dstDirPath )
399417 if dstDirPath == stdpath .Dir (srcPath ) {
400- return stderrors .New ("copy in place" )
418+ return errors .New ("copy in place" )
401419 }
402420 srcRawObj , err := Get (ctx , storage , srcPath )
403421 if err != nil {
@@ -428,8 +446,24 @@ func Copy(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string
428446 }
429447 }
430448 default :
431- return errs .NotImplement
449+ err = errs .NotImplement
450+ }
451+
452+ if ! utils .IsBool (lazyCache ... ) && err == nil && needHandleObjsUpdateHook () {
453+ if ! srcObj .IsDir () {
454+ go List (context .Background (), storage , dstDirPath , model.ListArgs {Refresh : true })
455+ } else {
456+ targetPath := stdpath .Join (dstDirPath , srcObj .GetName ())
457+ var limiter * rate.Limiter
458+ if l , _ := GetSettingItemByKey (conf .HandleHookRateLimit ); l != nil {
459+ if f , e := strconv .ParseFloat (l .Value , 64 ); e == nil && f > .0 {
460+ limiter = rate .NewLimiter (rate .Limit (f ), 1 )
461+ }
462+ }
463+ go RecursivelyListStorage (context .Background (), storage , targetPath , limiter , nil )
464+ }
432465 }
466+
433467 return errors .WithStack (err )
434468}
435469
@@ -557,6 +591,9 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file mod
557591 err = Remove (ctx , storage , tempPath )
558592 }
559593 }
594+ if ! utils .IsBool (lazyCache ... ) && err == nil && needHandleObjsUpdateHook () {
595+ go List (context .Background (), storage , dstDirPath , model.ListArgs {Refresh : true })
596+ }
560597 return errors .WithStack (err )
561598}
562599
@@ -601,6 +638,9 @@ func PutURL(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url
601638 default :
602639 return errors .WithStack (errs .NotImplement )
603640 }
641+ if ! utils .IsBool (lazyCache ... ) && err == nil && needHandleObjsUpdateHook () {
642+ go List (context .Background (), storage , dstDirPath , model.ListArgs {Refresh : true })
643+ }
604644 log .Debugf ("put url [%s](%s) done" , dstName , url )
605645 return errors .WithStack (err )
606646}
@@ -644,3 +684,8 @@ func GetDirectUploadInfo(ctx context.Context, tool string, storage driver.Driver
644684 }
645685 return info , nil
646686}
687+
688+ func needHandleObjsUpdateHook () bool {
689+ needHandle , _ := GetSettingItemByKey (conf .HandleHookAfterWriting )
690+ return needHandle != nil && (needHandle .Value == "true" || needHandle .Value == "1" )
691+ }
0 commit comments