alist/internal/driver/driver.go

61 lines
1.9 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-06-07 22:02:41 +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
// GetAddition Additional can't be modified externally, so needn't return pointer
GetAddition() Additional
2022-06-09 17:11:46 +08:00
// Init If already initialized, drop first
// need to unmarshal string to addition first
2022-07-10 14:45:39 +08:00
Init(ctx context.Context, storage model.Storage) 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 {
Get(ctx context.Context, path string) (model.Obj, error)
2022-06-06 21:48:53 +08:00
}
type Writer interface {
2022-06-15 20:31:23 +08:00
// MakeDir make a folder named `dirName` in `parentDir`
2022-06-15 20:41:17 +08:00
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error
2022-06-16 20:40:15 +08:00
// Move `srcObject` to `dstDir`
2022-06-15 20:41:17 +08:00
Move(ctx context.Context, srcObj, dstDir model.Obj) error
2022-06-15 20:31:23 +08:00
// Rename rename `srcObject` to `newName`
2022-06-15 20:41:17 +08:00
Rename(ctx context.Context, srcObj model.Obj, newName string) error
2022-06-16 20:40:15 +08:00
// Copy `srcObject` to `dstDir`
2022-06-15 20:41:17 +08:00
Copy(ctx context.Context, srcObj, dstDir model.Obj) error
2022-06-15 20:31:23 +08:00
// Remove remove `object`
2022-06-15 20:41:17 +08:00
Remove(ctx context.Context, obj model.Obj) error
2022-06-16 20:40:15 +08:00
// Put upload `stream` to `parentDir`
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
2022-06-18 20:06:45 +08:00
type UpdateProgress func(percentage int)