mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 18:16:47 -05:00
feat(webdav): carry the facets in the search REPORT hits
The search service returns audio, location, image, photo, video, motion photo and live photo with every hit, the REPORT response only carried photo and location, as flat oc:photo-* props. All facets are now rendered in the xml shape PROPFIND uses, so a client reads both the same way. This replaces the flat props.
This commit is contained in:
1 parent
9afb99f54a
commit
927df2bdce
3 files changed
+58
-118
No files matched your search
@@ -46,6 +46,7 @@ require (
|
||||
github.com/gookit/config/v2 v2.2.9
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.31.0
|
||||
github.com/iancoleman/strcase v0.3.0
|
||||
github.com/invopop/validation v0.8.0
|
||||
github.com/jellydator/ttlcache/v2 v2.11.1
|
||||
github.com/jellydator/ttlcache/v3 v3.4.1
|
||||
@@ -246,7 +247,6 @@ require (
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/yamux v0.1.2 // indirect
|
||||
github.com/huandu/xstrings v1.5.0 // indirect
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
|
||||
@@ -16,8 +16,12 @@ import (
|
||||
|
||||
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/iancoleman/strcase"
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
"go-micro.dev/v4/metadata"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
revactx "github.com/opencloud-eu/reva/v3/pkg/ctx"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storagespace"
|
||||
@@ -263,8 +267,13 @@ func matchToPropResponse(ctx context.Context, davPrefix, publicURL string, match
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:favorite", "1"))
|
||||
}
|
||||
|
||||
propstatOK.Prop = appendPhotoProps(propstatOK.Prop, match.GetEntity().GetPhoto())
|
||||
propstatOK.Prop = appendLocationProps(propstatOK.Prop, match.GetEntity().GetLocation())
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "audio", match.Entity.Audio)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "location", match.Entity.Location)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "image", match.Entity.Image)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "photo", match.Entity.Photo)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "video", match.Entity.Video)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "motion-photo", match.Entity.MotionPhoto)
|
||||
propstatOK.Prop = appendFacet(propstatOK.Prop, "live-photo", match.Entity.LivePhoto)
|
||||
|
||||
if len(propstatOK.Prop) > 0 {
|
||||
response.Propstat = append(response.Propstat, propstatOK)
|
||||
@@ -273,69 +282,43 @@ func matchToPropResponse(ctx context.Context, davPrefix, publicURL string, match
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
// decimal places of the photo props; six for a coordinate resolve about 10 cm
|
||||
const (
|
||||
lensPrecision = 2
|
||||
exposurePrecision = 0
|
||||
coordinatePrecision = 6
|
||||
altitudePrecision = 1
|
||||
)
|
||||
|
||||
func appendPhotoProps(props []prop.PropertyXML, photo *searchmsg.Photo) []prop.PropertyXML {
|
||||
if photo == nil {
|
||||
// appendFacet renders a facet in the xml shape PROPFIND uses for it.
|
||||
func appendFacet(props []prop.PropertyXML, name string, facet proto.Message) []prop.PropertyXML {
|
||||
m := facet.ProtoReflect()
|
||||
if !m.IsValid() {
|
||||
return props
|
||||
}
|
||||
if photo.GetTakenDateTime() != nil {
|
||||
props = append(props, prop.Escaped("oc:photo-taken-date-time", photo.GetTakenDateTime().AsTime().Format(time.RFC3339)))
|
||||
|
||||
content := strings.Builder{}
|
||||
fields := m.Descriptor().Fields()
|
||||
for i := 0; i < fields.Len(); i++ {
|
||||
fd := fields.Get(i)
|
||||
if !m.Has(fd) {
|
||||
continue
|
||||
}
|
||||
key := "oc:" + strcase.ToKebab(string(fd.Name()))
|
||||
content.WriteString("<" + key + ">")
|
||||
content.WriteString(prop.Escape(facetValue(fd, m.Get(fd))))
|
||||
content.WriteString("</" + key + ">")
|
||||
}
|
||||
props = appendStringProp(props, "oc:photo-camera-make", photo.CameraMake)
|
||||
props = appendStringProp(props, "oc:photo-camera-model", photo.CameraModel)
|
||||
props = appendFloat32Prop(props, "oc:photo-fnumber", photo.FNumber, lensPrecision)
|
||||
props = appendFloat32Prop(props, "oc:photo-focal-length", photo.FocalLength, lensPrecision)
|
||||
props = appendInt32Prop(props, "oc:photo-iso", photo.Iso)
|
||||
props = appendInt32Prop(props, "oc:photo-orientation", photo.Orientation)
|
||||
props = appendFloat32Prop(props, "oc:photo-exposure-numerator", photo.ExposureNumerator, exposurePrecision)
|
||||
props = appendFloat32Prop(props, "oc:photo-exposure-denominator", photo.ExposureDenominator, exposurePrecision)
|
||||
return props
|
||||
if content.Len() == 0 {
|
||||
return props
|
||||
}
|
||||
return append(props, prop.Raw("oc:"+name, content.String()))
|
||||
}
|
||||
|
||||
func appendLocationProps(props []prop.PropertyXML, location *searchmsg.GeoCoordinates) []prop.PropertyXML {
|
||||
if location == nil {
|
||||
return props
|
||||
func facetValue(fd protoreflect.FieldDescriptor, v protoreflect.Value) string {
|
||||
switch fd.Kind() {
|
||||
case protoreflect.FloatKind:
|
||||
return strconv.FormatFloat(v.Float(), 'f', -1, 32)
|
||||
case protoreflect.DoubleKind:
|
||||
return strconv.FormatFloat(v.Float(), 'f', -1, 64)
|
||||
case protoreflect.MessageKind:
|
||||
if ts, ok := v.Message().Interface().(*timestamppb.Timestamp); ok {
|
||||
return ts.AsTime().Format(time.RFC3339)
|
||||
}
|
||||
}
|
||||
// no zero check here: 0 is a valid coordinate (equator, prime meridian, sea level)
|
||||
props = appendFloat64Prop(props, "oc:photo-location-latitude", location.Latitude, coordinatePrecision)
|
||||
props = appendFloat64Prop(props, "oc:photo-location-longitude", location.Longitude, coordinatePrecision)
|
||||
props = appendFloat64Prop(props, "oc:photo-location-altitude", location.Altitude, altitudePrecision)
|
||||
return props
|
||||
}
|
||||
|
||||
func appendStringProp(props []prop.PropertyXML, name string, value *string) []prop.PropertyXML {
|
||||
if value == nil || *value == "" {
|
||||
return props
|
||||
}
|
||||
return append(props, prop.Escaped(name, *value))
|
||||
}
|
||||
|
||||
func appendFloat32Prop(props []prop.PropertyXML, name string, value *float32, precision int) []prop.PropertyXML {
|
||||
if value == nil || *value == 0 {
|
||||
return props
|
||||
}
|
||||
return append(props, prop.Escaped(name, strconv.FormatFloat(float64(*value), 'f', precision, 32)))
|
||||
}
|
||||
|
||||
func appendInt32Prop(props []prop.PropertyXML, name string, value *int32) []prop.PropertyXML {
|
||||
if value == nil || *value == 0 {
|
||||
return props
|
||||
}
|
||||
return append(props, prop.Escaped(name, strconv.FormatInt(int64(*value), 10)))
|
||||
}
|
||||
|
||||
func appendFloat64Prop(props []prop.PropertyXML, name string, value *float64, precision int) []prop.PropertyXML {
|
||||
if value == nil {
|
||||
return props
|
||||
}
|
||||
return append(props, prop.Escaped(name, strconv.FormatFloat(*value, 'f', precision, 64)))
|
||||
return v.String()
|
||||
}
|
||||
|
||||
type report struct {
|
||||
|
||||
@@ -42,65 +42,22 @@ var _ = Describe("SpacesSearchRegex", func() {
|
||||
)
|
||||
})
|
||||
|
||||
var _ = Describe("matchToPropResponse", func() {
|
||||
propsOf := func(entity *searchmsg.Entity) map[string]string {
|
||||
entity.Ref = &searchmsg.Reference{ResourceId: &searchmsg.ResourceID{StorageId: "storage", SpaceId: "space"}, Path: "./photo.jpg"}
|
||||
entity.Id = &searchmsg.ResourceID{StorageId: "storage", SpaceId: "space", OpaqueId: "photo"}
|
||||
entity.LastModifiedTime = timestamppb.Now()
|
||||
res, err := matchToPropResponse(context.Background(), "", "https://cloud.example.com", &searchmsg.Match{Entity: entity}, &userv1beta1.User{Id: &userv1beta1.UserId{OpaqueId: "alice"}}, thumbnail.SourceTypes{})
|
||||
var _ = Describe("multistatusResponse", func() {
|
||||
It("carries the facets of a hit in the PROPFIND shape", func() {
|
||||
id := &searchmsg.ResourceID{StorageId: "storage", SpaceId: "space", OpaqueId: "file"}
|
||||
res, err := multistatusResponse(context.Background(), "", "", []*searchmsg.Match{{Entity: &searchmsg.Entity{
|
||||
Ref: &searchmsg.Reference{ResourceId: id},
|
||||
Id: id,
|
||||
Audio: &searchmsg.Audio{},
|
||||
Photo: &searchmsg.Photo{FNumber: proto.Float32(1.8), TakenDateTime: timestamppb.New(time.Date(2018, 1, 1, 12, 34, 56, 0, time.UTC))},
|
||||
Location: &searchmsg.GeoCoordinates{Latitude: proto.Float64(0), Longitude: proto.Float64(11.576124)},
|
||||
LivePhoto: &searchmsg.LivePhoto{ContentId: proto.String("a&b"), StillImageTimeUs: proto.Int64(1233333)},
|
||||
}}}, &userv1beta1.User{Id: &userv1beta1.UserId{}}, thumbnail.NewSourceTypes(nil))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res.Propstat).To(HaveLen(1))
|
||||
props := map[string]string{}
|
||||
for _, p := range res.Propstat[0].Prop {
|
||||
props[p.XMLName.Local] = string(p.InnerXML)
|
||||
}
|
||||
return props
|
||||
}
|
||||
|
||||
It("returns the photo and location metadata", func() {
|
||||
props := propsOf(&searchmsg.Entity{
|
||||
Photo: &searchmsg.Photo{
|
||||
TakenDateTime: timestamppb.New(time.Date(2024, 5, 1, 12, 30, 0, 0, time.UTC)),
|
||||
CameraMake: proto.String("Acme"),
|
||||
CameraModel: proto.String("X100"),
|
||||
FNumber: proto.Float32(1.8),
|
||||
FocalLength: proto.Float32(26),
|
||||
Iso: proto.Int32(400),
|
||||
Orientation: proto.Int32(6),
|
||||
ExposureNumerator: proto.Float32(1),
|
||||
ExposureDenominator: proto.Float32(250),
|
||||
},
|
||||
Location: &searchmsg.GeoCoordinates{Latitude: proto.Float64(48.137154), Longitude: proto.Float64(11.576124), Altitude: proto.Float64(519.5)},
|
||||
})
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-taken-date-time", "2024-05-01T12:30:00Z"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-camera-make", "Acme"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-camera-model", "X100"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-fnumber", "1.80"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-focal-length", "26.00"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-iso", "400"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-orientation", "6"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-exposure-numerator", "1"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-exposure-denominator", "250"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-location-latitude", "48.137154"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-location-longitude", "11.576124"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-location-altitude", "519.5"))
|
||||
})
|
||||
|
||||
It("keeps a zero coordinate but skips empty photo values", func() {
|
||||
props := propsOf(&searchmsg.Entity{
|
||||
Photo: &searchmsg.Photo{CameraMake: proto.String(""), Iso: proto.Int32(0)},
|
||||
Location: &searchmsg.GeoCoordinates{Latitude: proto.Float64(0), Longitude: proto.Float64(0)},
|
||||
})
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-location-latitude", "0.000000"))
|
||||
Expect(props).To(HaveKeyWithValue("oc:photo-location-longitude", "0.000000"))
|
||||
Expect(props).ToNot(HaveKey("oc:photo-location-altitude"))
|
||||
Expect(props).ToNot(HaveKey("oc:photo-camera-make"))
|
||||
Expect(props).ToNot(HaveKey("oc:photo-iso"))
|
||||
})
|
||||
|
||||
It("adds no photo props to a match without them", func() {
|
||||
for name := range propsOf(&searchmsg.Entity{}) {
|
||||
Expect(name).ToNot(HavePrefix("oc:photo-"))
|
||||
}
|
||||
Expect(string(res)).To(ContainSubstring("<oc:photo><oc:f-number>1.8</oc:f-number><oc:taken-date-time>2018-01-01T12:34:56Z</oc:taken-date-time></oc:photo>"))
|
||||
Expect(string(res)).To(ContainSubstring("<oc:location><oc:latitude>0</oc:latitude><oc:longitude>11.576124</oc:longitude></oc:location>"))
|
||||
Expect(string(res)).To(ContainSubstring("<oc:live-photo><oc:content-id>a&b</oc:content-id><oc:still-image-time-us>1233333</oc:still-image-time-us></oc:live-photo>"))
|
||||
Expect(string(res)).ToNot(ContainSubstring("oc:audio"))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user