feat(fs): custom properties for files (#2407)
This commit is contained in:
@@ -59,11 +59,17 @@ type (
|
||||
StoragePolicyID int
|
||||
}
|
||||
|
||||
MetadataFilter struct {
|
||||
Key string
|
||||
Value string
|
||||
Exact bool
|
||||
}
|
||||
|
||||
SearchFileParameters struct {
|
||||
Name []string
|
||||
// NameOperatorOr is true if the name should match any of the given names, false if all of them
|
||||
NameOperatorOr bool
|
||||
Metadata map[string]string
|
||||
Metadata []MetadataFilter
|
||||
Type *types.FileType
|
||||
UseFullText bool
|
||||
CaseFolding bool
|
||||
|
||||
@@ -16,6 +16,10 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const (
|
||||
metadataExactMatchPrefix = "!exact:"
|
||||
)
|
||||
|
||||
func (f *fileClient) searchQuery(q *ent.FileQuery, args *SearchFileParameters, parents []*ent.File, ownerId int) *ent.FileQuery {
|
||||
if len(parents) == 1 && parents[0] == nil {
|
||||
q = q.Where(file.OwnerID(ownerId))
|
||||
@@ -69,13 +73,17 @@ func (f *fileClient) searchQuery(q *ent.FileQuery, args *SearchFileParameters, p
|
||||
}
|
||||
|
||||
if len(args.Metadata) > 0 {
|
||||
metaPredicates := lo.MapToSlice(args.Metadata, func(name string, value string) predicate.Metadata {
|
||||
nameEq := metadata.NameEQ(value)
|
||||
if name == "" {
|
||||
metaPredicates := lo.Map(args.Metadata, func(item MetadataFilter, index int) predicate.Metadata {
|
||||
if item.Exact {
|
||||
return metadata.And(metadata.NameEQ(item.Key), metadata.ValueEQ(item.Value))
|
||||
}
|
||||
|
||||
nameEq := metadata.NameEQ(item.Key)
|
||||
if item.Value == "" {
|
||||
return nameEq
|
||||
} else {
|
||||
valueContain := metadata.ValueContainsFold(value)
|
||||
return metadata.And(metadata.NameEQ(name), valueContain)
|
||||
valueContain := metadata.ValueContainsFold(item.Value)
|
||||
return metadata.And(nameEq, valueContain)
|
||||
}
|
||||
})
|
||||
metaPredicates = append(metaPredicates, metadata.IsPublic(true))
|
||||
|
||||
@@ -324,6 +324,22 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
defaultFileProps = []types.CustomProps{
|
||||
{
|
||||
ID: "description",
|
||||
Type: types.CustomPropsTypeText,
|
||||
Name: "fileManager.description",
|
||||
Icon: "fluent:slide-text-24-filled",
|
||||
},
|
||||
{
|
||||
ID: "rating",
|
||||
Type: types.CustomPropsTypeRating,
|
||||
Name: "fileManager.rating",
|
||||
Icon: "fluent:data-bar-vertical-star-24-filled",
|
||||
Max: 5,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
var DefaultSettings = map[string]string{
|
||||
@@ -516,4 +532,10 @@ func init() {
|
||||
}
|
||||
|
||||
DefaultSettings["file_viewers"] = string(viewers)
|
||||
|
||||
customProps, err := json.Marshal(defaultFileProps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
DefaultSettings["custom_props"] = string(customProps)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,8 @@ type (
|
||||
}
|
||||
|
||||
ColumTypeProps struct {
|
||||
MetadataKey string `json:"metadata_key,omitempty" binding:"max=255"`
|
||||
MetadataKey string `json:"metadata_key,omitempty" binding:"max=255"`
|
||||
CustomPropsID string `json:"custom_props_id,omitempty" binding:"max=255"`
|
||||
}
|
||||
|
||||
ShareProps struct {
|
||||
@@ -278,26 +279,51 @@ const (
|
||||
ViewerTypeCustom = "custom"
|
||||
)
|
||||
|
||||
type Viewer struct {
|
||||
ID string `json:"id"`
|
||||
Type ViewerType `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Exts []string `json:"exts"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
WopiActions map[string]map[ViewerAction]string `json:"wopi_actions,omitempty"`
|
||||
Props map[string]string `json:"props,omitempty"`
|
||||
MaxSize int64 `json:"max_size,omitempty"`
|
||||
Disabled bool `json:"disabled,omitempty"`
|
||||
Templates []NewFileTemplate `json:"templates,omitempty"`
|
||||
Platform string `json:"platform,omitempty"`
|
||||
}
|
||||
type (
|
||||
Viewer struct {
|
||||
ID string `json:"id"`
|
||||
Type ViewerType `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Exts []string `json:"exts"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
WopiActions map[string]map[ViewerAction]string `json:"wopi_actions,omitempty"`
|
||||
Props map[string]string `json:"props,omitempty"`
|
||||
MaxSize int64 `json:"max_size,omitempty"`
|
||||
Disabled bool `json:"disabled,omitempty"`
|
||||
Templates []NewFileTemplate `json:"templates,omitempty"`
|
||||
Platform string `json:"platform,omitempty"`
|
||||
}
|
||||
ViewerGroup struct {
|
||||
Viewers []Viewer `json:"viewers"`
|
||||
}
|
||||
|
||||
type ViewerGroup struct {
|
||||
Viewers []Viewer `json:"viewers"`
|
||||
}
|
||||
NewFileTemplate struct {
|
||||
Ext string `json:"ext"`
|
||||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
)
|
||||
|
||||
type NewFileTemplate struct {
|
||||
Ext string `json:"ext"`
|
||||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
type (
|
||||
CustomPropsType string
|
||||
CustomProps struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type CustomPropsType `json:"type"`
|
||||
Max int `json:"max,omitempty"`
|
||||
Min int `json:"min,omitempty"`
|
||||
Default string `json:"default,omitempty"`
|
||||
Options []string `json:"options,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
CustomPropsTypeText = "text"
|
||||
CustomPropsTypeNumber = "number"
|
||||
CustomPropsTypeBoolean = "boolean"
|
||||
CustomPropsTypeSelect = "select"
|
||||
CustomPropsTypeMultiSelect = "multi_select"
|
||||
CustomPropsTypeLink = "link"
|
||||
CustomPropsTypeRating = "rating"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user