refactor: change driver interface
This commit is contained in:
5
internal/fs/fs.go
Normal file
5
internal/fs/fs.go
Normal file
@ -0,0 +1,5 @@
|
||||
package fs
|
||||
|
||||
// the param named path of functions in this package is a virtual path
|
||||
// So, the purpose of this package is to convert virtual path to actual path
|
||||
// then pass the actual path to the operations package
|
@ -15,7 +15,7 @@ import (
|
||||
// List files
|
||||
// TODO: hide
|
||||
// TODO: sort
|
||||
func List(ctx context.Context, path string) ([]model.FileInfo, error) {
|
||||
func List(ctx context.Context, path string) ([]model.Object, error) {
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
|
||||
if err != nil {
|
||||
@ -40,7 +40,7 @@ func List(ctx context.Context, path string) ([]model.FileInfo, error) {
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func Get(ctx context.Context, path string) (model.FileInfo, error) {
|
||||
func Get(ctx context.Context, path string) (model.Object, error) {
|
||||
path = utils.StandardizationPath(path)
|
||||
// maybe a virtual file
|
||||
if path != "/" {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func containsByName(files []model.FileInfo, file model.FileInfo) bool {
|
||||
func containsByName(files []model.Object, file model.Object) bool {
|
||||
for _, f := range files {
|
||||
if f.GetName() == file.GetName() {
|
||||
return true
|
||||
@ -23,7 +23,7 @@ func containsByName(files []model.FileInfo, file model.FileInfo) bool {
|
||||
|
||||
var httpClient = &http.Client{}
|
||||
|
||||
func getFileStreamFromLink(file model.FileInfo, link *model.Link) (model.FileStreamer, error) {
|
||||
func getFileStreamFromLink(file model.Object, link *model.Link) (model.FileStreamer, error) {
|
||||
var rc io.ReadCloser
|
||||
mimetype := mime.TypeByExtension(stdpath.Ext(file.GetName()))
|
||||
if link.Data != nil {
|
||||
@ -57,7 +57,7 @@ func getFileStreamFromLink(file model.FileInfo, link *model.Link) (model.FileStr
|
||||
mimetype = "application/octet-stream"
|
||||
}
|
||||
stream := model.FileStream{
|
||||
FileInfo: file,
|
||||
Object: file,
|
||||
ReadCloser: rc,
|
||||
Mimetype: mimetype,
|
||||
}
|
||||
|
Reference in New Issue
Block a user