From 85a28d98223d3114670b0c0101f6ad2dffed8829 Mon Sep 17 00:00:00 2001 From: Echo Response <32877980+EchoResponse@users.noreply.github.com> Date: Sat, 20 Jan 2024 21:22:50 +0800 Subject: [PATCH] fix(quqi): error on uploading an existing file (#5920) --- drivers/quqi/driver.go | 23 ++++++++++++++++++++++- drivers/quqi/types.go | 3 +++ drivers/quqi/util.go | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/quqi/driver.go b/drivers/quqi/driver.go index 9bc23f8b837..98c184bd49e 100644 --- a/drivers/quqi/driver.go +++ b/drivers/quqi/driver.go @@ -306,6 +306,22 @@ func (d *Quqi) Put(ctx context.Context, dstDir model.Obj, stream model.FileStrea if err != nil { return nil, err } + // check exist + // if the file already exists in Quqi server, there is no need to actually upload it + if uploadInitResp.Data.Exist { + // the file name returned by Quqi does not include the extension name + nodeName, nodeExt := uploadInitResp.Data.NodeName, rawExt(stream.GetName()) + if nodeExt != "" { + nodeName = nodeName + "." + nodeExt + } + return &model.Object{ + ID: strconv.FormatInt(uploadInitResp.Data.NodeID, 10), + Name: nodeName, + Size: stream.GetSize(), + Modified: stream.ModTime(), + Ctime: stream.CreateTime(), + }, nil + } // listParts _, err = d.request("upload.quqi.com:20807", "/upload/v1/listParts", resty.MethodPost, func(req *resty.Request) { req.SetFormData(map[string]string{ @@ -384,9 +400,14 @@ func (d *Quqi) Put(ctx context.Context, dstDir model.Obj, stream model.FileStrea if err != nil { return nil, err } + // the file name returned by Quqi does not include the extension name + nodeName, nodeExt := uploadFinishResp.Data.NodeName, rawExt(stream.GetName()) + if nodeExt != "" { + nodeName = nodeName + "." + nodeExt + } return &model.Object{ ID: strconv.FormatInt(uploadFinishResp.Data.NodeID, 10), - Name: uploadFinishResp.Data.NodeName, + Name: nodeName, Size: stream.GetSize(), Modified: stream.ModTime(), Ctime: stream.CreateTime(), diff --git a/drivers/quqi/types.go b/drivers/quqi/types.go index 3f6c4ebe2dd..f64fb748e47 100644 --- a/drivers/quqi/types.go +++ b/drivers/quqi/types.go @@ -133,6 +133,9 @@ type UploadInitResp struct { Token string `json:"token"` UploadID string `json:"upload_id"` URL string `json:"url"` + NodeID int64 `json:"node_id"` + NodeName string `json:"node_name"` + ParentID int64 `json:"parent_id"` } `json:"data"` Err int `json:"err"` Msg string `json:"msg"` diff --git a/drivers/quqi/util.go b/drivers/quqi/util.go index 91fc0a02d7c..23a6a966934 100644 --- a/drivers/quqi/util.go +++ b/drivers/quqi/util.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/url" + stdpath "path" "strings" "github.com/alist-org/alist/v3/drivers/base" @@ -97,3 +98,13 @@ func (d *Quqi) checkLogin() bool { } return true } + +// rawExt 保留扩展名大小写 +func rawExt(name string) string { + ext := stdpath.Ext(name) + if strings.HasPrefix(ext, ".") { + ext = ext[1:] + } + + return ext +}