Skip to content

Commit

Permalink
feat: add image and photo metadata to search
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed May 16, 2024
1 parent 52e7ae9 commit a50e5a4
Show file tree
Hide file tree
Showing 11 changed files with 708 additions and 139 deletions.
429 changes: 344 additions & 85 deletions protogen/gen/ocis/messages/search/v0/search.pb.go

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions protogen/gen/ocis/messages/search/v0/search.pb.web.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 49 additions & 49 deletions protogen/gen/ocis/messages/settings/v0/settings.pb.go

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions protogen/gen/ocis/services/search/v0/search.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@
},
"remoteItemId": {
"$ref": "#/definitions/v0ResourceID"
},
"image": {
"$ref": "#/definitions/v0Image"
},
"photo": {
"$ref": "#/definitions/v0Photo"
}
}
},
Expand All @@ -296,6 +302,19 @@
}
}
},
"v0Image": {
"type": "object",
"properties": {
"width": {
"type": "integer",
"format": "int32"
},
"height": {
"type": "integer",
"format": "int32"
}
}
},
"v0IndexSpaceRequest": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -324,6 +343,45 @@
}
}
},
"v0Photo": {
"type": "object",
"properties": {
"cameraMake": {
"type": "string"
},
"cameraModel": {
"type": "string"
},
"exposureDenominator": {
"type": "number",
"format": "float"
},
"exposureNumerator": {
"type": "number",
"format": "float"
},
"fNumber": {
"type": "number",
"format": "float"
},
"focalLength": {
"type": "number",
"format": "float"
},
"iso": {
"type": "integer",
"format": "int32"
},
"orientation": {
"type": "integer",
"format": "int32"
},
"takenDateTime": {
"type": "string",
"format": "date-time"
}
}
},
"v0Reference": {
"type": "object",
"properties": {
Expand Down
27 changes: 23 additions & 4 deletions protogen/proto/ocis/messages/search/v0/search.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,27 @@ message Audio {
optional int32 year = 16;
}

message Image {
optional int32 width = 1;
optional int32 height = 2;
}

message GeoCoordinates {
optional double altitude = 1;
optional double latitude = 2;
optional double longitude = 3;
optional double altitude = 1;
optional double latitude = 2;
optional double longitude = 3;
}

message Photo {
optional string cameraMake = 1;
optional string cameraModel = 2;
optional float exposureDenominator = 3;
optional float exposureNumerator = 4;
optional float fNumber = 5;
optional float focalLength = 6;
optional int32 iso = 7;
optional int32 orientation = 8;
optional google.protobuf.Timestamp takenDateTime = 9;
}

message Entity {
Expand All @@ -48,7 +65,7 @@ message Entity {
string name = 3;
string etag = 4;
uint64 size = 5;
google.protobuf.Timestamp last_modified_time = 6;
google.protobuf.Timestamp last_modified_time = 6;
string mime_type = 7;
string permissions = 8;
uint64 type = 9;
Expand All @@ -60,6 +77,8 @@ message Entity {
Audio audio = 15;
GeoCoordinates location = 16;
ResourceID remote_item_id = 17;
Image image = 18;
Photo photo = 19;
}

message Match {
Expand Down
30 changes: 30 additions & 0 deletions services/graph/pkg/service/v0/driveitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ func cs3ResourceToDriveItem(logger *log.Logger, res *storageprovider.ResourceInf

if res.GetArbitraryMetadata() != nil {
driveItem.Audio = cs3ResourceToDriveItemAudioFacet(logger, res)
driveItem.Image = cs3ResourceToDriveItemImageFacet(logger, res)
driveItem.Location = cs3ResourceToDriveItemLocationFacet(logger, res)
driveItem.Photo = cs3ResourceToDriveItemPhotoFacet(logger, res)
}

return driveItem, nil
Expand All @@ -497,6 +499,20 @@ func cs3ResourceToDriveItemAudioFacet(logger *log.Logger, res *storageprovider.R
return nil
}

func cs3ResourceToDriveItemImageFacet(logger *log.Logger, res *storageprovider.ResourceInfo) *libregraph.Image {
k := res.GetArbitraryMetadata().GetMetadata()
if k == nil {
return nil
}

var image = &libregraph.Image{}
if ok := unmarshalStringMap(logger, image, k, "libre.graph.image."); ok {
return image
}

return nil
}

func cs3ResourceToDriveItemLocationFacet(logger *log.Logger, res *storageprovider.ResourceInfo) *libregraph.GeoCoordinates {
k := res.GetArbitraryMetadata().GetMetadata()
if k == nil {
Expand All @@ -511,6 +527,20 @@ func cs3ResourceToDriveItemLocationFacet(logger *log.Logger, res *storageprovide
return nil
}

func cs3ResourceToDriveItemPhotoFacet(logger *log.Logger, res *storageprovider.ResourceInfo) *libregraph.Photo {
k := res.GetArbitraryMetadata().GetMetadata()
if k == nil {
return nil
}

var photo = &libregraph.Photo{}
if ok := unmarshalStringMap(logger, photo, k, "libre.graph.photo."); ok {
return photo
}

return nil
}

func getFieldName(structField reflect.StructField) string {
tag := structField.Tag.Get("json")
if tag == "" {
Expand Down
2 changes: 1 addition & 1 deletion services/idp/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions services/search/pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type Document struct {
MimeType string
Tags []string
Audio *libregraph.Audio `json:"audio,omitempty"`
Image *libregraph.Image `json:"image,omitempty"`
Location *libregraph.GeoCoordinates `json:"location,omitempty"`
Photo *libregraph.Photo `json:"photo,omitempty"`
}

func CleanString(content, langCode string) string {
Expand Down
91 changes: 91 additions & 0 deletions services/search/pkg/content/tika.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -90,6 +91,8 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document,
}

doc.Location = t.getLocation(meta)
doc.Image = t.getImage(meta)
doc.Photo = t.getPhoto(meta)

if contentType, err := getFirstValue(meta, "Content-Type"); err == nil && strings.HasPrefix(contentType, "audio/") {
doc.Audio = t.getAudio(meta)
Expand All @@ -103,6 +106,31 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document,
return doc, nil
}

func (t Tika) getImage(meta map[string][]string) *libregraph.Image {
var image *libregraph.Image
initImage := func() {
if image == nil {
image = libregraph.NewImage()
}
}

if v, err := getFirstValue(meta, "tiff:ImageWidth"); err == nil {
if i, err := strconv.ParseInt(v, 0, 32); err == nil {
initImage()
image.SetWidth(int32(i))
}
}

if v, err := getFirstValue(meta, "tiff:ImageLength"); err == nil {
if i, err := strconv.ParseInt(v, 0, 32); err == nil {
initImage()
image.SetHeight(int32(i))
}
}

return image
}

func (t Tika) getLocation(meta map[string][]string) *libregraph.GeoCoordinates {
var location *libregraph.GeoCoordinates
initLocation := func() {
Expand Down Expand Up @@ -132,6 +160,69 @@ func (t Tika) getLocation(meta map[string][]string) *libregraph.GeoCoordinates {
return location
}

func (t Tika) getPhoto(meta map[string][]string) *libregraph.Photo {
var photo *libregraph.Photo
initPhoto := func() {
if photo == nil {
photo = libregraph.NewPhoto()
}
}

if v, err := getFirstValue(meta, "tiff:Make"); err == nil {
initPhoto()
photo.SetCameraMake(v)
}

if v, err := getFirstValue(meta, "tiff:Model"); err == nil {
initPhoto()
photo.SetCameraModel(v)
}

if v, err := getFirstValue(meta, "exif:FNumber"); err == nil {
if i, err := strconv.ParseFloat(v, 64); err == nil {
initPhoto()
photo.SetFNumber(i)
}
}

if v, err := getFirstValue(meta, "exif:FocalLength"); err == nil {
if i, err := strconv.ParseFloat(v, 64); err == nil {
initPhoto()
photo.SetFocalLength(i)
}
}

if v, err := getFirstValue(meta, "Base ISO"); err == nil {
if i, err := strconv.ParseInt(v, 0, 32); err == nil {
initPhoto()
photo.SetIso(int32(i))
}
}

if v, err := getFirstValue(meta, "tiff:Orientation"); err == nil {
if i, err := strconv.ParseInt(v, 0, 32); err == nil {
initPhoto()
photo.SetOrientation(int32(i))
}
}

if v, err := getFirstValue(meta, "exif:DateTimeOriginal"); err == nil {
layout := "2006-01-02T15:04:05"
if t, err := time.Parse(layout, v); err == nil {
initPhoto()
photo.SetTakenDateTime(t)
}
}

// TODO: no idea which keys to use for the next two values
// The denominator for the exposure time fraction from the camera. Read-only.
// ExposureDenominator *float64 `json:"exposureDenominator,omitempty"`
// The numerator for the exposure time fraction from the camera. Read-only.
// ExposureNumerator *float64 `json:"exposureNumerator,omitempty"`

return photo
}

func (t Tika) getAudio(meta map[string][]string) *libregraph.Audio {
var audio *libregraph.Audio
initAudio := func() {
Expand Down
Loading

0 comments on commit a50e5a4

Please sign in to comment.