mirror of https://github.com/cloudreve/Cloudreve
Fix: thumbnails for 21Vianet OneDrive
parent
752ce5ce62
commit
d3f132de6d
|
@ -22,8 +22,8 @@ type Policy struct {
|
||||||
BucketName string
|
BucketName string
|
||||||
IsPrivate bool
|
IsPrivate bool
|
||||||
BaseURL string
|
BaseURL string
|
||||||
AccessKey string `gorm:"size:512"`
|
AccessKey string `gorm:"size:1024"`
|
||||||
SecretKey string `gorm:"size:512"`
|
SecretKey string `gorm:"size:1024"`
|
||||||
MaxSize uint64
|
MaxSize uint64
|
||||||
AutoRename bool
|
AutoRename bool
|
||||||
DirNameRule string
|
DirNameRule string
|
||||||
|
|
|
@ -310,8 +310,17 @@ 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, "/")
|
||||||
cropOption := fmt.Sprintf("c%dx%d_Crop", w, h)
|
var (
|
||||||
requestURL := client.getRequestURL("me/drive/root:/"+dst+":/thumbnails") + "?select=" + cropOption
|
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)
|
res, err := client.requestWithStr(ctx, "GET", requestURL, "", 200)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -327,6 +336,10 @@ func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (s
|
||||||
return "", decodeErr
|
return "", decodeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if thumbRes.URL != "" {
|
||||||
|
return thumbRes.URL, nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(thumbRes.Value) == 1 {
|
if len(thumbRes.Value) == 1 {
|
||||||
if res, ok := thumbRes.Value[0][cropOption]; ok {
|
if res, ok := thumbRes.Value[0][cropOption]; ok {
|
||||||
return res.(map[string]interface{})["url"].(string), nil
|
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(
|
sizeRange := strings.Split(
|
||||||
status.NextExpectedRanges[len(status.NextExpectedRanges)-1],
|
status.NextExpectedRanges[len(status.NextExpectedRanges)-1],
|
||||||
"-",
|
"-",
|
||||||
|
|
|
@ -30,6 +30,7 @@ type Endpoints struct {
|
||||||
OAuthURL string // OAuth认证的基URL
|
OAuthURL string // OAuth认证的基URL
|
||||||
OAuthEndpoints *oauthEndpoint
|
OAuthEndpoints *oauthEndpoint
|
||||||
EndpointURL string // 接口请求的基URL
|
EndpointURL string // 接口请求的基URL
|
||||||
|
isInChina bool // 是否为世纪互联
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient 根据存储策略获取新的client
|
// NewClient 根据存储策略获取新的client
|
||||||
|
|
|
@ -72,6 +72,10 @@ func (client *Client) getOAuthEndpoint() *oauthEndpoint {
|
||||||
case "login.live.com":
|
case "login.live.com":
|
||||||
token, _ = url.Parse("https://login.live.com/oauth20_token.srf")
|
token, _ = url.Parse("https://login.live.com/oauth20_token.srf")
|
||||||
authorize, _ = url.Parse("https://login.live.com/oauth20_authorize.srf")
|
authorize, _ = url.Parse("https://login.live.com/oauth20_authorize.srf")
|
||||||
|
case "login.chinacloudapi.cn":
|
||||||
|
client.Endpoints.isInChina = true
|
||||||
|
token, _ = url.Parse("https://login.chinacloudapi.cn/common/oauth2/v2.0/token")
|
||||||
|
authorize, _ = url.Parse("https://login.chinacloudapi.cn/common/oauth2/v2.0/authorize")
|
||||||
default:
|
default:
|
||||||
token, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/token")
|
token, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/token")
|
||||||
authorize, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
|
authorize, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
|
||||||
|
|
|
@ -79,6 +79,7 @@ type BatchResponse struct {
|
||||||
// ThumbResponse 获取缩略图的响应
|
// ThumbResponse 获取缩略图的响应
|
||||||
type ThumbResponse struct {
|
type ThumbResponse struct {
|
||||||
Value []map[string]interface{} `json:"value"`
|
Value []map[string]interface{} `json:"value"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk 文件分片
|
// Chunk 文件分片
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
|
||||||
if err := fs.Trigger(ctx, "BeforeAddFileFailed"); err != nil {
|
if err := fs.Trigger(ctx, "BeforeAddFileFailed"); err != nil {
|
||||||
util.Log().Debug("BeforeAddFileFailed 钩子执行失败,%s", err)
|
util.Log().Debug("BeforeAddFileFailed 钩子执行失败,%s", err)
|
||||||
}
|
}
|
||||||
return nil, ErrFileExisted.WithError(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file := ctx.Value(fsctx.FileHeaderCtx).(FileHeader)
|
file := ctx.Value(fsctx.FileHeaderCtx).(FileHeader)
|
||||||
|
|
Loading…
Reference in New Issue