Feat: onedrive client upload / callback

This commit is contained in:
HFO4
2020-01-20 14:34:21 +08:00
parent 807aa5ac18
commit dd5f6e3d25
10 changed files with 359 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package filesystem
import (
"context"
"errors"
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/auth"
"github.com/HFO4/cloudreve/pkg/conf"
@@ -195,7 +196,6 @@ func (fs *FileSystem) DispatchHandler() error {
}
// NewFileSystemFromContext 从gin.Context创建文件系统
// TODO 用户不存在时使用匿名文件系统
func NewFileSystemFromContext(c *gin.Context) (*FileSystem, error) {
user, exist := c.Get("user")
if !exist {
@@ -205,6 +205,33 @@ func NewFileSystemFromContext(c *gin.Context) (*FileSystem, error) {
return fs, err
}
// NewFileSystemFromCallback 从gin.Context创建回调用文件系统
// TODO 测试
func NewFileSystemFromCallback(c *gin.Context) (*FileSystem, error) {
fs, err := NewFileSystemFromContext(c)
if err != nil {
return nil, err
}
// 获取回调会话
callbackSessionRaw, ok := c.Get("callbackSession")
if !ok {
return nil, errors.New("找不到回调会话")
}
callbackSession := callbackSessionRaw.(*serializer.UploadSession)
// 重新指向上传策略
policy, err := model.GetPolicyByID(callbackSession.PolicyID)
if err != nil {
return nil, err
}
fs.Policy = &policy
fs.User.Policy = policy
err = fs.DispatchHandler()
return fs, err
}
// SetTargetFile 设置当前处理的目标文件
func (fs *FileSystem) SetTargetFile(files *[]model.File) {
if len(fs.FileTarget) == 0 {