feat: local storage image thumbnail
This commit is contained in:
@ -32,7 +32,7 @@ type Reader interface {
|
||||
// List files in the path
|
||||
// if identify files by path, need to set ID with path,like path.Join(dir.GetID(), obj.GetName())
|
||||
// if identify files by id, need to set ID with corresponding id
|
||||
List(ctx context.Context, dir model.Obj) ([]model.Obj, error)
|
||||
List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error)
|
||||
// Link get url/filepath/reader of file
|
||||
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Dr
|
||||
}
|
||||
if srcObj.IsDir() {
|
||||
t.SetStatus("src object is dir, listing objs")
|
||||
objs, err := operations.List(t.Ctx, srcStorage, srcObjPath)
|
||||
objs, err := operations.List(t.Ctx, srcStorage, srcObjPath, model.ListArgs{})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath)
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ func list(ctx context.Context, path string) ([]model.Obj, error) {
|
||||
}
|
||||
return nil, errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
objs, err := operations.List(ctx, storage, actualPath)
|
||||
objs, err := operations.List(ctx, storage, actualPath, model.ListArgs{
|
||||
ReqPath: path,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("%+v", err)
|
||||
if len(virtualFiles) != 0 {
|
||||
|
@ -6,9 +6,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ListArgs struct {
|
||||
ReqPath string
|
||||
}
|
||||
|
||||
type LinkArgs struct {
|
||||
IP string
|
||||
Header http.Header
|
||||
Type string
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
|
@ -28,8 +28,8 @@ type URL interface {
|
||||
URL() string
|
||||
}
|
||||
|
||||
type Thumbnail interface {
|
||||
Thumbnail() string
|
||||
type Thumb interface {
|
||||
Thumb() string
|
||||
}
|
||||
|
||||
type SetID interface {
|
||||
|
@ -10,26 +10,39 @@ type Object struct {
|
||||
IsFolder bool
|
||||
}
|
||||
|
||||
func (f Object) GetName() string {
|
||||
return f.Name
|
||||
func (o Object) GetName() string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (f Object) GetSize() int64 {
|
||||
return f.Size
|
||||
func (o Object) GetSize() int64 {
|
||||
return o.Size
|
||||
}
|
||||
|
||||
func (f Object) ModTime() time.Time {
|
||||
return f.Modified
|
||||
func (o Object) ModTime() time.Time {
|
||||
return o.Modified
|
||||
}
|
||||
|
||||
func (f Object) IsDir() bool {
|
||||
return f.IsFolder
|
||||
func (o Object) IsDir() bool {
|
||||
return o.IsFolder
|
||||
}
|
||||
|
||||
func (f Object) GetID() string {
|
||||
return f.ID
|
||||
func (o Object) GetID() string {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (f *Object) SetID(id string) {
|
||||
f.ID = id
|
||||
func (o *Object) SetID(id string) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
type Thumbnail struct {
|
||||
Thumbnail string
|
||||
}
|
||||
|
||||
func (t Thumbnail) Thumb() string {
|
||||
return t.Thumbnail
|
||||
}
|
||||
|
||||
type ObjectThumbnail struct {
|
||||
Object
|
||||
Thumbnail
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func ClearCache(storage driver.Driver, path string) {
|
||||
}
|
||||
|
||||
// List files in storage, not contains virtual file
|
||||
func List(ctx context.Context, storage driver.Driver, path string, refresh ...bool) ([]model.Obj, error) {
|
||||
func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs, refresh ...bool) ([]model.Obj, error) {
|
||||
path = utils.StandardizePath(path)
|
||||
log.Debugf("operations.List %s", path)
|
||||
dir, err := Get(ctx, storage, path)
|
||||
@ -39,7 +39,7 @@ func List(ctx context.Context, storage driver.Driver, path string, refresh ...bo
|
||||
return nil, errors.WithStack(errs.NotFolder)
|
||||
}
|
||||
if storage.Config().NoCache {
|
||||
return storage.List(ctx, dir)
|
||||
return storage.List(ctx, dir, args)
|
||||
}
|
||||
key := stdpath.Join(storage.GetStorage().MountPath, path)
|
||||
if len(refresh) == 0 || !refresh[0] {
|
||||
@ -48,7 +48,7 @@ func List(ctx context.Context, storage driver.Driver, path string, refresh ...bo
|
||||
}
|
||||
}
|
||||
files, err, _ := filesG.Do(key, func() ([]model.Obj, error) {
|
||||
files, err := storage.List(ctx, dir)
|
||||
files, err := storage.List(ctx, dir, args)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "failed to list files")
|
||||
}
|
||||
@ -99,7 +99,7 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
|
||||
}
|
||||
// not root folder
|
||||
dir, name := stdpath.Split(path)
|
||||
files, err := List(ctx, storage, dir)
|
||||
files, err := List(ctx, storage, dir, model.ListArgs{})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "failed get parent list")
|
||||
}
|
||||
@ -148,7 +148,7 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
return link, file, err
|
||||
}
|
||||
|
||||
// other api
|
||||
// Other api
|
||||
func Other(ctx context.Context, storage driver.Driver, args model.FsOtherArgs) (interface{}, error) {
|
||||
obj, err := Get(ctx, storage, args.Path)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user