mirror of https://github.com/cloudreve/Cloudreve
Modify: return parent folder id while listing objects
parent
4c530a26a0
commit
16613a6113
|
@ -13,7 +13,6 @@ type Group struct {
|
||||||
MaxStorage uint64
|
MaxStorage uint64
|
||||||
ShareEnabled bool
|
ShareEnabled bool
|
||||||
WebDAVEnabled bool
|
WebDAVEnabled bool
|
||||||
Aria2Option string
|
|
||||||
Color string
|
Color string
|
||||||
SpeedLimit int
|
SpeedLimit int
|
||||||
Options string `json:"-",gorm:"type:text"`
|
Options string `json:"-",gorm:"type:text"`
|
||||||
|
@ -36,18 +35,6 @@ type GroupOption struct {
|
||||||
Aria2Options []interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
|
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获取用户组
|
// GetGroupByID 用ID获取用户组
|
||||||
func GetGroupByID(ID interface{}) (Group, error) {
|
func GetGroupByID(ID interface{}) (Group, error) {
|
||||||
var group Group
|
var group Group
|
||||||
|
|
|
@ -63,22 +63,6 @@ func TestGroup_AfterFind(t *testing.T) {
|
||||||
asserts.Equal(testCase.PolicyList, []uint{})
|
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) {
|
func TestGroup_BeforeSave(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
group := Group{
|
group := Group{
|
||||||
|
|
|
@ -188,7 +188,6 @@ func addDefaultGroups() {
|
||||||
ShareEnabled: true,
|
ShareEnabled: true,
|
||||||
Color: "danger",
|
Color: "danger",
|
||||||
WebDAVEnabled: true,
|
WebDAVEnabled: true,
|
||||||
Aria2Option: "0,0,0",
|
|
||||||
OptionsSerialized: GroupOption{
|
OptionsSerialized: GroupOption{
|
||||||
ArchiveDownload: true,
|
ArchiveDownload: true,
|
||||||
ArchiveTask: true,
|
ArchiveTask: true,
|
||||||
|
@ -211,7 +210,6 @@ func addDefaultGroups() {
|
||||||
ShareEnabled: true,
|
ShareEnabled: true,
|
||||||
Color: "danger",
|
Color: "danger",
|
||||||
WebDAVEnabled: true,
|
WebDAVEnabled: true,
|
||||||
Aria2Option: "0,0,0",
|
|
||||||
}
|
}
|
||||||
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
||||||
util.Log().Panic("无法创建初始注册会员用户组, %s", err)
|
util.Log().Panic("无法创建初始注册会员用户组, %s", err)
|
||||||
|
|
|
@ -67,6 +67,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
downloadURL,
|
downloadURL,
|
||||||
nil,
|
nil,
|
||||||
request.WithContext(ctx),
|
request.WithContext(ctx),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Driver OneDrive 适配器
|
// Driver OneDrive 适配器
|
||||||
|
@ -40,6 +41,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
downloadURL,
|
downloadURL,
|
||||||
nil,
|
nil,
|
||||||
request.WithContext(ctx),
|
request.WithContext(ctx),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -99,6 +99,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
downloadURL,
|
downloadURL,
|
||||||
nil,
|
nil,
|
||||||
request.WithContext(ctx),
|
request.WithContext(ctx),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -50,6 +50,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
request.WithHeader(
|
request.WithHeader(
|
||||||
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
|
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
|
||||||
),
|
),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Driver 远程存储策略适配器
|
// Driver 远程存储策略适配器
|
||||||
|
@ -70,6 +71,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
downloadURL,
|
downloadURL,
|
||||||
nil,
|
nil,
|
||||||
request.WithContext(ctx),
|
request.WithContext(ctx),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -68,6 +68,7 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||||
request.WithHeader(
|
request.WithHeader(
|
||||||
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
|
http.Header{"Cache-Control": {"no-cache", "no-store", "must-revalidate"}},
|
||||||
),
|
),
|
||||||
|
request.WithTimeout(time.Duration(0)),
|
||||||
).CheckHTTPResponse(200).GetRSCloser()
|
).CheckHTTPResponse(200).GetRSCloser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -257,6 +257,7 @@ func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor fu
|
||||||
if !isExist {
|
if !isExist {
|
||||||
return []Object{}, nil
|
return []Object{}, nil
|
||||||
}
|
}
|
||||||
|
fs.SetTargetDir(&[]model.Folder{*folder})
|
||||||
|
|
||||||
var parentPath = path.Join(folder.Position, folder.Name)
|
var parentPath = path.Join(folder.Position, folder.Name)
|
||||||
var childFolders []model.Folder
|
var childFolders []model.Folder
|
||||||
|
|
|
@ -44,6 +44,7 @@ type group struct {
|
||||||
AllowArchiveDownload bool `json:"allowArchiveDownload"`
|
AllowArchiveDownload bool `json:"allowArchiveDownload"`
|
||||||
ShareFreeEnabled bool `json:"shareFree"`
|
ShareFreeEnabled bool `json:"shareFree"`
|
||||||
ShareDownload bool `json:"shareDownload"`
|
ShareDownload bool `json:"shareDownload"`
|
||||||
|
CompressEnabled bool `json:"compress"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type storage struct {
|
type storage struct {
|
||||||
|
@ -54,7 +55,6 @@ type storage struct {
|
||||||
|
|
||||||
// BuildUser 序列化用户
|
// BuildUser 序列化用户
|
||||||
func BuildUser(user model.User) User {
|
func BuildUser(user model.User) User {
|
||||||
aria2Option := user.Group.GetAria2Option()
|
|
||||||
return User{
|
return User{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
|
@ -75,11 +75,11 @@ func BuildUser(user model.User) User {
|
||||||
ID: user.GroupID,
|
ID: user.GroupID,
|
||||||
Name: user.Group.Name,
|
Name: user.Group.Name,
|
||||||
AllowShare: user.Group.ShareEnabled,
|
AllowShare: user.Group.ShareEnabled,
|
||||||
AllowRemoteDownload: aria2Option[0],
|
AllowRemoteDownload: user.Group.OptionsSerialized.Aria2,
|
||||||
AllowTorrentDownload: aria2Option[2],
|
|
||||||
AllowArchiveDownload: user.Group.OptionsSerialized.ArchiveDownload,
|
AllowArchiveDownload: user.Group.OptionsSerialized.ArchiveDownload,
|
||||||
ShareFreeEnabled: user.Group.OptionsSerialized.ShareFree,
|
ShareFreeEnabled: user.Group.OptionsSerialized.ShareFree,
|
||||||
ShareDownload: user.Group.OptionsSerialized.ShareDownload,
|
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)
|
return serializer.Err(serializer.CodeCreateFolderFailed, err.Error(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var parentID uint
|
||||||
|
if len(fs.DirTarget) > 0 {
|
||||||
|
parentID = fs.DirTarget[0].ID
|
||||||
|
}
|
||||||
|
|
||||||
return serializer.Response{
|
return serializer.Response{
|
||||||
Code: 0,
|
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)
|
return serializer.Err(serializer.CodeCreateFolderFailed, err.Error(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var parentID uint
|
||||||
|
if len(fs.DirTarget) > 0 {
|
||||||
|
parentID = fs.DirTarget[0].ID
|
||||||
|
}
|
||||||
|
|
||||||
return serializer.Response{
|
return serializer.Response{
|
||||||
Code: 0,
|
Code: 0,
|
||||||
Data: objects,
|
Data: map[string]interface{}{
|
||||||
|
"parent": parentID,
|
||||||
|
"objects": objects,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue