Fix: upload was marked canceled when small file uploaded

This commit is contained in:
HFO4
2019-11-27 12:49:31 +08:00
parent 4156a71adf
commit 29def02489
8 changed files with 71 additions and 21 deletions

View File

@@ -2,9 +2,7 @@ package filesystem
import (
"context"
"errors"
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/HFO4/cloudreve/pkg/util"
"io"
)
@@ -37,9 +35,9 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
return &newFile, nil
}
// Download 处理下载文件请求path为虚拟路径
// GetContent 获取文件内容path为虚拟路径
// TODO:测试
func (fs *FileSystem) Download(ctx context.Context, path string) (io.ReadCloser, error) {
func (fs *FileSystem) GetContent(ctx context.Context, path string) (io.ReadSeeker, error) {
// 触发`下载前`钩子
err := fs.Trigger(ctx, fs.BeforeFileDownload)
if err != nil {
@@ -52,6 +50,7 @@ func (fs *FileSystem) Download(ctx context.Context, path string) (io.ReadCloser,
if !exist {
return nil, ErrObjectNotExist
}
fs.Target = &file
// 将当前存储策略重设为文件使用的
fs.Policy = file.GetPolicy()
@@ -60,5 +59,11 @@ func (fs *FileSystem) Download(ctx context.Context, path string) (io.ReadCloser,
return nil, err
}
return nil, serializer.NewError(serializer.CodeEncryptError, "人都的", errors.New("不是人都的"))
// 获取文件流
rs, err := fs.Handler.Get(ctx, file.SourceName)
if err != nil {
return nil, ErrIO.WithError(err)
}
return rs, nil
}