feat(thumb): generate thumb for OneDrive files

pull/1690/head
Aaron Liu 2 years ago
parent 62b73b577b
commit e115497dfe

@ -3,7 +3,6 @@ package onedrive
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"io"
@ -32,6 +31,8 @@ const (
// ListRetry 列取请求重试次数
ListRetry = 1
chunkRetrySleep = time.Second * 5
notFoundError = "itemNotFound"
)
// GetSourcePath 获取文件的绝对路径
@ -438,7 +439,7 @@ func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (s
}
}
return "", errors.New("failed to generate thumb")
return "", ErrThumbSizeNotFound
}
// MonitorUpload 监控客户端分片上传进度
@ -469,7 +470,7 @@ func (client *Client) MonitorUpload(uploadURL, callbackKey, path string, size ui
if err != nil {
if resErr, ok := err.(*RespError); ok {
if resErr.APIError.Code == "itemNotFound" {
if resErr.APIError.Code == notFoundError {
util.Log().Debug("Upload completed, will check upload callback later.")
select {
case <-time.After(time.Duration(interval) * time.Second):

@ -17,6 +17,8 @@ var (
ErrDeleteFile = errors.New("cannot delete file")
// ErrClientCanceled 客户端取消操作
ErrClientCanceled = errors.New("client canceled")
// Desired thumb size not available
ErrThumbSizeNotFound = errors.New("thumb size not found")
)
// Client OneDrive客户端

@ -147,11 +147,13 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co
res, err := handler.Client.GetThumbURL(ctx, file.SourceName, thumbSize[0], thumbSize[1])
if err != nil {
// 如果出现异常就清空文件的pic_info
if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok {
file.UpdatePicInfo("")
var apiErr *RespError
if errors.As(err, &apiErr); err == ErrThumbSizeNotFound || (apiErr != nil && apiErr.APIError.Code == notFoundError) {
// OneDrive cannot generate thumbnail for this file
return nil, driver.ErrorThumbNotSupported
}
}
return &response.ContentResponse{
Redirect: true,
URL: res,

@ -115,6 +115,7 @@ func (fs *FileSystem) GenerateThumbnail(ctx context.Context, file *model.File) {
// 新建上下文
newCtx, cancel := context.WithCancel(context.Background())
defer cancel()
// TODO: check file size
// 获取文件数据
source, err := fs.Handler.Get(newCtx, file.SourceName)

Loading…
Cancel
Save