|
package driver |
|
|
|
import ( |
|
"context" |
|
|
|
"github.com/alist-org/alist/v3/internal/model" |
|
) |
|
|
|
type Driver interface { |
|
Meta |
|
Reader |
|
|
|
|
|
} |
|
|
|
type Meta interface { |
|
Config() Config |
|
|
|
GetStorage() *model.Storage |
|
SetStorage(model.Storage) |
|
|
|
GetAddition() Additional |
|
|
|
Init(ctx context.Context) error |
|
Drop(ctx context.Context) error |
|
} |
|
|
|
type Other interface { |
|
Other(ctx context.Context, args model.OtherArgs) (interface{}, error) |
|
} |
|
|
|
type Offline interface { |
|
Offline(ctx context.Context, args model.OtherArgs) (interface{}, error) |
|
} |
|
|
|
type Reader interface { |
|
|
|
|
|
|
|
List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) |
|
|
|
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) |
|
} |
|
|
|
type GetRooter interface { |
|
GetRoot(ctx context.Context) (model.Obj, error) |
|
} |
|
|
|
type Getter interface { |
|
|
|
Get(ctx context.Context, path string) (model.Obj, error) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Mkdir interface { |
|
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error |
|
} |
|
|
|
type Move interface { |
|
Move(ctx context.Context, srcObj, dstDir model.Obj) error |
|
} |
|
|
|
type Rename interface { |
|
Rename(ctx context.Context, srcObj model.Obj, newName string) error |
|
} |
|
|
|
type Copy interface { |
|
Copy(ctx context.Context, srcObj, dstDir model.Obj) error |
|
} |
|
|
|
type Remove interface { |
|
Remove(ctx context.Context, obj model.Obj) error |
|
} |
|
|
|
type Put interface { |
|
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) error |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type MkdirResult interface { |
|
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) |
|
} |
|
|
|
type MoveResult interface { |
|
Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) |
|
} |
|
|
|
type RenameResult interface { |
|
Rename(ctx context.Context, srcObj model.Obj, newName string) (model.Obj, error) |
|
} |
|
|
|
type CopyResult interface { |
|
Copy(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) |
|
} |
|
|
|
type PutResult interface { |
|
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) (model.Obj, error) |
|
} |
|
|
|
type UpdateProgress func(percentage float64) |
|
|
|
type Progress struct { |
|
Total int64 |
|
Done int64 |
|
up UpdateProgress |
|
} |
|
|
|
func (p *Progress) Write(b []byte) (n int, err error) { |
|
n = len(b) |
|
p.Done += int64(n) |
|
p.up(float64(p.Done) / float64(p.Total) * 100) |
|
return |
|
} |
|
|
|
func NewProgress(total int64, up UpdateProgress) *Progress { |
|
return &Progress{ |
|
Total: total, |
|
up: up, |
|
} |
|
} |
|
|