Feat: file download in service level

This commit is contained in:
HFO4
2019-11-26 20:59:57 +08:00
parent a734493b65
commit 4156a71adf
10 changed files with 99 additions and 30 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/HFO4/cloudreve/pkg/util"
"io"
)
@@ -36,7 +37,28 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
return &newFile, nil
}
// Download 处理下载文件请求
// Download 处理下载文件请求path为虚拟路径
// TODO:测试
func (fs *FileSystem) Download(ctx context.Context, path string) (io.ReadCloser, error) {
// 触发`下载前`钩子
err := fs.Trigger(ctx, fs.BeforeFileDownload)
if err != nil {
util.Log().Debug("BeforeFileDownload 钩子执行失败,%s", err)
return nil, err
}
// 找到文件
exist, file := fs.IsFileExist(path)
if !exist {
return nil, ErrObjectNotExist
}
// 将当前存储策略重设为文件使用的
fs.Policy = file.GetPolicy()
err = fs.dispatchHandler()
if err != nil {
return nil, err
}
return nil, serializer.NewError(serializer.CodeEncryptError, "人都的", errors.New("不是人都的"))
}