Fix: failed to get thumbnails under global OneDrive policy

pull/796/head
HFO4 3 years ago
parent d1377262e3
commit 170f2279c1

@ -186,12 +186,12 @@ func (file *File) Rename(new string) error {
// UpdatePicInfo 更新文件的图像信息 // UpdatePicInfo 更新文件的图像信息
func (file *File) UpdatePicInfo(value string) error { 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 更新文件的大小信息 // UpdateSize 更新文件的大小信息
func (file *File) UpdateSize(value uint64) error { 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 更新文件的源文件名 // UpdateSourceName 更新文件的源文件名

@ -450,17 +450,7 @@ func (client *Client) makeBatchDeleteRequestsBody(files []string) string {
// GetThumbURL 获取给定尺寸的缩略图URL // GetThumbURL 获取给定尺寸的缩略图URL
func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (string, error) { func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (string, error) {
dst = strings.TrimPrefix(dst, "/") dst = strings.TrimPrefix(dst, "/")
var ( requestURL := client.getRequestURL("root:/"+dst+":/thumbnails/0") + "/large"
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
}
res, err := client.requestWithStr(ctx, "GET", requestURL, "", 200) res, err := client.requestWithStr(ctx, "GET", requestURL, "", 200)
if err != nil { 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 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 return res.(map[string]interface{})["url"].(string), nil
} }
} }

@ -966,7 +966,7 @@ func TestClient_GetThumbURL(t *testing.T) {
Err: nil, Err: nil,
Response: &http.Response{ Response: &http.Response{
StatusCode: 200, StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"c1x1_Crop":{"url":"thumb"}}]}`)), Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"large":{"url":"thumb"}}]}`)),
}, },
}) })
client.Request = clientMock client.Request = clientMock

@ -39,8 +39,8 @@ func (fs *FileSystem) GetThumb(ctx context.Context, id uint) (*response.ContentR
res.MaxAge = model.GetIntSetting("preview_timeout", 60) res.MaxAge = model.GetIntSetting("preview_timeout", 60)
} }
// 出错时重新生成缩略图 // 本地存储策略出错时重新生成缩略图
if err != nil { if err != nil && fs.Policy.Type == "local" {
fs.GenerateThumbnail(ctx, &fs.FileTarget[0]) fs.GenerateThumbnail(ctx, &fs.FileTarget[0])
} }

Loading…
Cancel
Save