alist/internal/driver/driver.go

108 lines
2.5 KiB
Go
Raw Normal View History

2022-06-06 21:48:53 +08:00
package driver
import (
"context"
2022-06-15 18:06:42 +08:00
"github.com/alist-org/alist/v3/internal/model"
2022-06-06 21:48:53 +08:00
)
type Driver interface {
2022-06-07 22:02:41 +08:00
Meta
2022-06-06 21:48:53 +08:00
Reader
//Writer
2022-09-11 18:40:19 +08:00
//Other
2022-06-07 18:13:55 +08:00
}
2022-06-07 22:02:41 +08:00
type Meta interface {
2022-06-07 18:13:55 +08:00
Config() Config
2022-08-30 21:52:06 +08:00
// GetStorage just get raw storage, no need to implement, because model.Storage have implemented
GetStorage() *model.Storage
SetStorage(model.Storage)
// GetAddition Additional is used for unmarshal of JSON, so need return pointer
2022-08-30 21:52:06 +08:00
GetAddition() Additional
2022-06-09 17:11:46 +08:00
// Init If already initialized, drop first
Init(ctx context.Context) error
2022-06-07 18:13:55 +08:00
Drop(ctx context.Context) error
2022-06-06 21:48:53 +08:00
}
2022-06-07 22:02:41 +08:00
type Other interface {
2022-08-03 14:14:37 +08:00
Other(ctx context.Context, args model.OtherArgs) (interface{}, error)
2022-06-07 22:02:41 +08:00
}
2022-06-06 21:48:53 +08:00
type Reader interface {
2022-06-16 20:40:15 +08:00
// List files in the path
// if identify files by path, need to set ID with path,like path.Join(dir.GetID(), obj.GetName())
2022-06-15 20:41:17 +08:00
// if identify files by id, need to set ID with corresponding id
2022-08-11 20:32:17 +08:00
List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error)
2022-06-15 20:41:17 +08:00
// Link get url/filepath/reader of file
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
2022-06-28 22:13:47 +08:00
}
type Getter interface {
GetRoot(ctx context.Context) (model.Obj, error)
2022-06-06 21:48:53 +08:00
}
//type Writer interface {
// Mkdir
// Move
// Rename
// Copy
// Remove
// Put
//}
type Mkdir interface {
2022-06-15 20:41:17 +08:00
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error
}
type Move interface {
2022-06-15 20:41:17 +08:00
Move(ctx context.Context, srcObj, dstDir model.Obj) error
}
type Rename interface {
2022-06-15 20:41:17 +08:00
Rename(ctx context.Context, srcObj model.Obj, newName string) error
}
type Copy interface {
2022-06-15 20:41:17 +08:00
Copy(ctx context.Context, srcObj, dstDir model.Obj) error
}
type Remove interface {
2022-06-15 20:41:17 +08:00
Remove(ctx context.Context, obj model.Obj) error
}
type Put interface {
2022-06-20 22:29:52 +08:00
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) error
2022-06-06 21:48:53 +08:00
}
2022-06-17 21:23:44 +08:00
//type WriteResult interface {
// MkdirResult
// MoveResult
// RenameResult
// CopyResult
// PutResult
// Remove
//}
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)
}
2022-06-18 20:06:45 +08:00
type UpdateProgress func(percentage int)