Fix: thumbnails for 21Vianet OneDrive
This commit is contained in:
parent
752ce5ce62
commit
d3f132de6d
6 changed files with 27 additions and 5 deletions
|
@ -22,8 +22,8 @@ type Policy struct {
|
|||
BucketName string
|
||||
IsPrivate bool
|
||||
BaseURL string
|
||||
AccessKey string `gorm:"size:512"`
|
||||
SecretKey string `gorm:"size:512"`
|
||||
AccessKey string `gorm:"size:1024"`
|
||||
SecretKey string `gorm:"size:1024"`
|
||||
MaxSize uint64
|
||||
AutoRename bool
|
||||
DirNameRule string
|
||||
|
|
|
@ -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],
|
||||
"-",
|
||||
|
|
|
@ -30,6 +30,7 @@ type Endpoints struct {
|
|||
OAuthURL string // OAuth认证的基URL
|
||||
OAuthEndpoints *oauthEndpoint
|
||||
EndpointURL string // 接口请求的基URL
|
||||
isInChina bool // 是否为世纪互联
|
||||
}
|
||||
|
||||
// NewClient 根据存储策略获取新的client
|
||||
|
|
|
@ -72,6 +72,10 @@ func (client *Client) getOAuthEndpoint() *oauthEndpoint {
|
|||
case "login.live.com":
|
||||
token, _ = url.Parse("https://login.live.com/oauth20_token.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:
|
||||
token, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/token")
|
||||
authorize, _ = url.Parse("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
|
||||
|
|
|
@ -79,6 +79,7 @@ type BatchResponse struct {
|
|||
// ThumbResponse 获取缩略图的响应
|
||||
type ThumbResponse struct {
|
||||
Value []map[string]interface{} `json:"value"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Chunk 文件分片
|
||||
|
|
|
@ -49,7 +49,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
|
|||
if err := fs.Trigger(ctx, "BeforeAddFileFailed"); err != nil {
|
||||
util.Log().Debug("BeforeAddFileFailed 钩子执行失败,%s", err)
|
||||
}
|
||||
return nil, ErrFileExisted.WithError(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file := ctx.Value(fsctx.FileHeaderCtx).(FileHeader)
|
||||
|
|
Loading…
Add table
Reference in a new issue