diff --git a/drivers/local/driver.go b/drivers/local/driver.go index e685fb1f..99a6cf21 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -68,9 +68,9 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([ } thumb := "" if d.Thumbnail && utils.GetFileType(f.Name()) == conf.IMAGE { - thumb = common.GetApiUrl(nil) + stdpath.Join("/d", args.ReqPath, f.Name()) + thumb = common.GetApiUrl(nil) + stdpath.Join("/d", utils.GetFullPath(d.MountPath, fullPath), f.Name()) thumb = utils.EncodePath(thumb, true) - thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(args.ReqPath, f.Name())) + thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(utils.GetFullPath(d.MountPath, fullPath), f.Name())) } isFolder := f.IsDir() || isSymlinkDir(f, fullPath) var size int64 diff --git a/internal/fs/list.go b/internal/fs/list.go index 51775efc..29ed0a57 100644 --- a/internal/fs/list.go +++ b/internal/fs/list.go @@ -23,7 +23,7 @@ func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error var _objs []model.Obj if storage != nil { _objs, err = op.List(ctx, storage, actualPath, model.ListArgs{ - ReqPath: path, + //ReqPath: path, }, refresh...) if err != nil { log.Errorf("%+v", err) diff --git a/internal/model/args.go b/internal/model/args.go index b3655476..b832ed8e 100644 --- a/internal/model/args.go +++ b/internal/model/args.go @@ -7,7 +7,7 @@ import ( ) type ListArgs struct { - ReqPath string + //ReqPath string } type LinkArgs struct { diff --git a/internal/model/obj.go b/internal/model/obj.go index e57b7c83..9d48e2e1 100644 --- a/internal/model/obj.go +++ b/internal/model/obj.go @@ -12,7 +12,7 @@ import ( "github.com/maruel/natural" ) -type UnwrapObj interface { +type ObjUnwrap interface { Unwrap() Obj } @@ -99,7 +99,6 @@ func ExtractFolder(objs []Obj, extractFolder string) { }) } -// Wrap func WrapObjName(objs Obj) Obj { return &ObjWrapName{Obj: objs} } @@ -110,8 +109,8 @@ func WrapObjsName(objs []Obj) { } } -func UnwrapObjs(obj Obj) Obj { - if unwrap, ok := obj.(UnwrapObj); ok { +func UnwrapObj(obj Obj) Obj { + if unwrap, ok := obj.(ObjUnwrap); ok { obj = unwrap.Unwrap() } return obj @@ -121,7 +120,7 @@ func GetThumb(obj Obj) (thumb string, ok bool) { if obj, ok := obj.(Thumb); ok { return obj.Thumb(), true } - if unwrap, ok := obj.(UnwrapObj); ok { + if unwrap, ok := obj.(ObjUnwrap); ok { return GetThumb(unwrap.Unwrap()) } return thumb, false @@ -131,7 +130,7 @@ func GetUrl(obj Obj) (url string, ok bool) { if obj, ok := obj.(URL); ok { return obj.URL(), true } - if unwrap, ok := obj.(UnwrapObj); ok { + if unwrap, ok := obj.(ObjUnwrap); ok { return GetUrl(unwrap.Unwrap()) } return url, false diff --git a/internal/op/fs.go b/internal/op/fs.go index f24214d7..1b74ad0b 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -130,9 +130,9 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li // call hooks go func(reqPath string, files []model.Obj) { for _, hook := range objsUpdateHooks { - hook(args.ReqPath, files) + hook(reqPath, files) } - }(args.ReqPath, files) + }(utils.GetFullPath(storage.GetStorage().MountPath, path), files) // sort objs if storage.Config().LocalSort { @@ -218,7 +218,7 @@ func GetUnwrap(ctx context.Context, storage driver.Driver, path string) (model.O if err != nil { return nil, err } - return model.UnwrapObjs(obj), err + return model.UnwrapObj(obj), err } var linkCache = cache.NewMemCache(cache.WithShards[*model.Link](16)) @@ -338,7 +338,7 @@ func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string if err != nil { return errors.WithMessage(err, "failed to get src object") } - srcObj := model.UnwrapObjs(srcRawObj) + srcObj := model.UnwrapObj(srcRawObj) dstDir, err := GetUnwrap(ctx, storage, dstDirPath) if err != nil { return errors.WithMessage(err, "failed to get dst dir") @@ -380,7 +380,7 @@ func Rename(ctx context.Context, storage driver.Driver, srcPath, dstName string, if err != nil { return errors.WithMessage(err, "failed to get src object") } - srcObj := model.UnwrapObjs(srcRawObj) + srcObj := model.UnwrapObj(srcRawObj) srcDirPath := stdpath.Dir(srcPath) switch s := storage.(type) { @@ -460,7 +460,7 @@ func Remove(ctx context.Context, storage driver.Driver, path string) error { switch s := storage.(type) { case driver.Remove: - err = s.Remove(ctx, model.UnwrapObjs(rawObj)) + err = s.Remove(ctx, model.UnwrapObj(rawObj)) if err == nil { delCacheObj(storage, dirPath, rawObj) } diff --git a/pkg/utils/balance.go b/pkg/utils/balance.go index e6df65c9..700d8c1c 100644 --- a/pkg/utils/balance.go +++ b/pkg/utils/balance.go @@ -9,10 +9,10 @@ func IsBalance(str string) bool { } // GetActualMountPath remove balance suffix -func GetActualMountPath(virtualPath string) string { - bIndex := strings.LastIndex(virtualPath, ".balance") +func GetActualMountPath(mountPath string) string { + bIndex := strings.LastIndex(mountPath, ".balance") if bIndex != -1 { - virtualPath = virtualPath[:bIndex] + mountPath = mountPath[:bIndex] } - return virtualPath + return mountPath } diff --git a/pkg/utils/path.go b/pkg/utils/path.go index 9bd42a11..1e3a8c4a 100644 --- a/pkg/utils/path.go +++ b/pkg/utils/path.go @@ -80,3 +80,7 @@ func JoinBasePath(basePath, reqPath string) (string, error) { } return stdpath.Join(FixAndCleanPath(basePath), FixAndCleanPath(reqPath)), nil } + +func GetFullPath(mountPath, path string) string { + return stdpath.Join(GetActualMountPath(mountPath), path) +}