提交 16613a61 编写于 作者: H HFO4

Modify: return parent folder id while listing objects

上级 4c530a26
......@@ -13,7 +13,6 @@ type Group struct {
MaxStorage uint64
ShareEnabled bool
WebDAVEnabled bool
Aria2Option string
Color string
SpeedLimit int
Options string `json:"-",gorm:"type:text"`
......@@ -36,18 +35,6 @@ type GroupOption struct {
Aria2Options []interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
}
// GetAria2Option 获取用户离线下载设备
func (group *Group) GetAria2Option() [3]bool {
if len(group.Aria2Option) != 5 {
return [3]bool{false, false, false}
}
return [3]bool{
group.Aria2Option[0] == '1',
group.Aria2Option[2] == '1',
group.Aria2Option[4] == '1',
}
}
// GetGroupByID 用ID获取用户组
func GetGroupByID(ID interface{}) (Group, error) {
var group Group
......
......@@ -63,22 +63,6 @@ func TestGroup_AfterFind(t *testing.T) {
asserts.Equal(testCase.PolicyList, []uint{})
}
func TestGroup_GetAria2Option(t *testing.T) {
asserts := assert.New(t)
group := Group{}
// 格式错误
{
group.Aria2Option = "123"
asserts.Equal([3]bool{false, false, false}, group.GetAria2Option())
}
// 正常
{
group.Aria2Option = "1,1,0"
asserts.Equal([3]bool{true, true, false}, group.GetAria2Option())
}
}
func TestGroup_BeforeSave(t *testing.T) {
asserts := assert.New(t)
group := Group{
......
......@@ -188,7 +188,6 @@ func addDefaultGroups() {
ShareEnabled: true,
Color: "danger",
WebDAVEnabled: true,
Aria2Option: "0,0,0",
OptionsSerialized: GroupOption{
ArchiveDownload: true,
ArchiveTask: true,
......@@ -211,7 +210,6 @@ func addDefaultGroups() {
ShareEnabled: true,
Color: "danger",
WebDAVEnabled: true,
Aria2Option: "0,0,0",
}
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
util.Log().Panic("无法创建初始注册会员用户组, %s", err)
......
......@@ -67,6 +67,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
downloadURL,
nil,
request.WithContext(ctx),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -10,6 +10,7 @@ import (
"github.com/HFO4/cloudreve/pkg/serializer"
"io"
"net/url"
"time"
)
// Driver OneDrive 适配器
......@@ -40,6 +41,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
downloadURL,
nil,
request.WithContext(ctx),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -99,6 +99,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
downloadURL,
nil,
request.WithContext(ctx),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -50,6 +50,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
request.WithHeader(
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -17,6 +17,7 @@ import (
"net/url"
"path"
"strings"
"time"
)
// Driver 远程存储策略适配器
......@@ -70,6 +71,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
downloadURL,
nil,
request.WithContext(ctx),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -68,6 +68,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
request.WithHeader(
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
),
request.WithTimeout(time.Duration(0)),
).CheckHTTPResponse(200).GetRSCloser()
if err != nil {
return nil, err
......
......@@ -257,6 +257,7 @@ func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor fu
if !isExist {
return []Object{}, nil
}
fs.SetTargetDir(&[]model.Folder{*folder})
var parentPath = path.Join(folder.Position, folder.Name)
var childFolders []model.Folder
......
......@@ -44,6 +44,7 @@ type group struct {
AllowArchiveDownload bool `json:"allowArchiveDownload"`
ShareFreeEnabled bool `json:"shareFree"`
ShareDownload bool `json:"shareDownload"`
CompressEnabled bool `json:"compress"`
}
type storage struct {
......@@ -54,7 +55,6 @@ type storage struct {
// BuildUser 序列化用户
func BuildUser(user model.User) User {
aria2Option := user.Group.GetAria2Option()
return User{
ID: user.ID,
Email: user.Email,
......@@ -75,11 +75,11 @@ func BuildUser(user model.User) User {
ID: user.GroupID,
Name: user.Group.Name,
AllowShare: user.Group.ShareEnabled,
AllowRemoteDownload: aria2Option[0],
AllowTorrentDownload: aria2Option[2],
AllowRemoteDownload: user.Group.OptionsSerialized.Aria2,
AllowArchiveDownload: user.Group.OptionsSerialized.ArchiveDownload,
ShareFreeEnabled: user.Group.OptionsSerialized.ShareFree,
ShareDownload: user.Group.OptionsSerialized.ShareDownload,
CompressEnabled: user.Group.OptionsSerialized.ArchiveTask,
},
}
}
......
......@@ -31,9 +31,17 @@ func (service *DirectoryService) ListDirectory(c *gin.Context) serializer.Respon
return serializer.Err(serializer.CodeCreateFolderFailed, err.Error(), err)
}
var parentID uint
if len(fs.DirTarget) > 0 {
parentID = fs.DirTarget[0].ID
}
return serializer.Response{
Code: 0,
Data: objects,
Data: map[string]interface{}{
"parent": parentID,
"objects": objects,
},
}
}
......
......@@ -215,9 +215,17 @@ func (service *Service) List(c *gin.Context) serializer.Response {
return serializer.Err(serializer.CodeCreateFolderFailed, err.Error(), err)
}
var parentID uint
if len(fs.DirTarget) > 0 {
parentID = fs.DirTarget[0].ID
}
return serializer.Response{
Code: 0,
Data: objects,
Data: map[string]interface{}{
"parent": parentID,
"objects": objects,
},
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册