🚧 webdav write interface

This commit is contained in:
微凉
2021-12-05 15:22:19 +08:00
parent 809850321a
commit 9c5627a382
16 changed files with 347 additions and 99 deletions

View File

@ -135,11 +135,11 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
if file.Type != conf.FOLDER {
return &file, err
} else {
return nil, NotFile
return nil, ErrNotFile
}
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func init() {

View File

@ -25,34 +25,34 @@ func (driver Pan123) Items() []Item {
{
Name: "username",
Label: "username",
Type: "string",
Type: TypeString,
Required: true,
Description: "account username/phone number",
},
{
Name: "password",
Label: "password",
Type: "string",
Type: TypeString,
Required: true,
Description: "account password",
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: "string",
Type: TypeString,
Required: false,
},
{
Name: "order_by",
Label: "order_by",
Type: "select",
Type: TypeSelect,
Values: "name,fileId,updateAt,createAt",
Required: true,
},
{
Name: "order_direction",
Label: "order_direction",
Type: "select",
Type: TypeSelect,
Values: "asc,desc",
Required: true,
},
@ -89,7 +89,7 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
@ -186,7 +186,27 @@ func (driver Pan123) Proxy(c *gin.Context, account *model.Account) {
}
func (driver Pan123) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver Pan123) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Pan123) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Pan123) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Pan123) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Pan123) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*Pan123)(nil)

View File

@ -62,11 +62,11 @@ func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
// if file.Size != -1 {
// return &file, err
// } else {
// return nil, NotFile
// return nil, ErrNotFile
// }
// }
// }
// return nil, PathNotFound
// return nil, ErrPathNotFound
//}
type Cloud189Down struct {

View File

@ -24,34 +24,34 @@ func (driver Cloud189) Items() []Item {
{
Name: "username",
Label: "username",
Type: "string",
Type: TypeString,
Required: true,
Description: "account username/phone number",
},
{
Name: "password",
Label: "password",
Type: "string",
Type: TypeString,
Required: true,
Description: "account password",
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "order_by",
Label: "order_by",
Type: "select",
Type: TypeSelect,
Values: "name,size,lastOpTime,createdDate",
Required: true,
},
{
Name: "order_direction",
Label: "desc",
Type: "select",
Type: TypeSelect,
Values: "true,false",
Required: true,
},
@ -97,7 +97,7 @@ func (driver Cloud189) File(path string, account *model.Account) (*model.File, e
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) {
@ -132,7 +132,7 @@ func (driver Cloud189) Link(path string, account *model.Account) (string, error)
return "", err
}
if file.Type == conf.FOLDER {
return "", NotFile
return "", ErrNotFile
}
client, ok := client189Map[account.Name]
if !ok {
@ -194,7 +194,28 @@ func (driver Cloud189) Proxy(ctx *gin.Context, account *model.Account) {
}
func (driver Cloud189) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver Cloud189) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Cloud189) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Cloud189) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Cloud189) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*Cloud189)(nil)

View File

@ -25,33 +25,33 @@ func (driver AliDrive) Items() []Item {
{
Name: "order_by",
Label: "order_by",
Type: "select",
Type: TypeSelect,
Values: "name,size,updated_at,created_at",
Required: false,
},
{
Name: "order_direction",
Label: "order_direction",
Type: "select",
Type: TypeSelect,
Values: "ASC,DESC",
Required: false,
},
{
Name: "refresh_token",
Label: "refresh token",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: "string",
Type: TypeString,
Required: false,
},
{
Name: "limit",
Label: "limit",
Type: "number",
Type: TypeNumber,
Required: false,
Description: ">0 and <=200",
},
@ -123,7 +123,7 @@ func (driver AliDrive) File(path string, account *model.Account) (*model.File, e
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver AliDrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -233,7 +233,7 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
req["category"] = "live_transcoding"
}
default:
return nil, NotSupport
return nil, ErrNotSupport
}
_, err = aliClient.R().SetResult(&resp).SetError(&e).
SetHeader("authorization", "Bearer\t"+account.AccessToken).
@ -247,4 +247,24 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
return resp, nil
}
func (driver AliDrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver AliDrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver AliDrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver AliDrive) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*AliDrive)(nil)

