diff --git a/models/policy.go b/models/policy.go index f545c43..abe9c6e 100644 --- a/models/policy.go +++ b/models/policy.go @@ -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 diff --git a/pkg/filesystem/driver/onedrive/api.go b/pkg/filesystem/driver/onedrive/api.go index 56b6597..d3cfba9 100644 --- a/pkg/filesystem/driver/onedrive/api.go +++ b/pkg/filesystem/driver/onedrive/api.go @@ -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], "-", diff --git a/pkg/filesystem/driver/onedrive/client.go b/pkg/filesystem/driver/onedrive/client.go index 61a7558..a5ca4ab 100644 --- a/pkg/filesystem/driver/onedrive/client.go +++ b/pkg/filesystem/driver/onedrive/client.go @@ -30,6 +30,7 @@ type Endpoints struct { OAuthURL string // OAuth认证的基URL OAuthEndpoints *oauthEndpoint EndpointURL string // 接口请求的基URL + isInChina bool // 是否为世纪互联 } // NewClient 根据存储策略获取新的client diff --git a/pkg/filesystem/driver/onedrive/oauth.go b/pkg/filesystem/driver/onedrive/oauth.go index 96521c7..aebaf6d 100644 --- a/pkg/filesystem/driver/onedrive/oauth.go +++ b/pkg/filesystem/driver/onedrive/oauth.go @@ -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") diff --git a/pkg/filesystem/driver/onedrive/types.go b/pkg/filesystem/driver/onedrive/types.go index 5386c93..5730ead 100644 --- a/pkg/filesystem/driver/onedrive/types.go +++ b/pkg/filesystem/driver/onedrive/types.go @@ -79,6 +79,7 @@ type BatchResponse struct { // ThumbResponse 获取缩略图的响应 type ThumbResponse struct { Value []map[string]interface{} `json:"value"` + URL string `json:"url"` } // Chunk 文件分片 diff --git a/pkg/filesystem/file.go b/pkg/filesystem/file.go index 6eebc02..8ec5fd0 100644 --- a/pkg/filesystem/file.go +++ b/pkg/filesystem/file.go @@ -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)