Skip to content

Commit

Permalink
Fix: failed to get thumbnails under global OneDrive policy
Browse files Browse the repository at this point in the history
  • Loading branch information
HFO4 committed Mar 14, 2021
1 parent d137726 commit 170f227
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 更新文件的源文件名
Expand Down
14 changes: 2 additions & 12 deletions pkg/filesystem/driver/onedrive/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/filesystem/driver/onedrive/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/filesystem/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down

0 comments on commit 170f227

Please sign in to comment.