github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/serializer/explorer.go (about) 1 package serializer 2 3 import ( 4 "encoding/gob" 5 model "github.com/cloudreve/Cloudreve/v3/models" 6 "github.com/cloudreve/Cloudreve/v3/pkg/hashid" 7 "time" 8 ) 9 10 func init() { 11 gob.Register(ObjectProps{}) 12 } 13 14 // ObjectProps 文件、目录对象的详细属性信息 15 type ObjectProps struct { 16 CreatedAt time.Time `json:"created_at"` 17 UpdatedAt time.Time `json:"updated_at"` 18 Policy string `json:"policy"` 19 Size uint64 `json:"size"` 20 ChildFolderNum int `json:"child_folder_num"` 21 ChildFileNum int `json:"child_file_num"` 22 Path string `json:"path"` 23 24 QueryDate time.Time `json:"query_date"` 25 } 26 27 // ObjectList 文件、目录列表 28 type ObjectList struct { 29 Parent string `json:"parent,omitempty"` 30 Objects []Object `json:"objects"` 31 Policy *PolicySummary `json:"policy,omitempty"` 32 } 33 34 // Object 文件或者目录 35 type Object struct { 36 ID string `json:"id"` 37 Name string `json:"name"` 38 Path string `json:"path"` 39 Thumb bool `json:"thumb"` 40 Size uint64 `json:"size"` 41 Type string `json:"type"` 42 Date time.Time `json:"date"` 43 CreateDate time.Time `json:"create_date"` 44 Key string `json:"key,omitempty"` 45 SourceEnabled bool `json:"source_enabled"` 46 } 47 48 // PolicySummary 用于前端组件使用的存储策略概况 49 type PolicySummary struct { 50 ID string `json:"id"` 51 Name string `json:"name"` 52 Type string `json:"type"` 53 MaxSize uint64 `json:"max_size"` 54 FileType []string `json:"file_type"` 55 } 56 57 // BuildObjectList 构建列目录响应 58 func BuildObjectList(parent uint, objects []Object, policy *model.Policy) ObjectList { 59 res := ObjectList{ 60 Objects: objects, 61 } 62 63 if parent > 0 { 64 res.Parent = hashid.HashID(parent, hashid.FolderID) 65 } 66 67 if policy != nil { 68 res.Policy = &PolicySummary{ 69 ID: hashid.HashID(policy.ID, hashid.PolicyID), 70 Name: policy.Name, 71 Type: policy.Type, 72 MaxSize: policy.MaxSize, 73 FileType: policy.OptionsSerialized.FileType, 74 } 75 } 76 77 return res 78 } 79 80 // Sources 获取外链的结果响应 81 type Sources struct { 82 URL string `json:"url"` 83 Name string `json:"name"` 84 Parent uint `json:"parent"` 85 Error string `json:"error,omitempty"` 86 } 87 88 // DocPreviewSession 文档预览会话响应 89 type DocPreviewSession struct { 90 URL string `json:"url"` 91 AccessToken string `json:"access_token,omitempty"` 92 AccessTokenTTL int64 `json:"access_token_ttl,omitempty"` 93 } 94 95 // WopiFileInfo Response for `CheckFileInfo` 96 type WopiFileInfo struct { 97 // Required 98 BaseFileName string 99 Version string 100 Size int64 101 102 // Breadcrumb 103 BreadcrumbBrandName string 104 BreadcrumbBrandUrl string 105 BreadcrumbFolderName string 106 BreadcrumbFolderUrl string 107 108 // Post Message 109 FileSharingPostMessage bool 110 ClosePostMessage bool 111 PostMessageOrigin string 112 113 // Other miscellaneous properties 114 FileNameMaxLength int 115 LastModifiedTime string 116 117 // User metadata 118 IsAnonymousUser bool 119 UserFriendlyName string 120 UserId string 121 OwnerId string 122 123 // Permission 124 ReadOnly bool 125 UserCanRename bool 126 UserCanReview bool 127 UserCanWrite bool 128 129 SupportsRename bool 130 SupportsReviewing bool 131 SupportsUpdate bool 132 }