From b59fcf74f5269ec5162185df5b85625ee2bfedb9 Mon Sep 17 00:00:00 2001 From: ihipop Date: Fri, 25 Dec 2020 13:12:21 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E9=98=BF=E9=87=8C=E4=BA=91=E7=9A=84=20g?= =?UTF-8?q?olang=20SDK=20=E4=BC=9A=E6=8A=8A=E6=95=B4=E4=B8=AA=20object=20K?= =?UTF-8?q?EY=E4=B9=9F=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit b9cd82b849065f0d1ad093708f09c8722339bf2a) --- .gitignore | 1 + pkg/filesystem/file.go | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 40a55874..2acda621 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ version.lock *.ini conf/conf.ini /statik/ +/vendor/ \ No newline at end of file diff --git a/pkg/filesystem/file.go b/pkg/filesystem/file.go index efe5101d..eeadadce 100644 --- a/pkg/filesystem/file.go +++ b/pkg/filesystem/file.go @@ -2,8 +2,6 @@ package filesystem import ( "context" - "io" - model "github.com/cloudreve/Cloudreve/v3/models" "github.com/cloudreve/Cloudreve/v3/pkg/conf" "github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx" @@ -11,6 +9,8 @@ import ( "github.com/cloudreve/Cloudreve/v3/pkg/serializer" "github.com/cloudreve/Cloudreve/v3/pkg/util" "github.com/juju/ratelimit" + "io" + "net/url" ) /* ============ @@ -288,8 +288,11 @@ func (fs *FileSystem) signURL(ctx context.Context, file *model.File, ttl int64, if err != nil { return "", serializer.NewError(serializer.CodeNotSet, "无法获取外链", err) } - - return source, nil + // 阿里云的 golang SDK 会把整个object KEY也编码 临时解决方案是清空`RawPath`让golang的`url.EscapedPath`修正这个问题 + // https://github.com/cloudreve/Cloudreve/issues/677 https://github.com/aliyun/aliyun-oss-go-sdk/blob/6f7e8f88c64181cc2d86d8bd46090b68851e645a/oss/conn.go#L767 + sourceUrl, _ := url.Parse(source) + sourceUrl.RawPath = "" + return sourceUrl.String(), nil } // ResetFileIfNotExist 重设当前目标文件为 path,如果当前目标为空