Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
68d4a861
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
68d4a861
编写于
1月 17, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: storage policy should be re-dispatched according to policy id in upload session
上级
b862ddb6
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
22 addition
and
45 deletion
+22
-45
middleware/auth.go
middleware/auth.go
+0
-5
middleware/auth_test.go
middleware/auth_test.go
+0
-30
pkg/filesystem/archive.go
pkg/filesystem/archive.go
+1
-1
pkg/filesystem/file.go
pkg/filesystem/file.go
+3
-3
pkg/filesystem/filesystem.go
pkg/filesystem/filesystem.go
+3
-3
pkg/filesystem/filesystem_test.go
pkg/filesystem/filesystem_test.go
+2
-2
pkg/filesystem/hooks.go
pkg/filesystem/hooks.go
+1
-1
service/callback/upload.go
service/callback/upload.go
+12
-0
未找到文件。
middleware/auth.go
浏览文件 @
68d4a861
...
...
@@ -132,11 +132,6 @@ func uploadCallbackCheck(c *gin.Context) (serializer.Response, *model.User) {
}
c
.
Set
(
"user"
,
&
user
)
// 检查存储策略是否一致
if
user
.
GetPolicyID
()
!=
callbackSession
.
PolicyID
{
return
serializer
.
Err
(
serializer
.
CodePolicyNotAllowed
,
"存储策略已变更,请重新上传"
,
nil
),
nil
}
return
serializer
.
Response
{},
&
user
}
...
...
middleware/auth_test.go
浏览文件 @
68d4a861
...
...
@@ -277,36 +277,6 @@ func TestRemoteCallbackAuth(t *testing.T) {
asserts
.
True
(
c
.
IsAborted
())
}
// 存储策略不一致
{
cache
.
Set
(
"callback_testCallBackRemote"
,
serializer
.
UploadSession
{
UID
:
1
,
PolicyID
:
2
,
VirtualPath
:
"/"
,
},
0
,
)
cache
.
Deletes
([]
string
{
"1"
},
"policy_"
)
mock
.
ExpectQuery
(
"SELECT(.+)users(.+)"
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
,
"group_id"
})
.
AddRow
(
1
,
1
))
mock
.
ExpectQuery
(
"SELECT(.+)groups(.+)"
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
,
"policies"
})
.
AddRow
(
1
,
"[3]"
))
mock
.
ExpectQuery
(
"SELECT(.+)policies(.+)"
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
,
"secret_key"
})
.
AddRow
(
3
,
"123"
))
c
,
_
:=
gin
.
CreateTestContext
(
rec
)
c
.
Params
=
[]
gin
.
Param
{
{
"key"
,
"testCallBackRemote"
},
}
c
.
Request
,
_
=
http
.
NewRequest
(
"POST"
,
"/api/v3/callback/remote/testCallBackRemote"
,
nil
)
authInstance
:=
auth
.
HMACAuth
{
SecretKey
:
[]
byte
(
"123"
)}
auth
.
SignRequest
(
authInstance
,
c
.
Request
,
0
)
AuthFunc
(
c
)
asserts
.
NoError
(
mock
.
ExpectationsWereMet
())
asserts
.
True
(
c
.
IsAborted
())
}
// 签名错误
{
cache
.
Set
(
...
...
pkg/filesystem/archive.go
浏览文件 @
68d4a861
...
...
@@ -105,7 +105,7 @@ func (fs *FileSystem) doCompress(ctx context.Context, file *model.File, folder *
if
file
!=
nil
{
// 切换上传策略
fs
.
Policy
=
file
.
GetPolicy
()
err
:=
fs
.
d
ispatchHandler
()
err
:=
fs
.
D
ispatchHandler
()
if
err
!=
nil
{
util
.
Log
()
.
Warning
(
"无法压缩文件%s,%s"
,
file
.
Name
,
err
)
return
...
...
pkg/filesystem/file.go
浏览文件 @
68d4a861
...
...
@@ -79,7 +79,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
func
(
fs
*
FileSystem
)
GetPhysicalFileContent
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
// 重设上传策略
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"local"
}
_
=
fs
.
d
ispatchHandler
()
_
=
fs
.
D
ispatchHandler
()
// 获取文件流
rs
,
err
:=
fs
.
Handler
.
Get
(
ctx
,
path
)
...
...
@@ -184,7 +184,7 @@ func (fs *FileSystem) deleteGroupedFile(ctx context.Context, files map[uint][]*m
// 切换上传策略
fs
.
Policy
=
toBeDeletedFiles
[
0
]
.
GetPolicy
()
err
:=
fs
.
d
ispatchHandler
()
err
:=
fs
.
D
ispatchHandler
()
if
err
!=
nil
{
failed
[
policyID
]
=
sourceNames
continue
...
...
@@ -327,7 +327,7 @@ func (fs *FileSystem) resetPolicyToFirstFile(ctx context.Context) error {
}
fs
.
Policy
=
fs
.
FileTarget
[
0
]
.
GetPolicy
()
err
:=
fs
.
d
ispatchHandler
()
err
:=
fs
.
D
ispatchHandler
()
if
err
!=
nil
{
return
err
}
...
...
pkg/filesystem/filesystem.go
浏览文件 @
68d4a861
...
...
@@ -109,7 +109,7 @@ func NewFileSystem(user *model.User) (*FileSystem, error) {
fs
:=
getEmptyFS
()
fs
.
User
=
user
// 分配存储策略适配器
err
:=
fs
.
d
ispatchHandler
()
err
:=
fs
.
D
ispatchHandler
()
// TODO 分配默认钩子
return
fs
,
err
...
...
@@ -135,9 +135,9 @@ func NewAnonymousFileSystem() (*FileSystem, error) {
return
fs
,
nil
}
//
d
ispatchHandler 根据存储策略分配文件适配器
//
D
ispatchHandler 根据存储策略分配文件适配器
// TODO 完善测试
func
(
fs
*
FileSystem
)
d
ispatchHandler
()
error
{
func
(
fs
*
FileSystem
)
D
ispatchHandler
()
error
{
var
policyType
string
var
currentPolicy
*
model
.
Policy
...
...
pkg/filesystem/filesystem_test.go
浏览文件 @
68d4a861
...
...
@@ -64,13 +64,13 @@ func TestDispatchHandler(t *testing.T) {
}
// 未指定,使用用户默认
err
:=
fs
.
d
ispatchHandler
()
err
:=
fs
.
D
ispatchHandler
()
asserts
.
NoError
(
err
)
asserts
.
IsType
(
local
.
Driver
{},
fs
.
Handler
)
// 已指定,发生错误
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"unknown"
}
err
=
fs
.
d
ispatchHandler
()
err
=
fs
.
D
ispatchHandler
()
asserts
.
Error
(
err
)
}
...
...
pkg/filesystem/hooks.go
浏览文件 @
68d4a861
...
...
@@ -106,7 +106,7 @@ func HookResetPolicy(ctx context.Context, fs *FileSystem) error {
}
fs
.
Policy
=
originFile
.
GetPolicy
()
return
fs
.
d
ispatchHandler
()
return
fs
.
D
ispatchHandler
()
}
// HookValidateCapacity 验证并扣除用户容量,包含数据库操作
...
...
service/callback/upload.go
浏览文件 @
68d4a861
...
...
@@ -2,6 +2,7 @@ package callback
import
(
"context"
model
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/filesystem"
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
"github.com/HFO4/cloudreve/pkg/filesystem/local"
...
...
@@ -61,6 +62,17 @@ func ProcessCallback(service CallbackProcessService, c *gin.Context) serializer.
}
callbackSession
:=
callbackSessionRaw
.
(
*
serializer
.
UploadSession
)
// 重新指向上传策略
policy
,
err
:=
model
.
GetPolicyByID
(
callbackSession
.
PolicyID
)
if
err
!=
nil
{
return
serializer
.
Err
(
serializer
.
CodePolicyNotAllowed
,
err
.
Error
(),
err
)
}
fs
.
Policy
=
&
policy
err
=
fs
.
DispatchHandler
()
if
err
!=
nil
{
return
serializer
.
Err
(
serializer
.
CodePolicyNotAllowed
,
err
.
Error
(),
err
)
}
// 获取父目录
exist
,
parentFolder
:=
fs
.
IsPathExist
(
callbackSession
.
VirtualPath
)
if
!
exist
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录