From 9c5627a3823dd481d0a78b2bc16bd0e545adf1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Sun, 5 Dec 2021 15:22:19 +0800 Subject: [PATCH] :construction: webdav write interface --- drivers/123.go | 4 +- drivers/123_driver.go | 34 ++++++++++++---- drivers/189.go | 4 +- drivers/189_driver.go | 37 +++++++++++++---- drivers/ali_driver.go | 34 ++++++++++++---- drivers/alidrive.go | 2 +- drivers/driver.go | 9 +++-- drivers/google_driver.go | 34 ++++++++++++---- drivers/googledrive.go | 4 +- drivers/lanzou_driver.go | 34 ++++++++++++---- drivers/native_driver.go | 32 ++++++++++++--- drivers/one_driver.go | 45 +++++++++++++++------ drivers/types.go | 15 +++---- model/file_stream.go | 35 ++++++++++++++++ server/webdav/file.go | 87 ++++++++++++++++++++++++++++++++++++++-- server/webdav/webdav.go | 36 ++++++----------- 16 files changed, 347 insertions(+), 99 deletions(-) create mode 100644 model/file_stream.go diff --git a/drivers/123.go b/drivers/123.go index 0e80d4da..adcbd1d4 100644 --- a/drivers/123.go +++ b/drivers/123.go @@ -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() { diff --git a/drivers/123_driver.go b/drivers/123_driver.go index e056131b..740b46c6 100644 --- a/drivers/123_driver.go +++ b/drivers/123_driver.go @@ -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) \ No newline at end of file diff --git a/drivers/189.go b/drivers/189.go index 6f60a032..4cb74c65 100644 --- a/drivers/189.go +++ b/drivers/189.go @@ -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 { diff --git a/drivers/189_driver.go b/drivers/189_driver.go index 4b0407ea..23f16f1e 100644 --- a/drivers/189_driver.go +++ b/drivers/189_driver.go @@ -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) \ No newline at end of file diff --git a/drivers/ali_driver.go b/drivers/ali_driver.go index e2c518cb..48ec8fe6 100644 --- a/drivers/ali_driver.go +++ b/drivers/ali_driver.go @@ -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) \ No newline at end of file diff --git a/drivers/alidrive.go b/drivers/alidrive.go index 94b7d08f..b23a9308 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -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 { diff --git a/drivers/driver.go b/drivers/driver.go index 09a3108c..9edb279c 100644 --- a/drivers/driver.go +++ b/drivers/driver.go @@ -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 { diff --git a/drivers/google_driver.go b/drivers/google_driver.go index a68ebd04..b54d2a6c 100644 --- a/drivers/google_driver.go +++ b/drivers/google_driver.go @@ -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) \ No newline at end of file diff --git a/drivers/googledrive.go b/drivers/googledrive.go index 8008e388..e7b97c42 100644 --- a/drivers/googledrive.go +++ b/drivers/googledrive.go @@ -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() { diff --git a/drivers/lanzou_driver.go b/drivers/lanzou_driver.go index 1a7d9853..cb603476 100644 --- a/drivers/lanzou_driver.go +++ b/drivers/lanzou_driver.go @@ -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) diff --git a/drivers/native_driver.go b/drivers/native_driver.go index 7c1d200a..80dc2a76 100644 --- a/drivers/native_driver.go +++ b/drivers/native_driver.go @@ -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) diff --git a/drivers/one_driver.go b/drivers/one_driver.go index 55c2d885..6fad7629 100644 --- a/drivers/one_driver.go +++ b/drivers/one_driver.go @@ -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) \ No newline at end of file diff --git a/drivers/types.go b/drivers/types.go index 1baa3234..bafd9228 100644 --- a/drivers/types.go +++ b/drivers/types.go @@ -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" ) diff --git a/model/file_stream.go b/model/file_stream.go new file mode 100644 index 00000000..13325e3e --- /dev/null +++ b/model/file_stream.go @@ -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 +} \ No newline at end of file diff --git a/server/webdav/file.go b/server/webdav/file.go index 53687d4a..fe4dd374 100644 --- a/server/webdav/file.go +++ b/server/webdav/file.go @@ -15,6 +15,7 @@ import ( "net/http" "path" "path/filepath" + "strconv" "strings" "time" ) @@ -133,6 +134,45 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, reqPath string) (inte 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 // path.Clean("/" + name). func slashClean(name string) string { @@ -145,16 +185,55 @@ func slashClean(name string) string { // moveFiles moves files and/or directories from src to dst. // // 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 } // copyFiles copies files and/or directories from src to dst. // // 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 } diff --git a/server/webdav/webdav.go b/server/webdav/webdav.go index 9536fe41..ed2eb0c8 100644 --- a/server/webdav/webdav.go +++ b/server/webdav/webdav.go @@ -253,26 +253,11 @@ func (h *Handler) handleDelete(w http.ResponseWriter, r *http.Request, fs *FileS return status, err } defer release() - - //ctx := r.Context() - - //// 尝试作为文件删除 - //if ok, file := fs.IsFileExist(reqPath); ok { - // 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 + err = fs.Delete(reqPath) + if err != nil { + return http.StatusMethodNotAllowed, err + } + return http.StatusNoContent, nil } // OK @@ -291,6 +276,11 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request, fs *FileSyst ctx, cancel := context.WithCancel(context.Background()) defer cancel() + err = fs.Upload(ctx, r, reqPath) + if err != nil { + return http.StatusMethodNotAllowed, err + } + etag, err := findETag(ctx, fs, h.LockSystem, reqPath, nil) if err != nil { return http.StatusInternalServerError, err @@ -361,7 +351,7 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *Fil ctx := r.Context() - isExist, target := isPathExist(ctx, fs, src) + isExist, _ := isPathExist(ctx, fs, src) if !isExist { 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 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只包含源文件, @@ -409,7 +399,7 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *Fil 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