View File

@ -127,7 +127,7 @@ func (driver AliDrive) GetFile(path string, account *model.Account) (*AliFile, e
}
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver AliDrive) RefreshToken(account *model.Account) error {

View File

@ -25,10 +25,11 @@ type Driver interface {
Preview(path string, account *model.Account) (interface{}, error)
// TODO
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
//MakeDir(path string, account *model.Account) error
//Move(src string, des string, account *model.Account) error
//Delete(path string) error
//Upload(file *fs.File, path string, account *model.Account) error
MakeDir(path string, account *model.Account) error
Move(src string, dst string, account *model.Account) error
Copy(src string, dst string, account *model.Account) error
Delete(path string, account *model.Account) error
Upload(file *model.FileStream, account *model.Account) error
}
type Item struct {

View File

@ -24,25 +24,25 @@ func (driver GoogleDrive) Items() []Item {
{
Name: "client_id",
Label: "client id",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "client_secret",
Label: "client secret",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "refresh_token",
Label: "refresh token",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: "string",
Type: TypeString,
Required: false,
},
}
@ -86,7 +86,7 @@ func (driver GoogleDrive) File(path string, account *model.Account) (*model.File
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -121,7 +121,7 @@ func (driver GoogleDrive) Link(path string, account *model.Account) (string, err
return "", err
}
if file.Type == conf.FOLDER {
return "", NotFile
return "", ErrNotFile
}
link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id)
var e GoogleError
@ -165,7 +165,27 @@ func (driver GoogleDrive) Proxy(c *gin.Context, account *model.Account) {
}
func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver GoogleDrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver GoogleDrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver GoogleDrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver GoogleDrive) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*GoogleDrive)(nil)

View File

@ -144,11 +144,11 @@ func (driver GoogleDrive) GetFiles(id string, account *model.Account) ([]GoogleF
// if !driver.IsDir(file.MimeType) {
// return &file, err
// } else {
// return nil, drivers.NotFile
// return nil, drivers.ErrNotFile
// }
// }
// }
// return nil, drivers.PathNotFound
// return nil, drivers.ErrPathNotFound
//}
func init() {

View File

@ -24,30 +24,30 @@ func (driver Lanzou) Items() []Item {
{
Name: "onedrive_type",
Label: "lanzou type",
Type: SELECT,
Type: TypeSelect,
Required: true,
Values: "cookie,url",
},
{
Name: "access_token",
Label: "cookie",
Type: STRING,
Type: TypeString,
Description: "about 15 days valid",
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: STRING,
Type: TypeString,
},
{
Name: "site_url",
Label: "share url",
Type: STRING,
Type: TypeString,
},
{
Name: "password",
Label: "share password",
Type: STRING,
Type: TypeString,
},
}
}
@ -85,7 +85,7 @@ func (driver Lanzou) File(path string, account *model.Account) (*model.File, err
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) {
@ -157,7 +157,27 @@ func (driver Lanzou) Proxy(c *gin.Context, account *model.Account) {
}
func (driver Lanzou) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver *Lanzou) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver *Lanzou) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver *Lanzou) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver *Lanzou) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*Lanzou)(nil)

View File

