feat: misc improvements about upload/copy/hash (#5045)
general: add createTime/updateTime support in webdav and some drivers general: add hash support in some drivers general: cross-storage rapid-upload support general: enhance upload to avoid local temp file if possible general: replace readseekcloser with File interface to speed upstream operations feat(aliyun_open): same as above feat(crypt): add hack for 139cloud Close #4934 Close #4819 baidu_netdisk needs to improve the upload code to support rapid-upload
This commit is contained in:
@ -131,8 +131,8 @@ var liveProps = map[xml.Name]struct {
|
||||
dir: true,
|
||||
},
|
||||
{Space: "DAV:", Local: "creationdate"}: {
|
||||
findFn: nil,
|
||||
dir: false,
|
||||
findFn: findCreationDate,
|
||||
dir: true,
|
||||
},
|
||||
{Space: "DAV:", Local: "getcontentlanguage"}: {
|
||||
findFn: nil,
|
||||
@ -383,6 +383,9 @@ func findContentLength(ctx context.Context, ls LockSystem, name string, fi model
|
||||
func findLastModified(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {
|
||||
return fi.ModTime().UTC().Format(http.TimeFormat), nil
|
||||
}
|
||||
func findCreationDate(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {
|
||||
return fi.CreateTime().UTC().Format(http.TimeFormat), nil
|
||||
}
|
||||
|
||||
// ErrNotImplemented should be returned by optional interfaces if they
|
||||
// want the original implementation to be used.
|
||||
|
29
server/webdav/util.go
Normal file
29
server/webdav/util.go
Normal file
@ -0,0 +1,29 @@
|
||||
package webdav
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (h *Handler) getModTime(r *http.Request) time.Time {
|
||||
return h.getHeaderTime(r, "X-OC-Mtime")
|
||||
}
|
||||
|
||||
// owncloud/ nextcloud haven't impl this, but we can add the support since rclone may support this soon
|
||||
func (h *Handler) getCreateTime(r *http.Request) time.Time {
|
||||
return h.getHeaderTime(r, "X-OC-Ctime")
|
||||
}
|
||||
|
||||
func (h *Handler) getHeaderTime(r *http.Request, header string) time.Time {
|
||||
hVal := r.Header.Get(header)
|
||||
if hVal != "" {
|
||||
modTimeUnix, err := strconv.ParseInt(hVal, 10, 64)
|
||||
if err == nil {
|
||||
return time.Unix(modTimeUnix, 0)
|
||||
}
|
||||
log.Warnf("getModTime in Webdav, failed to parse %s, %s", header, err)
|
||||
}
|
||||
return time.Now()
|
||||
}
|
@ -8,6 +8,7 @@ package webdav // import "golang.org/x/net/webdav"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/stream"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -321,12 +322,13 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
|
||||
obj := model.Object{
|
||||
Name: path.Base(reqPath),
|
||||
Size: r.ContentLength,
|
||||
Modified: time.Now(),
|
||||
Modified: h.getModTime(r),
|
||||
Ctime: h.getCreateTime(r),
|
||||
}
|
||||
stream := &model.FileStream{
|
||||
Obj: &obj,
|
||||
ReadCloser: r.Body,
|
||||
Mimetype: r.Header.Get("Content-Type"),
|
||||
stream := &stream.FileStream{
|
||||
Obj: &obj,
|
||||
Reader: r.Body,
|
||||
Mimetype: r.Header.Get("Content-Type"),
|
||||
}
|
||||
if stream.Mimetype == "" {
|
||||
stream.Mimetype = utils.GetMimeType(reqPath)
|
||||
@ -336,6 +338,8 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
|
||||
_ = r.Body.Close()
|
||||
_ = stream.Close()
|
||||
// TODO(rost): Returning 405 Method Not Allowed might not be appropriate.
|
||||
if err != nil {
|
||||
return http.StatusMethodNotAllowed, err
|
||||
|
Reference in New Issue
Block a user