mirror of https://github.com/Xhofe/alist
🚧 webdav write interface
parent
809850321a
commit
9c5627a382
|
@ -135,11 +135,11 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
|
||||||
if file.Type != conf.FOLDER {
|
if file.Type != conf.FOLDER {
|
||||||
return &file, err
|
return &file, err
|
||||||
} else {
|
} else {
|
||||||
return nil, NotFile
|
return nil, ErrNotFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -25,34 +25,34 @@ func (driver Pan123) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "username",
|
Name: "username",
|
||||||
Label: "username",
|
Label: "username",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "account username/phone number",
|
Description: "account username/phone number",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "password",
|
Name: "password",
|
||||||
Label: "password",
|
Label: "password",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "account password",
|
Description: "account password",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder file_id",
|
Label: "root folder file_id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
Label: "order_by",
|
Label: "order_by",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "name,fileId,updateAt,createAt",
|
Values: "name,fileId,updateAt,createAt",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_direction",
|
Name: "order_direction",
|
||||||
Label: "order_direction",
|
Label: "order_direction",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "asc,desc",
|
Values: "asc,desc",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
@ -89,7 +89,7 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
|
||||||
return &file, nil
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
|
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) {
|
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)
|
var _ Driver = (*Pan123)(nil)
|
|
@ -62,11 +62,11 @@ func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
|
||||||
// if file.Size != -1 {
|
// if file.Size != -1 {
|
||||||
// return &file, err
|
// return &file, err
|
||||||
// } else {
|
// } else {
|
||||||
// return nil, NotFile
|
// return nil, ErrNotFile
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// return nil, PathNotFound
|
// return nil, ErrPathNotFound
|
||||||
//}
|
//}
|
||||||
|
|
||||||
type Cloud189Down struct {
|
type Cloud189Down struct {
|
||||||
|
|
|
@ -24,34 +24,34 @@ func (driver Cloud189) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "username",
|
Name: "username",
|
||||||
Label: "username",
|
Label: "username",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "account username/phone number",
|
Description: "account username/phone number",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "password",
|
Name: "password",
|
||||||
Label: "password",
|
Label: "password",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "account password",
|
Description: "account password",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder file_id",
|
Label: "root folder file_id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
Label: "order_by",
|
Label: "order_by",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "name,size,lastOpTime,createdDate",
|
Values: "name,size,lastOpTime,createdDate",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_direction",
|
Name: "order_direction",
|
||||||
Label: "desc",
|
Label: "desc",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "true,false",
|
Values: "true,false",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
@ -97,7 +97,7 @@ func (driver Cloud189) File(path string, account *model.Account) (*model.File, e
|
||||||
return &file, nil
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) {
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
if file.Type == conf.FOLDER {
|
if file.Type == conf.FOLDER {
|
||||||
return "", NotFile
|
return "", ErrNotFile
|
||||||
}
|
}
|
||||||
client, ok := client189Map[account.Name]
|
client, ok := client189Map[account.Name]
|
||||||
if !ok {
|
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) {
|
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)
|
var _ Driver = (*Cloud189)(nil)
|
|
@ -25,33 +25,33 @@ func (driver AliDrive) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
Label: "order_by",
|
Label: "order_by",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "name,size,updated_at,created_at",
|
Values: "name,size,updated_at,created_at",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_direction",
|
Name: "order_direction",
|
||||||
Label: "order_direction",
|
Label: "order_direction",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "ASC,DESC",
|
Values: "ASC,DESC",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "refresh_token",
|
Name: "refresh_token",
|
||||||
Label: "refresh token",
|
Label: "refresh token",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder file_id",
|
Label: "root folder file_id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "limit",
|
Name: "limit",
|
||||||
Label: "limit",
|
Label: "limit",
|
||||||
Type: "number",
|
Type: TypeNumber,
|
||||||
Required: false,
|
Required: false,
|
||||||
Description: ">0 and <=200",
|
Description: ">0 and <=200",
|
||||||
},
|
},
|
||||||
|
@ -123,7 +123,7 @@ func (driver AliDrive) File(path string, account *model.Account) (*model.File, e
|
||||||
return &file, nil
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver AliDrive) Files(path string, account *model.Account) ([]model.File, error) {
|
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"
|
req["category"] = "live_transcoding"
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, NotSupport
|
return nil, ErrNotSupport
|
||||||
}
|
}
|
||||||
_, err = aliClient.R().SetResult(&resp).SetError(&e).
|
_, err = aliClient.R().SetResult(&resp).SetError(&e).
|
||||||
SetHeader("authorization", "Bearer\t"+account.AccessToken).
|
SetHeader("authorization", "Bearer\t"+account.AccessToken).
|
||||||
|
@ -247,4 +247,24 @@ func (driver AliDrive) Preview(path string, account *model.Account) (interface{}
|
||||||
return resp, nil
|
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)
|
var _ Driver = (*AliDrive)(nil)
|
|
@ -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 {
|
func (driver AliDrive) RefreshToken(account *model.Account) error {
|
||||||
|
|
|
@ -25,10 +25,11 @@ type Driver interface {
|
||||||
Preview(path string, account *model.Account) (interface{}, error)
|
Preview(path string, account *model.Account) (interface{}, error)
|
||||||
// TODO
|
// TODO
|
||||||
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
|
//Search(path string, keyword string, account *model.Account) ([]*model.File, error)
|
||||||
//MakeDir(path string, account *model.Account) error
|
MakeDir(path string, account *model.Account) error
|
||||||
//Move(src string, des string, account *model.Account) error
|
Move(src string, dst string, account *model.Account) error
|
||||||
//Delete(path string) error
|
Copy(src string, dst string, account *model.Account) error
|
||||||
//Upload(file *fs.File, path string, account *model.Account) error
|
Delete(path string, account *model.Account) error
|
||||||
|
Upload(file *model.FileStream, account *model.Account) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
|
|
|
@ -24,25 +24,25 @@ func (driver GoogleDrive) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "client_id",
|
Name: "client_id",
|
||||||
Label: "client id",
|
Label: "client id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "client_secret",
|
Name: "client_secret",
|
||||||
Label: "client secret",
|
Label: "client secret",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "refresh_token",
|
Name: "refresh_token",
|
||||||
Label: "refresh token",
|
Label: "refresh token",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder file_id",
|
Label: "root folder file_id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func (driver GoogleDrive) File(path string, account *model.Account) (*model.File
|
||||||
return &file, nil
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) {
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
if file.Type == conf.FOLDER {
|
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)
|
link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id)
|
||||||
var e GoogleError
|
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) {
|
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)
|
var _ Driver = (*GoogleDrive)(nil)
|
|
@ -144,11 +144,11 @@ func (driver GoogleDrive) GetFiles(id string, account *model.Account) ([]GoogleF
|
||||||
// if !driver.IsDir(file.MimeType) {
|
// if !driver.IsDir(file.MimeType) {
|
||||||
// return &file, err
|
// return &file, err
|
||||||
// } else {
|
// } else {
|
||||||
// return nil, drivers.NotFile
|
// return nil, drivers.ErrNotFile
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// return nil, drivers.PathNotFound
|
// return nil, drivers.ErrPathNotFound
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -24,30 +24,30 @@ func (driver Lanzou) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "onedrive_type",
|
Name: "onedrive_type",
|
||||||
Label: "lanzou type",
|
Label: "lanzou type",
|
||||||
Type: SELECT,
|
Type: TypeSelect,
|
||||||
Required: true,
|
Required: true,
|
||||||
Values: "cookie,url",
|
Values: "cookie,url",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "access_token",
|
Name: "access_token",
|
||||||
Label: "cookie",
|
Label: "cookie",
|
||||||
Type: STRING,
|
Type: TypeString,
|
||||||
Description: "about 15 days valid",
|
Description: "about 15 days valid",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder file_id",
|
Label: "root folder file_id",
|
||||||
Type: STRING,
|
Type: TypeString,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "site_url",
|
Name: "site_url",
|
||||||
Label: "share url",
|
Label: "share url",
|
||||||
Type: STRING,
|
Type: TypeString,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "password",
|
Name: "password",
|
||||||
Label: "share 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 &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) {
|
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) {
|
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)
|
var _ Driver = (*Lanzou)(nil)
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
type Native struct{}
|
type Native struct{}
|
||||||
|
|
||||||
|
|
||||||
func (driver Native) Config() DriverConfig {
|
func (driver Native) Config() DriverConfig {
|
||||||
return DriverConfig{
|
return DriverConfig{
|
||||||
Name: "Native",
|
Name: "Native",
|
||||||
|
@ -27,20 +28,20 @@ func (driver Native) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder path",
|
Label: "root folder path",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
Label: "order_by",
|
Label: "order_by",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "name,size,updated_at",
|
Values: "name,size,updated_at",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_direction",
|
Name: "order_direction",
|
||||||
Label: "order_direction",
|
Label: "order_direction",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "ASC,DESC",
|
Values: "ASC,DESC",
|
||||||
Required: false,
|
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) {
|
func (driver Native) File(path string, account *model.Account) (*model.File, error) {
|
||||||
fullPath := filepath.Join(account.RootFolder, path)
|
fullPath := filepath.Join(account.RootFolder, path)
|
||||||
if !utils.Exists(fullPath) {
|
if !utils.Exists(fullPath) {
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
f, err := os.Stat(fullPath)
|
f, err := os.Stat(fullPath)
|
||||||
if err != nil {
|
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) {
|
func (driver Native) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
fullPath := filepath.Join(account.RootFolder, path)
|
fullPath := filepath.Join(account.RootFolder, path)
|
||||||
if !utils.Exists(fullPath) {
|
if !utils.Exists(fullPath) {
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
files := make([]model.File, 0)
|
files := make([]model.File, 0)
|
||||||
rawFiles, err := ioutil.ReadDir(fullPath)
|
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) {
|
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)
|
var _ Driver = (*Native)(nil)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
type Onedrive struct{}
|
type Onedrive struct{}
|
||||||
|
|
||||||
|
|
||||||
func (driver Onedrive) Config() DriverConfig {
|
func (driver Onedrive) Config() DriverConfig {
|
||||||
return DriverConfig{
|
return DriverConfig{
|
||||||
Name: "Onedrive",
|
Name: "Onedrive",
|
||||||
|
@ -25,7 +26,7 @@ func (driver Onedrive) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "zone",
|
Name: "zone",
|
||||||
Label: "zone",
|
Label: "zone",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Required: true,
|
Required: true,
|
||||||
Values: "global,cn,us,de",
|
Values: "global,cn,us,de",
|
||||||
Description: "",
|
Description: "",
|
||||||
|
@ -33,57 +34,57 @@ func (driver Onedrive) Items() []Item {
|
||||||
{
|
{
|
||||||
Name: "onedrive_type",
|
Name: "onedrive_type",
|
||||||
Label: "onedrive type",
|
Label: "onedrive type",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Required: true,
|
Required: true,
|
||||||
Values: "onedrive,sharepoint",
|
Values: "onedrive,sharepoint",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "client_id",
|
Name: "client_id",
|
||||||
Label: "client id",
|
Label: "client id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "client_secret",
|
Name: "client_secret",
|
||||||
Label: "client secret",
|
Label: "client secret",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "redirect_uri",
|
Name: "redirect_uri",
|
||||||
Label: "redirect uri",
|
Label: "redirect uri",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "refresh_token",
|
Name: "refresh_token",
|
||||||
Label: "refresh token",
|
Label: "refresh token",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "site_id",
|
Name: "site_id",
|
||||||
Label: "site id",
|
Label: "site id",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "root_folder",
|
||||||
Label: "root folder path",
|
Label: "root folder path",
|
||||||
Type: "string",
|
Type: TypeString,
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
Label: "order_by",
|
Label: "order_by",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "name,size,lastModifiedDateTime",
|
Values: "name,size,lastModifiedDateTime",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "order_direction",
|
Name: "order_direction",
|
||||||
Label: "order_direction",
|
Label: "order_direction",
|
||||||
Type: "select",
|
Type: TypeSelect,
|
||||||
Values: "asc,desc",
|
Values: "asc,desc",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
|
@ -147,7 +148,7 @@ func (driver Onedrive) File(path string, account *model.Account) (*model.File, e
|
||||||
return &file, nil
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, PathNotFound
|
return nil, ErrPathNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) {
|
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) {
|
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)
|
var _ Driver = (*Onedrive)(nil)
|
|
@ -3,14 +3,15 @@ package drivers
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
PathNotFound = fmt.Errorf("path not found")
|
ErrPathNotFound = fmt.Errorf("path not found")
|
||||||
NotFile = fmt.Errorf("not file")
|
ErrNotFile = fmt.Errorf("not file")
|
||||||
NotImplement = fmt.Errorf("not implement")
|
ErrNotImplement = fmt.Errorf("not implement")
|
||||||
NotSupport = fmt.Errorf("not support")
|
ErrNotSupport = fmt.Errorf("not support")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
STRING = "string"
|
TypeString = "string"
|
||||||
SELECT = "select"
|
TypeSelect = "select"
|
||||||
BOOL = "bool"
|
TypeBool = "bool"
|
||||||
|
TypeNumber = "number"
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
type FileStream struct {
|
||||||
|
File io.ReadCloser
|
||||||
|
Size uint64
|
||||||
|
Path string
|
||||||
|
Name string
|
||||||
|
MIMEType string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) Read(p []byte) (n int, err error) {
|
||||||
|
return file.File.Read(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) GetMIMEType() string {
|
||||||
|
return file.MIMEType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) GetSize() uint64 {
|
||||||
|
return file.Size
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) Close() error {
|
||||||
|
return file.File.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) GetFileName() string {
|
||||||
|
return file.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file FileStream) GetPath() string {
|
||||||
|
return file.Path
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -133,6 +134,45 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, reqPath string) (inte
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath string) error {
|
||||||
|
rawPath = utils.ParsePath(rawPath)
|
||||||
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
|
return ErrNotImplemented
|
||||||
|
}
|
||||||
|
account, path_, driver, err := ParsePath(rawPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fileSize, err := strconv.ParseUint(r.Header.Get("Content-Length"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
filePath, fileName := filepath.Split(path_)
|
||||||
|
fileData := model.FileStream{
|
||||||
|
MIMEType: r.Header.Get("Content-Type"),
|
||||||
|
File: r.Body,
|
||||||
|
Size: fileSize,
|
||||||
|
Name: fileName,
|
||||||
|
Path: filePath,
|
||||||
|
}
|
||||||
|
return driver.Upload(&fileData, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *FileSystem) Delete(rawPath string) error {
|
||||||
|
rawPath = utils.ParsePath(rawPath)
|
||||||
|
if rawPath == "/" {
|
||||||
|
return ErrNotImplemented
|
||||||
|
}
|
||||||
|
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
||||||
|
return ErrNotImplemented
|
||||||
|
}
|
||||||
|
account, path_, driver, err := ParsePath(rawPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return driver.Delete(path_, account)
|
||||||
|
}
|
||||||
|
|
||||||
// slashClean is equivalent to but slightly more efficient than
|
// slashClean is equivalent to but slightly more efficient than
|
||||||
// path.Clean("/" + name).
|
// path.Clean("/" + name).
|
||||||
func slashClean(name string) string {
|
func slashClean(name string) string {
|
||||||
|
@ -145,16 +185,55 @@ func slashClean(name string) string {
|
||||||
// moveFiles moves files and/or directories from src to dst.
|
// moveFiles moves files and/or directories from src to dst.
|
||||||
//
|
//
|
||||||
// See section 9.9.4 for when various HTTP status codes apply.
|
// See section 9.9.4 for when various HTTP status codes apply.
|
||||||
func moveFiles(ctx context.Context, fs *FileSystem, src FileInfo, dst string, overwrite bool) (status int, err error) {
|
func moveFiles(ctx context.Context, fs *FileSystem, src string, dst string, overwrite bool) (status int, err error) {
|
||||||
|
src = utils.ParsePath(src)
|
||||||
|
dst = utils.ParsePath(dst)
|
||||||
|
if src == dst {
|
||||||
|
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||||
|
}
|
||||||
|
srcAccount, srcPath, driver, err := ParsePath(src)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
|
}
|
||||||
|
dstAccount, dstPath, _, err := ParsePath(dst)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
|
}
|
||||||
|
if srcAccount.Name != dstAccount.Name {
|
||||||
|
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||||
|
}
|
||||||
|
err = driver.Move(srcPath,dstPath,srcAccount)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
return http.StatusNoContent, nil
|
return http.StatusNoContent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyFiles copies files and/or directories from src to dst.
|
// copyFiles copies files and/or directories from src to dst.
|
||||||
//
|
//
|
||||||
// See section 9.8.5 for when various HTTP status codes apply.
|
// See section 9.8.5 for when various HTTP status codes apply.
|
||||||
func copyFiles(ctx context.Context, fs *FileSystem, src FileInfo, dst string, overwrite bool, depth int, recursion int) (status int, err error) {
|
func copyFiles(ctx context.Context, fs *FileSystem, src string, dst string, overwrite bool, depth int, recursion int) (status int, err error) {
|
||||||
|
src = utils.ParsePath(src)
|
||||||
|
dst = utils.ParsePath(dst)
|
||||||
|
if src == dst {
|
||||||
|
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||||
|
}
|
||||||
|
srcAccount, srcPath, driver, err := ParsePath(src)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
|
}
|
||||||
|
dstAccount, dstPath, _, err := ParsePath(dst)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
|
}
|
||||||
|
if srcAccount.Name != dstAccount.Name {
|
||||||
|
// TODO 跨账号复制
|
||||||
|
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||||
|
}
|
||||||
|
err = driver.Copy(srcPath,dstPath,srcAccount)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
return http.StatusNoContent, nil
|
return http.StatusNoContent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,26 +253,11 @@ func (h *Handler) handleDelete(w http.ResponseWriter, r *http.Request, fs *FileS
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
defer release()
|
defer release()
|
||||||
|
err = fs.Delete(reqPath)
|
||||||
//ctx := r.Context()
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
//// 尝试作为文件删除
|
}
|
||||||
//if ok, file := fs.IsFileExist(reqPath); ok {
|
return http.StatusNoContent, nil
|
||||||
// if err := fs.Delete(ctx, []uint{}, []uint{file.ID}, false); err != nil {
|
|
||||||
// return http.StatusMethodNotAllowed, err
|
|
||||||
// }
|
|
||||||
// return http.StatusNoContent, nil
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//// 尝试作为目录删除
|
|
||||||
//if ok, folder := fs.IsPathExist(reqPath); ok {
|
|
||||||
// if err := fs.Delete(ctx, []uint{folder.ID}, []uint{}, false); err != nil {
|
|
||||||
// return http.StatusMethodNotAllowed, err
|
|
||||||
// }
|
|
||||||
// return http.StatusNoContent, nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
return http.StatusNotFound, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK
|
||||||
|
@ -291,6 +276,11 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request, fs *FileSyst
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
err = fs.Upload(ctx, r, reqPath)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusMethodNotAllowed, err
|
||||||
|
}
|
||||||
|
|
||||||
etag, err := findETag(ctx, fs, h.LockSystem, reqPath, nil)
|
etag, err := findETag(ctx, fs, h.LockSystem, reqPath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
@ -361,7 +351,7 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *Fil
|
||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
isExist, target := isPathExist(ctx, fs, src)
|
isExist, _ := isPathExist(ctx, fs, src)
|
||||||
|
|
||||||
if !isExist {
|
if !isExist {
|
||||||
return http.StatusNotFound, nil
|
return http.StatusNotFound, nil
|
||||||
|
@ -390,7 +380,7 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *Fil
|
||||||
return http.StatusBadRequest, errInvalidDepth
|
return http.StatusBadRequest, errInvalidDepth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return copyFiles(ctx, fs, target, dst, r.Header.Get("Overwrite") != "F", depth, 0)
|
return copyFiles(ctx, fs, src, dst, r.Header.Get("Overwrite") != "F", depth, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// windows下,某些情况下(网盘根目录下)Office保存文件时附带的锁token只包含源文件,
|
// windows下,某些情况下(网盘根目录下)Office保存文件时附带的锁token只包含源文件,
|
||||||
|
@ -409,7 +399,7 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *Fil
|
||||||
return http.StatusBadRequest, errInvalidDepth
|
return http.StatusBadRequest, errInvalidDepth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return moveFiles(ctx, fs, target, dst, r.Header.Get("Overwrite") == "T")
|
return moveFiles(ctx, fs, src, dst, r.Header.Get("Overwrite") == "T")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK
|
// OK
|
||||||
|
|
Loading…
Reference in New Issue