Fix: thumbnails for 21Vianet OneDrive

This commit is contained in:
HFO4
2020-01-22 08:58:59 +08:00
parent 752ce5ce62
commit d3f132de6d
6 changed files with 27 additions and 5 deletions

View File

@@ -310,8 +310,17 @@ 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, "/")
cropOption := fmt.Sprintf("c%dx%d_Crop", w, h)
requestURL := client.getRequestURL("me/drive/root:/"+dst+":/thumbnails") + "?select=" + cropOption
var (
cropOption string
requestURL string
)
if client.Endpoints.isInChina {
cropOption = "large"
requestURL = client.getRequestURL("me/drive/root:/"+dst+":/thumbnails/0") + "/" + cropOption
} else {
cropOption = fmt.Sprintf("c%dx%d_Crop", w, h)
requestURL = client.getRequestURL("me/drive/root:/"+dst+":/thumbnails") + "?select=" + cropOption
}
res, err := client.requestWithStr(ctx, "GET", requestURL, "", 200)
if err != nil {
@@ -327,6 +336,10 @@ func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (s
return "", decodeErr
}
if thumbRes.URL != "" {
return thumbRes.URL, nil
}
if len(thumbRes.Value) == 1 {
if res, ok := thumbRes.Value[0][cropOption]; ok {
return res.(map[string]interface{})["url"].(string), nil
@@ -386,6 +399,9 @@ func (client *Client) MonitorUpload(uploadURL, callbackKey, path string, size ui
}
// 成功获取分片上传状态,检查文件大小
if len(status.NextExpectedRanges) == 0 {
continue
}
sizeRange := strings.Split(
status.NextExpectedRanges[len(status.NextExpectedRanges)-1],
"-",