alist/internal/driver/driver.go

108 lines
2.5 KiB
Go
Raw Normal View History

2022-06-06 13:48:53 +00:00
package driver
import (
"context"
2022-06-15 10:06:42 +00:00
"github.com/alist-org/alist/v3/internal/model"
2022-06-06 13:48:53 +00:00
)
type Driver interface {
2022-06-07 14:02:41 +00:00
Meta
2022-06-06 13:48:53 +00:00
Reader
//Writer
2022-09-11 10:40:19 +00:00
//Other
2022-06-07 10:13:55 +00:00
}
2022-06-07 14:02:41 +00:00
type Meta interface {
2022-06-07 10:13:55 +00:00
Config() Config
2022-08-30 13:52:06 +00: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 13:52:06 +00:00
GetAddition() Additional
2022-06-09 09:11:46 +00:00
// Init If already initialized, drop first
Init(ctx context.Context) error
2022-06-07 10:13:55 +00:00
Drop(ctx context.Context) error
2022-06-06 13:48:53 +00:00
}
2022-06-07 14:02:41 +00:00
type Other interface {
2022-08-03 06:14:37 +00:00
Other(ctx context.Context, args model.OtherArgs) (interface{}, error)
2022-06-07 14:02:41 +00:00
}
2022-06-06 13:48:53 +00:00
type Reader interface {
2022-06-16 12:40:15 +00: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 12:41:17 +00:00
// if identify files by id, need to set ID with corresponding id
2022-08-11 12:32:17 +00:00
List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error)
2022-06-15 12:41:17 +00:00
// Link get url/filepath/reader of file
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
2022-06-28 14:13:47 +00:00
}
type Getter interface {
GetRoot(ctx context.Context) (model.Obj, error)
2022-06-06 13:48:53 +00:00
}
//type Writer interface {
// Mkdir
// Move
// Rename
// Copy
// Remove
// Put
//}
type Mkdir interface {
2022-06-15 12:41:17 +00:00
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error
}
type Move interface {
2022-06-15 12:41:17 +00:00
Move(ctx context.Context, srcObj, dstDir model.Obj) error
}
type Rename interface {
2022-06-15 12:41:17 +00:00
Rename(ctx context.Context, srcObj model.Obj, newName string) error
}
type Copy interface {
2022-06-15 12:41:17 +00:00
Copy(ctx context.Context, srcObj, dstDir model.Obj) error
}
type Remove interface {
2022-06-15 12:41:17 +00:00
Remove(ctx context.Context, obj model.Obj) error
}
type Put interface {
2022-06-20 14:29:52 +00:00
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) error
2022-06-06 13:48:53 +00:00
}
2022-06-17 13:23:44 +00: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 12:06:45 +00:00
type UpdateProgress func(percentage int)