mirror of
https://github.com/rclone/rclone.git
synced 2024-12-01 13:04:21 +08:00
webdav: nextcloud: fix must use /dav/files/USER endpoint not /webdav error
Fix https://github.com/rclone/rclone/issues/7103 Before this change the RegExp validating the endpoint URL was a bit too strict allowing only /dav/files/USER due to chunking limitations. This patch adds back support for /dav/files/USER/dir/subdir etc. Co-authored-by: Nick Craig-Wood <nick@craig-wood.com>
This commit is contained in:
parent
22a14a8c98
commit
b4c7b240d8
|
@ -14,7 +14,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
|
@ -41,10 +40,6 @@ func (f *Fs) setUploadChunkSize(cs fs.SizeSuffix) (old fs.SizeSuffix, err error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) getChunksUploadURL() string {
|
|
||||||
return strings.Replace(f.endpointURL, "/dav/files/", "/dav/uploads/", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Object) getChunksUploadDir() (string, error) {
|
func (o *Object) getChunksUploadDir() (string, error) {
|
||||||
hasher := md5.New()
|
hasher := md5.New()
|
||||||
_, err := hasher.Write([]byte(o.filePath()))
|
_, err := hasher.Write([]byte(o.filePath()))
|
||||||
|
@ -55,12 +50,16 @@ func (o *Object) getChunksUploadDir() (string, error) {
|
||||||
return uploadDir, nil
|
return uploadDir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) verifyChunkConfig() error {
|
func (f *Fs) getChunksUploadURL() (string, error) {
|
||||||
if f.opt.ChunkSize != 0 && !validateNextCloudChunkedURL.MatchString(f.endpointURL) {
|
submatch := nextCloudURLRegex.FindStringSubmatch(f.endpointURL)
|
||||||
return errors.New("chunked upload with nextcloud must use /dav/files/USER endpoint not /webdav")
|
if submatch == nil {
|
||||||
|
return "", errors.New("the remote url looks incorrect. Note that nextcloud chunked uploads require you to use the /dav/files/USER endpoint instead of /webdav")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
baseURL, user := submatch[1], submatch[2]
|
||||||
|
chunksUploadURL := fmt.Sprintf("%s/dav/uploads/%s/", baseURL, user)
|
||||||
|
|
||||||
|
return chunksUploadURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) shouldUseChunkedUpload(src fs.ObjectInfo) bool {
|
func (o *Object) shouldUseChunkedUpload(src fs.ObjectInfo) bool {
|
||||||
|
|
|
@ -569,7 +569,8 @@ func (f *Fs) fetchAndSetBearerToken() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var validateNextCloudChunkedURL = regexp.MustCompile(`^.*/dav/files/[^/]+/?$`)
|
// The WebDAV url can optionally be suffixed with a path. This suffix needs to be ignored for determining the temporary upload directory of chunks.
|
||||||
|
var nextCloudURLRegex = regexp.MustCompile(`^(.*)/dav/files/([^/]+)`)
|
||||||
|
|
||||||
// setQuirks adjusts the Fs for the vendor passed in
|
// setQuirks adjusts the Fs for the vendor passed in
|
||||||
func (f *Fs) setQuirks(ctx context.Context, vendor string) error {
|
func (f *Fs) setQuirks(ctx context.Context, vendor string) error {
|
||||||
|
@ -592,11 +593,18 @@ func (f *Fs) setQuirks(ctx context.Context, vendor string) error {
|
||||||
f.propsetMtime = true
|
f.propsetMtime = true
|
||||||
f.hasOCSHA1 = true
|
f.hasOCSHA1 = true
|
||||||
f.canChunk = true
|
f.canChunk = true
|
||||||
if err := f.verifyChunkConfig(); err != nil {
|
|
||||||
|
if f.opt.ChunkSize == 0 {
|
||||||
|
fs.Logf(nil, "Chunked uploads are disabled because nextcloud_chunk_size is set to 0")
|
||||||
|
} else {
|
||||||
|
chunksUploadURL, err := f.getChunksUploadURL()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
f.chunksUploadURL = f.getChunksUploadURL()
|
|
||||||
|
f.chunksUploadURL = chunksUploadURL
|
||||||
fs.Logf(nil, "Chunks temporary upload directory: %s", f.chunksUploadURL)
|
fs.Logf(nil, "Chunks temporary upload directory: %s", f.chunksUploadURL)
|
||||||
|
}
|
||||||
case "sharepoint":
|
case "sharepoint":
|
||||||
// To mount sharepoint, two Cookies are required
|
// To mount sharepoint, two Cookies are required
|
||||||
// They have to be set instead of BasicAuth
|
// They have to be set instead of BasicAuth
|
||||||
|
|
Loading…
Reference in New Issue
Block a user