mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: get policy from directory props / Feat: return source enabled flag in file list
This commit is contained in:
@@ -2,6 +2,8 @@ package serializer
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -21,3 +23,55 @@ type ObjectProps struct {
|
||||
|
||||
QueryDate time.Time `json:"query_date"`
|
||||
}
|
||||
|
||||
// ObjectList 文件、目录列表
|
||||
type ObjectList struct {
|
||||
Parent string `json:"parent,omitempty"`
|
||||
Objects []Object `json:"objects"`
|
||||
Policy *PolicySummary `json:"policy,omitempty"`
|
||||
}
|
||||
|
||||
// Object 文件或者目录
|
||||
type Object struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Pic string `json:"pic"`
|
||||
Size uint64 `json:"size"`
|
||||
Type string `json:"type"`
|
||||
Date time.Time `json:"date"`
|
||||
Key string `json:"key,omitempty"`
|
||||
SourceEnabled bool `json:"source_enabled"`
|
||||
}
|
||||
|
||||
// PolicySummary 用于前端组件使用的存储策略概况
|
||||
type PolicySummary struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
MaxSize uint64 `json:"max_size"`
|
||||
FileType []string `json:"file_type"`
|
||||
}
|
||||
|
||||
// BuildObjectList 构建列目录响应
|
||||
func BuildObjectList(parent uint, objects []Object, policy *model.Policy) ObjectList {
|
||||
res := ObjectList{
|
||||
Objects: objects,
|
||||
}
|
||||
|
||||
if parent > 0 {
|
||||
res.Parent = hashid.HashID(parent, hashid.FolderID)
|
||||
}
|
||||
|
||||
if policy != nil {
|
||||
res.Policy = &PolicySummary{
|
||||
ID: hashid.HashID(policy.ID, hashid.PolicyID),
|
||||
Name: policy.Name,
|
||||
Type: policy.Type,
|
||||
MaxSize: policy.MaxSize,
|
||||
FileType: policy.OptionsSerialized.FileType,
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ type User struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
PreferredTheme string `json:"preferred_theme"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
Policy policy `json:"policy"`
|
||||
Group group `json:"group"`
|
||||
Tags []tag `json:"tags"`
|
||||
}
|
||||
@@ -98,13 +97,6 @@ func BuildUser(user model.User) User {
|
||||
CreatedAt: user.CreatedAt,
|
||||
PreferredTheme: user.OptionsSerialized.PreferredTheme,
|
||||
Anonymous: user.IsAnonymous(),
|
||||
Policy: policy{
|
||||
SaveType: user.Policy.Type,
|
||||
MaxSize: fmt.Sprintf("%.2fmb", float64(user.Policy.MaxSize)/(1024*1024)),
|
||||
AllowedType: user.Policy.OptionsSerialized.FileType,
|
||||
UploadURL: user.Policy.GetUploadURL(),
|
||||
AllowGetSource: user.Policy.IsOriginLinkEnable,
|
||||
},
|
||||
Group: group{
|
||||
ID: user.GroupID,
|
||||
Name: user.Group.Name,
|
||||
|
||||
Reference in New Issue
Block a user