Feat: WebDAV mount folders

This commit is contained in:
HFO4
2020-02-18 13:45:59 +08:00
parent 86889e2fac
commit b4219927d6
8 changed files with 209 additions and 0 deletions

View File

@@ -2,6 +2,8 @@ package serializer
import (
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/hashid"
"github.com/HFO4/cloudreve/pkg/util"
)
type quota struct {
@@ -20,6 +22,58 @@ type storagePacks struct {
ExpirationDate string `json:"expiration_date"`
}
// MountedFolders 已挂载的目录
type MountedFolders struct {
ID string `json:"id"`
Name string `json:"name"`
PolicyName string `json:"policy_name"`
}
type policyOptions struct {
Name string `json:"name"`
ID string `json:"id"`
}
// BuildPolicySettingRes 构建存储策略选项选择
func BuildPolicySettingRes(policies []model.Policy, current *model.Policy) Response {
options := make([]policyOptions, 0, len(policies))
for _, policy := range policies {
options = append(options, policyOptions{
Name: policy.Name,
ID: hashid.HashID(policy.ID, hashid.PolicyID),
})
}
return Response{
Data: map[string]interface{}{
"options": options,
"current": policyOptions{
Name: current.Name,
ID: hashid.HashID(current.ID, hashid.PolicyID),
},
},
}
}
// BuildMountedFolderRes 构建已挂载目录响应list为当前用户可用存储策略ID
func BuildMountedFolderRes(folders []model.Folder, list []uint) []MountedFolders {
res := make([]MountedFolders, 0, len(folders))
for _, folder := range folders {
single := MountedFolders{
ID: hashid.HashID(folder.ID, hashid.FolderID),
Name: folder.Name,
PolicyName: "[已失效存储策略]",
}
if policy, err := model.GetPolicyByID(folder.PolicyID); err == nil && util.ContainsUint(list, policy.ID) {
single.PolicyName = policy.Name
}
res = append(res, single)
}
return res
}
// BuildUserQuotaResponse 序列化用户存储配额概况响应
func BuildUserQuotaResponse(user *model.User, packs []model.StoragePack) Response {
packSize := user.GetAvailablePackSize()