alist/internal/driver/driver.go

60 lines
1.7 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-06-07 14:02:41 +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-06-09 09:11:46 +00:00
// Init If already initialized, drop first
// need to unmarshal string to addition first
2022-07-10 06:45:39 +00:00
Init(ctx context.Context, storage model.Storage) error
2022-06-07 10:13:55 +00:00
Drop(ctx context.Context) error
2022-07-10 06:45:39 +00:00
// GetStorage just get raw storage
GetStorage() model.Storage
2022-06-08 08:20:58 +00:00
GetAddition() Additional
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
List(ctx context.Context, dir model.Obj) ([]model.Obj, error)
// 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 {
Get(ctx context.Context, path string) (model.Obj, error)
2022-06-06 13:48:53 +00:00
}
type Writer interface {
2022-06-15 12:31:23 +00:00
// MakeDir make a folder named `dirName` in `parentDir`
2022-06-15 12:41:17 +00:00
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error
2022-06-16 12:40:15 +00:00
// Move `srcObject` to `dstDir`
2022-06-15 12:41:17 +00:00
Move(ctx context.Context, srcObj, dstDir model.Obj) error
2022-06-15 12:31:23 +00:00
// Rename rename `srcObject` to `newName`
2022-06-15 12:41:17 +00:00
Rename(ctx context.Context, srcObj model.Obj, newName string) error
2022-06-16 12:40:15 +00:00
// Copy `srcObject` to `dstDir`
2022-06-15 12:41:17 +00:00
Copy(ctx context.Context, srcObj, dstDir model.Obj) error
2022-06-15 12:31:23 +00:00
// Remove remove `object`
2022-06-15 12:41:17 +00:00
Remove(ctx context.Context, obj model.Obj) error
2022-06-16 12:40:15 +00:00
// Put upload `stream` to `parentDir`
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
2022-06-18 12:06:45 +00:00
type UpdateProgress func(percentage int)