@ -15,6 +15,7 @@ import (
type Native struct{}
func (driver Native) Config() DriverConfig {
return DriverConfig{
Name: "Native",
@ -27,20 +28,20 @@ func (driver Native) Items() []Item {
{
Name: "root_folder",
Label: "root folder path",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "order_by",
Label: "order_by",
Type: "select",
Type: TypeSelect,
Values: "name,size,updated_at",
Required: false,
},
{
Name: "order_direction",
Label: "order_direction",
Type: "select",
Type: TypeSelect,
Values: "ASC,DESC",
Required: false,
},
@ -66,7 +67,7 @@ func (driver Native) Save(account *model.Account, old *model.Account) error {
func (driver Native) File(path string, account *model.Account) (*model.File, error) {
fullPath := filepath.Join(account.RootFolder, path)
if !utils.Exists(fullPath) {
return nil, PathNotFound
return nil, ErrPathNotFound
}
f, err := os.Stat(fullPath)
if err != nil {
@ -90,7 +91,7 @@ func (driver Native) File(path string, account *model.Account) (*model.File, err
func (driver Native) Files(path string, account *model.Account) ([]model.File, error) {
fullPath := filepath.Join(account.RootFolder, path)
if !utils.Exists(fullPath) {
return nil, PathNotFound
return nil, ErrPathNotFound
}
files := make([]model.File, 0)
rawFiles, err := ioutil.ReadDir(fullPath)
@ -155,7 +156,26 @@ func (driver Native) Proxy(c *gin.Context, account *model.Account) {
}
func (driver Native) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver Native) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Native) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Native) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Native) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Native) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*Native)(nil)

View File

@ -13,6 +13,7 @@ import (
type Onedrive struct{}
func (driver Onedrive) Config() DriverConfig {
return DriverConfig{
Name: "Onedrive",
@ -25,7 +26,7 @@ func (driver Onedrive) Items() []Item {
{
Name: "zone",
Label: "zone",
Type: "select",
Type: TypeSelect,
Required: true,
Values: "global,cn,us,de",
Description: "",
@ -33,57 +34,57 @@ func (driver Onedrive) Items() []Item {
{
Name: "onedrive_type",
Label: "onedrive type",
Type: "select",
Type: TypeSelect,
Required: true,
Values: "onedrive,sharepoint",
},
{
Name: "client_id",
Label: "client id",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "client_secret",
Label: "client secret",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "redirect_uri",
Label: "redirect uri",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "refresh_token",
Label: "refresh token",
Type: "string",
Type: TypeString,
Required: true,
},
{
Name: "site_id",
Label: "site id",
Type: "string",
Type: TypeString,
Required: false,
},
{
Name: "root_folder",
Label: "root folder path",
Type: "string",
Type: TypeString,
Required: false,
},
{
Name: "order_by",
Label: "order_by",
Type: "select",
Type: TypeSelect,
Values: "name,size,lastModifiedDateTime",
Required: false,
},
{
Name: "order_direction",
Label: "order_direction",
Type: "select",
Type: TypeSelect,
Values: "asc,desc",
Required: false,
},
@ -147,7 +148,7 @@ func (driver Onedrive) File(path string, account *model.Account) (*model.File, e
return &file, nil
}
}
return nil, PathNotFound
return nil, ErrPathNotFound
}
func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) {
@ -204,7 +205,27 @@ func (driver Onedrive) Proxy(c *gin.Context, account *model.Account) {
}
func (driver Onedrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
return nil, ErrNotSupport
}
func (driver Onedrive) MakeDir(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Onedrive) Move(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Onedrive) Copy(src string, dst string, account *model.Account) error {
return ErrNotImplement
}
func (driver Onedrive) Delete(path string, account *model.Account) error {
return ErrNotImplement
}
func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) error {
return ErrNotImplement
}
var _ Driver = (*Onedrive)(nil)

View File

@ -3,14 +3,15 @@ package drivers
import "fmt"
var (
PathNotFound = fmt.Errorf("path not found")
NotFile = fmt.Errorf("not file")
NotImplement = fmt.Errorf("not implement")
NotSupport = fmt.Errorf("not support")
ErrPathNotFound = fmt.Errorf("path not found")
ErrNotFile = fmt.Errorf("not file")
ErrNotImplement = fmt.Errorf("not implement")
ErrNotSupport = fmt.Errorf("not support")
)
const (
STRING = "string"
SELECT = "select"
BOOL = "bool"
TypeString = "string"
TypeSelect = "select"
TypeBool = "bool"
TypeNumber = "number"
)