Skip to content

Commit

Permalink
fix(quqi): error on uploading an existing file (#5920)
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoResponse authored Jan 20, 2024
1 parent 4f7761f commit 85a28d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
23 changes: 22 additions & 1 deletion drivers/quqi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions drivers/quqi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 11 additions & 0 deletions drivers/quqi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/url"
stdpath "path"
"strings"

"github.com/alist-org/alist/v3/drivers/base"
Expand Down Expand Up @@ -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
}

0 comments on commit 85a28d9

Please sign in to comment.