mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: file download in service level
This commit is contained in:
@@ -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("不是人都的"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user