From 170f2279c1f9cb1d95533d6fc9f87e0ff5ce4d24 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 14 Mar 2021 11:03:10 +0800 Subject: [PATCH] Fix: failed to get thumbnails under global OneDrive policy --- models/file.go | 4 ++-- pkg/filesystem/driver/onedrive/api.go | 14 ++------------ pkg/filesystem/driver/onedrive/api_test.go | 2 +- pkg/filesystem/image.go | 4 ++-- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/models/file.go b/models/file.go index 7b1d6e8..453e76f 100644 --- a/models/file.go +++ b/models/file.go @@ -186,12 +186,12 @@ func (file *File) Rename(new string) error { // UpdatePicInfo 更新文件的图像信息 func (file *File) UpdatePicInfo(value string) error { - return DB.Model(&file).Update("pic_info", value).Error + return DB.Model(&file).Set("gorm:association_autoupdate", false).Update("pic_info", value).Error } // UpdateSize 更新文件的大小信息 func (file *File) UpdateSize(value uint64) error { - return DB.Model(&file).Update("size", value).Error + return DB.Model(&file).Set("gorm:association_autoupdate", false).Update("size", value).Error } // UpdateSourceName 更新文件的源文件名 diff --git a/pkg/filesystem/driver/onedrive/api.go b/pkg/filesystem/driver/onedrive/api.go index 6dfb6ca..d8f7b38 100644 --- a/pkg/filesystem/driver/onedrive/api.go +++ b/pkg/filesystem/driver/onedrive/api.go @@ -450,17 +450,7 @@ func (client *Client) makeBatchDeleteRequestsBody(files []string) string { // GetThumbURL 获取给定尺寸的缩略图URL func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (string, error) { dst = strings.TrimPrefix(dst, "/") - var ( - cropOption string - requestURL string - ) - if client.Endpoints.isInChina { - cropOption = "large" - requestURL = client.getRequestURL("root:/"+dst+":/thumbnails/0") + "/" + cropOption - } else { - cropOption = fmt.Sprintf("c%dx%d_Crop", w, h) - requestURL = client.getRequestURL("root:/"+dst+":/thumbnails") + "?select=" + cropOption - } + requestURL := client.getRequestURL("root:/"+dst+":/thumbnails/0") + "/large" res, err := client.requestWithStr(ctx, "GET", requestURL, "", 200) if err != nil { @@ -481,7 +471,7 @@ func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (s } if len(thumbRes.Value) == 1 { - if res, ok := thumbRes.Value[0][cropOption]; ok { + if res, ok := thumbRes.Value[0]["large"]; ok { return res.(map[string]interface{})["url"].(string), nil } } diff --git a/pkg/filesystem/driver/onedrive/api_test.go b/pkg/filesystem/driver/onedrive/api_test.go index b0324ea..02fb294 100644 --- a/pkg/filesystem/driver/onedrive/api_test.go +++ b/pkg/filesystem/driver/onedrive/api_test.go @@ -966,7 +966,7 @@ func TestClient_GetThumbURL(t *testing.T) { Err: nil, Response: &http.Response{ StatusCode: 200, - Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"c1x1_Crop":{"url":"thumb"}}]}`)), + Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"large":{"url":"thumb"}}]}`)), }, }) client.Request = clientMock diff --git a/pkg/filesystem/image.go b/pkg/filesystem/image.go index a2e7e08..f072a1d 100644 --- a/pkg/filesystem/image.go +++ b/pkg/filesystem/image.go @@ -39,8 +39,8 @@ func (fs *FileSystem) GetThumb(ctx context.Context, id uint) (*response.ContentR res.MaxAge = model.GetIntSetting("preview_timeout", 60) } - // 出错时重新生成缩略图 - if err != nil { + // 本地存储策略出错时重新生成缩略图 + if err != nil && fs.Policy.Type == "local" { fs.GenerateThumbnail(ctx, &fs.FileTarget[0]) }