From da81b6b48f8e6cdd35d0a38745914da0ce9b3e53 Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 11 Aug 2026 23:47:21 +0800 Subject: [PATCH] feat: persist and display client media metadata (#6180) --- internal/testutil/image.go | 24 + proto/api/v1/attachment_service.proto | 58 ++ proto/api/v1/user_service.proto | 2 + proto/gen/api/v1/attachment_service.pb.go | 584 ++++++++++++++++-- proto/gen/api/v1/user_service.pb.go | 22 +- proto/gen/openapi.yaml | 73 +++ proto/gen/store/attachment.pb.go | 490 ++++++++++++++- proto/gen/store/user_setting.pb.go | 20 +- proto/store/attachment.proto | 39 ++ proto/store/user_setting.proto | 2 + .../api/v1/attachment_media_metadata.go | 204 ++++++ .../api/v1/attachment_media_metadata_test.go | 123 ++++ server/router/api/v1/attachment_service.go | 8 + .../api/v1/attachment_service_storage.go | 13 +- .../router/api/v1/gateway_marshaler_test.go | 48 ++ .../api/v1/test/attachment_service_test.go | 107 ++++ .../router/api/v1/test/user_setting_test.go | 54 ++ .../router/api/v1/user_service_converters.go | 14 +- server/router/api/v1/user_service_settings.go | 19 +- store/test/attachment_test.go | 24 + web/package.json | 1 + web/pnpm-lock.yaml | 8 + web/src/components/AttachmentIcon.tsx | 16 +- .../AttachmentLibrary/AttachmentMediaGrid.tsx | 12 +- web/src/components/MediaMetadataDetails.tsx | 246 ++++++++ web/src/components/MemoEditor/hooks/index.ts | 2 +- .../MemoEditor/hooks/useFileUpload.ts | 27 +- web/src/components/MemoEditor/index.tsx | 19 +- .../MemoEditor/services/cacheService.ts | 2 +- .../services/mediaMetadataService.ts | 352 +++++++++++ .../MemoEditor/services/uploadService.ts | 4 +- .../components/MemoEditor/types/attachment.ts | 8 +- .../Attachment/AttachmentListEditor.tsx | 30 +- web/src/components/PreviewImageDialog.tsx | 101 ++- .../Settings/PreferencesSection.tsx | 35 +- web/src/locales/en.json | 39 +- web/src/locales/zh-Hans.json | 39 +- web/src/locales/zh-Hant.json | 39 +- .../proto/api/v1/attachment_service_pb.ts | 217 ++++++- web/src/types/proto/api/v1/user_service_pb.ts | 9 +- web/src/utils/media-item.ts | 4 + web/src/utils/media-metadata.ts | 130 ++++ .../attachment-library-source-link.test.tsx | 54 +- web/tests/insert-menu.test.tsx | 1 + web/tests/media-item-preview-metadata.test.ts | 19 + web/tests/media-metadata-display.test.ts | 35 ++ web/tests/media-metadata-exif-fixture.test.ts | 141 +++++ web/tests/media-metadata-service.test.ts | 162 +++++ web/tests/preferences-media-metadata.test.tsx | 55 ++ web/tests/preview-image-dialog.test.tsx | 139 +++++ web/tests/upload-media-metadata.test.ts | 95 +++ web/tests/use-inline-image-upload.test.tsx | 13 + 52 files changed, 3782 insertions(+), 200 deletions(-) create mode 100644 internal/testutil/image.go create mode 100644 server/router/api/v1/attachment_media_metadata.go create mode 100644 server/router/api/v1/attachment_media_metadata_test.go create mode 100644 web/src/components/MediaMetadataDetails.tsx create mode 100644 web/src/components/MemoEditor/services/mediaMetadataService.ts create mode 100644 web/src/utils/media-metadata.ts create mode 100644 web/tests/media-item-preview-metadata.test.ts create mode 100644 web/tests/media-metadata-display.test.ts create mode 100644 web/tests/media-metadata-exif-fixture.test.ts create mode 100644 web/tests/media-metadata-service.test.ts create mode 100644 web/tests/preferences-media-metadata.test.tsx create mode 100644 web/tests/upload-media-metadata.test.ts diff --git a/internal/testutil/image.go b/internal/testutil/image.go new file mode 100644 index 00000000..320e1fa0 --- /dev/null +++ b/internal/testutil/image.go @@ -0,0 +1,24 @@ +package testutil + +import ( + "bytes" + "image" + "image/color" + "image/jpeg" +) + +// BuildJPEG returns a solid-color width×height JPEG blob for tests. +func BuildJPEG(width, height int) []byte { + img := image.NewRGBA(image.Rect(0, 0, width, height)) + for y := range height { + for x := range width { + img.Set(x, y, color.RGBA{R: 80, G: 120, B: 160, A: 255}) + } + } + var buffer bytes.Buffer + if err := jpeg.Encode(&buffer, img, &jpeg.Options{Quality: 90}); err != nil { + // Encoding an in-memory RGBA image cannot fail with valid dimensions. + panic(err) + } + return buffer.Bytes() +} diff --git a/proto/api/v1/attachment_service.proto b/proto/api/v1/attachment_service.proto index 6a806bb7..a214ba22 100644 --- a/proto/api/v1/attachment_service.proto +++ b/proto/api/v1/attachment_service.proto @@ -73,6 +73,58 @@ message MotionMedia { bool has_embedded_video = 5; } +// MediaMetadata contains normalized metadata explicitly supplied by a client. +// The server validates and stores this data but does not extract it from the media file. +message MediaMetadata { + // Optional. Display-oriented width in pixels. + optional int32 width = 1; + // Optional. Display-oriented height in pixels. + optional int32 height = 2; + + oneof details { + PhotoMetadata photo = 3; + VideoMetadata video = 4; + } +} + +message PhotoMetadata { + // Optional. Capture time as recorded by the source media. + MediaCaptureTime capture_time = 1; + // Optional. Geographic location recorded by the source media. + MediaLocation location = 2; + // Optional. EXIF orientation value from 1 through 8 as recorded by the source file. + // This value is informational and must not be reapplied to the stored attachment; + // width and height already describe its display-oriented dimensions. + optional int32 source_exif_orientation = 3; + string camera_make = 4; + string camera_model = 5; + string lens_model = 6; + optional double f_number = 7; + optional double exposure_time_seconds = 8; + optional int32 iso = 9; + optional double focal_length_mm = 10; +} + +message MediaCaptureTime { + // Local date and time without a time zone, formatted as YYYY-MM-DDTHH:mm:ss[.fraction]. + string local_date_time = 1; + // Optional. UTC offset formatted as Z or +/-HH:MM. + optional string utc_offset = 2; +} + +message MediaLocation { + // Optional. WGS84 latitude in decimal degrees. Must be provided with longitude. + optional double latitude = 1; + // Optional. WGS84 longitude in decimal degrees. Must be provided with latitude. + optional double longitude = 2; + // Optional. Signed altitude in meters relative to sea level. + optional double altitude_meters = 3; +} + +message VideoMetadata { + optional double duration_seconds = 1; +} + message Attachment { option (google.api.resource) = { type: "memos.api.v1/Attachment" @@ -109,6 +161,12 @@ message Attachment { // Optional. Motion media metadata. MotionMedia motion_media = 9 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Immutable normalized media metadata explicitly supplied by the client at creation time. + MediaMetadata media_metadata = 10 [ + (google.api.field_behavior) = OPTIONAL, + (google.api.field_behavior) = IMMUTABLE + ]; } message CreateAttachmentRequest { diff --git a/proto/api/v1/user_service.proto b/proto/api/v1/user_service.proto index 27f880fc..304921f1 100644 --- a/proto/api/v1/user_service.proto +++ b/proto/api/v1/user_service.proto @@ -456,6 +456,8 @@ message UserSetting { // This references a CSS file in the web/public/themes/ directory. // If not set, the default theme will be used. string theme = 4 [(google.api.field_behavior) = OPTIONAL]; + // Whether the official client should save metadata from future media uploads. + bool save_media_metadata = 5 [(google.api.field_behavior) = OPTIONAL]; } // Tag metadata for user-specific display rules. diff --git a/proto/gen/api/v1/attachment_service.pb.go b/proto/gen/api/v1/attachment_service.pb.go index 463a7df5..10d56028 100644 --- a/proto/gen/api/v1/attachment_service.pb.go +++ b/proto/gen/api/v1/attachment_service.pb.go @@ -202,6 +202,390 @@ func (x *MotionMedia) GetHasEmbeddedVideo() bool { return false } +// MediaMetadata contains normalized metadata explicitly supplied by a client. +// The server validates and stores this data but does not extract it from the media file. +type MediaMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Optional. Display-oriented width in pixels. + Width *int32 `protobuf:"varint,1,opt,name=width,proto3,oneof" json:"width,omitempty"` + // Optional. Display-oriented height in pixels. + Height *int32 `protobuf:"varint,2,opt,name=height,proto3,oneof" json:"height,omitempty"` + // Types that are valid to be assigned to Details: + // + // *MediaMetadata_Photo + // *MediaMetadata_Video + Details isMediaMetadata_Details `protobuf_oneof:"details"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaMetadata) Reset() { + *x = MediaMetadata{} + mi := &file_api_v1_attachment_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaMetadata) ProtoMessage() {} + +func (x *MediaMetadata) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaMetadata.ProtoReflect.Descriptor instead. +func (*MediaMetadata) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{1} +} + +func (x *MediaMetadata) GetWidth() int32 { + if x != nil && x.Width != nil { + return *x.Width + } + return 0 +} + +func (x *MediaMetadata) GetHeight() int32 { + if x != nil && x.Height != nil { + return *x.Height + } + return 0 +} + +func (x *MediaMetadata) GetDetails() isMediaMetadata_Details { + if x != nil { + return x.Details + } + return nil +} + +func (x *MediaMetadata) GetPhoto() *PhotoMetadata { + if x != nil { + if x, ok := x.Details.(*MediaMetadata_Photo); ok { + return x.Photo + } + } + return nil +} + +func (x *MediaMetadata) GetVideo() *VideoMetadata { + if x != nil { + if x, ok := x.Details.(*MediaMetadata_Video); ok { + return x.Video + } + } + return nil +} + +type isMediaMetadata_Details interface { + isMediaMetadata_Details() +} + +type MediaMetadata_Photo struct { + Photo *PhotoMetadata `protobuf:"bytes,3,opt,name=photo,proto3,oneof"` +} + +type MediaMetadata_Video struct { + Video *VideoMetadata `protobuf:"bytes,4,opt,name=video,proto3,oneof"` +} + +func (*MediaMetadata_Photo) isMediaMetadata_Details() {} + +func (*MediaMetadata_Video) isMediaMetadata_Details() {} + +type PhotoMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Optional. Capture time as recorded by the source media. + CaptureTime *MediaCaptureTime `protobuf:"bytes,1,opt,name=capture_time,json=captureTime,proto3" json:"capture_time,omitempty"` + // Optional. Geographic location recorded by the source media. + Location *MediaLocation `protobuf:"bytes,2,opt,name=location,proto3" json:"location,omitempty"` + // Optional. EXIF orientation value from 1 through 8 as recorded by the source file. + // This value is informational and must not be reapplied to the stored attachment; + // width and height already describe its display-oriented dimensions. + SourceExifOrientation *int32 `protobuf:"varint,3,opt,name=source_exif_orientation,json=sourceExifOrientation,proto3,oneof" json:"source_exif_orientation,omitempty"` + CameraMake string `protobuf:"bytes,4,opt,name=camera_make,json=cameraMake,proto3" json:"camera_make,omitempty"` + CameraModel string `protobuf:"bytes,5,opt,name=camera_model,json=cameraModel,proto3" json:"camera_model,omitempty"` + LensModel string `protobuf:"bytes,6,opt,name=lens_model,json=lensModel,proto3" json:"lens_model,omitempty"` + FNumber *float64 `protobuf:"fixed64,7,opt,name=f_number,json=fNumber,proto3,oneof" json:"f_number,omitempty"` + ExposureTimeSeconds *float64 `protobuf:"fixed64,8,opt,name=exposure_time_seconds,json=exposureTimeSeconds,proto3,oneof" json:"exposure_time_seconds,omitempty"` + Iso *int32 `protobuf:"varint,9,opt,name=iso,proto3,oneof" json:"iso,omitempty"` + FocalLengthMm *float64 `protobuf:"fixed64,10,opt,name=focal_length_mm,json=focalLengthMm,proto3,oneof" json:"focal_length_mm,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PhotoMetadata) Reset() { + *x = PhotoMetadata{} + mi := &file_api_v1_attachment_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PhotoMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PhotoMetadata) ProtoMessage() {} + +func (x *PhotoMetadata) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PhotoMetadata.ProtoReflect.Descriptor instead. +func (*PhotoMetadata) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{2} +} + +func (x *PhotoMetadata) GetCaptureTime() *MediaCaptureTime { + if x != nil { + return x.CaptureTime + } + return nil +} + +func (x *PhotoMetadata) GetLocation() *MediaLocation { + if x != nil { + return x.Location + } + return nil +} + +func (x *PhotoMetadata) GetSourceExifOrientation() int32 { + if x != nil && x.SourceExifOrientation != nil { + return *x.SourceExifOrientation + } + return 0 +} + +func (x *PhotoMetadata) GetCameraMake() string { + if x != nil { + return x.CameraMake + } + return "" +} + +func (x *PhotoMetadata) GetCameraModel() string { + if x != nil { + return x.CameraModel + } + return "" +} + +func (x *PhotoMetadata) GetLensModel() string { + if x != nil { + return x.LensModel + } + return "" +} + +func (x *PhotoMetadata) GetFNumber() float64 { + if x != nil && x.FNumber != nil { + return *x.FNumber + } + return 0 +} + +func (x *PhotoMetadata) GetExposureTimeSeconds() float64 { + if x != nil && x.ExposureTimeSeconds != nil { + return *x.ExposureTimeSeconds + } + return 0 +} + +func (x *PhotoMetadata) GetIso() int32 { + if x != nil && x.Iso != nil { + return *x.Iso + } + return 0 +} + +func (x *PhotoMetadata) GetFocalLengthMm() float64 { + if x != nil && x.FocalLengthMm != nil { + return *x.FocalLengthMm + } + return 0 +} + +type MediaCaptureTime struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Local date and time without a time zone, formatted as YYYY-MM-DDTHH:mm:ss[.fraction]. + LocalDateTime string `protobuf:"bytes,1,opt,name=local_date_time,json=localDateTime,proto3" json:"local_date_time,omitempty"` + // Optional. UTC offset formatted as Z or +/-HH:MM. + UtcOffset *string `protobuf:"bytes,2,opt,name=utc_offset,json=utcOffset,proto3,oneof" json:"utc_offset,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaCaptureTime) Reset() { + *x = MediaCaptureTime{} + mi := &file_api_v1_attachment_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaCaptureTime) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaCaptureTime) ProtoMessage() {} + +func (x *MediaCaptureTime) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaCaptureTime.ProtoReflect.Descriptor instead. +func (*MediaCaptureTime) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{3} +} + +func (x *MediaCaptureTime) GetLocalDateTime() string { + if x != nil { + return x.LocalDateTime + } + return "" +} + +func (x *MediaCaptureTime) GetUtcOffset() string { + if x != nil && x.UtcOffset != nil { + return *x.UtcOffset + } + return "" +} + +type MediaLocation struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Optional. WGS84 latitude in decimal degrees. Must be provided with longitude. + Latitude *float64 `protobuf:"fixed64,1,opt,name=latitude,proto3,oneof" json:"latitude,omitempty"` + // Optional. WGS84 longitude in decimal degrees. Must be provided with latitude. + Longitude *float64 `protobuf:"fixed64,2,opt,name=longitude,proto3,oneof" json:"longitude,omitempty"` + // Optional. Signed altitude in meters relative to sea level. + AltitudeMeters *float64 `protobuf:"fixed64,3,opt,name=altitude_meters,json=altitudeMeters,proto3,oneof" json:"altitude_meters,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaLocation) Reset() { + *x = MediaLocation{} + mi := &file_api_v1_attachment_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaLocation) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaLocation) ProtoMessage() {} + +func (x *MediaLocation) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaLocation.ProtoReflect.Descriptor instead. +func (*MediaLocation) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{4} +} + +func (x *MediaLocation) GetLatitude() float64 { + if x != nil && x.Latitude != nil { + return *x.Latitude + } + return 0 +} + +func (x *MediaLocation) GetLongitude() float64 { + if x != nil && x.Longitude != nil { + return *x.Longitude + } + return 0 +} + +func (x *MediaLocation) GetAltitudeMeters() float64 { + if x != nil && x.AltitudeMeters != nil { + return *x.AltitudeMeters + } + return 0 +} + +type VideoMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + DurationSeconds *float64 `protobuf:"fixed64,1,opt,name=duration_seconds,json=durationSeconds,proto3,oneof" json:"duration_seconds,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *VideoMetadata) Reset() { + *x = VideoMetadata{} + mi := &file_api_v1_attachment_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *VideoMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*VideoMetadata) ProtoMessage() {} + +func (x *VideoMetadata) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use VideoMetadata.ProtoReflect.Descriptor instead. +func (*VideoMetadata) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{5} +} + +func (x *VideoMetadata) GetDurationSeconds() float64 { + if x != nil && x.DurationSeconds != nil { + return *x.DurationSeconds + } + return 0 +} + type Attachment struct { state protoimpl.MessageState `protogen:"open.v1"` // The name of the attachment. @@ -223,14 +607,16 @@ type Attachment struct { // Format: memos/{memo} Memo *string `protobuf:"bytes,8,opt,name=memo,proto3,oneof" json:"memo,omitempty"` // Optional. Motion media metadata. - MotionMedia *MotionMedia `protobuf:"bytes,9,opt,name=motion_media,json=motionMedia,proto3" json:"motion_media,omitempty"` + MotionMedia *MotionMedia `protobuf:"bytes,9,opt,name=motion_media,json=motionMedia,proto3" json:"motion_media,omitempty"` + // Optional. Immutable normalized media metadata explicitly supplied by the client at creation time. + MediaMetadata *MediaMetadata `protobuf:"bytes,10,opt,name=media_metadata,json=mediaMetadata,proto3" json:"media_metadata,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *Attachment) Reset() { *x = Attachment{} - mi := &file_api_v1_attachment_service_proto_msgTypes[1] + mi := &file_api_v1_attachment_service_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -242,7 +628,7 @@ func (x *Attachment) String() string { func (*Attachment) ProtoMessage() {} func (x *Attachment) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[1] + mi := &file_api_v1_attachment_service_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -255,7 +641,7 @@ func (x *Attachment) ProtoReflect() protoreflect.Message { // Deprecated: Use Attachment.ProtoReflect.Descriptor instead. func (*Attachment) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{1} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{6} } func (x *Attachment) GetName() string { @@ -321,6 +707,13 @@ func (x *Attachment) GetMotionMedia() *MotionMedia { return nil } +func (x *Attachment) GetMediaMetadata() *MediaMetadata { + if x != nil { + return x.MediaMetadata + } + return nil +} + type CreateAttachmentRequest struct { state protoimpl.MessageState `protogen:"open.v1"` // Required. The attachment to create. @@ -335,7 +728,7 @@ type CreateAttachmentRequest struct { func (x *CreateAttachmentRequest) Reset() { *x = CreateAttachmentRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[2] + mi := &file_api_v1_attachment_service_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -347,7 +740,7 @@ func (x *CreateAttachmentRequest) String() string { func (*CreateAttachmentRequest) ProtoMessage() {} func (x *CreateAttachmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[2] + mi := &file_api_v1_attachment_service_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -360,7 +753,7 @@ func (x *CreateAttachmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateAttachmentRequest.ProtoReflect.Descriptor instead. func (*CreateAttachmentRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{2} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{7} } func (x *CreateAttachmentRequest) GetAttachment() *Attachment { @@ -401,7 +794,7 @@ type ListAttachmentsRequest struct { func (x *ListAttachmentsRequest) Reset() { *x = ListAttachmentsRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[3] + mi := &file_api_v1_attachment_service_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -413,7 +806,7 @@ func (x *ListAttachmentsRequest) String() string { func (*ListAttachmentsRequest) ProtoMessage() {} func (x *ListAttachmentsRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[3] + mi := &file_api_v1_attachment_service_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -426,7 +819,7 @@ func (x *ListAttachmentsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListAttachmentsRequest.ProtoReflect.Descriptor instead. func (*ListAttachmentsRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{3} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{8} } func (x *ListAttachmentsRequest) GetPageSize() int32 { @@ -470,7 +863,7 @@ type ListAttachmentsResponse struct { func (x *ListAttachmentsResponse) Reset() { *x = ListAttachmentsResponse{} - mi := &file_api_v1_attachment_service_proto_msgTypes[4] + mi := &file_api_v1_attachment_service_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -482,7 +875,7 @@ func (x *ListAttachmentsResponse) String() string { func (*ListAttachmentsResponse) ProtoMessage() {} func (x *ListAttachmentsResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[4] + mi := &file_api_v1_attachment_service_proto_msgTypes[9] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -495,7 +888,7 @@ func (x *ListAttachmentsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListAttachmentsResponse.ProtoReflect.Descriptor instead. func (*ListAttachmentsResponse) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{4} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{9} } func (x *ListAttachmentsResponse) GetAttachments() []*Attachment { @@ -523,7 +916,7 @@ type GetAttachmentRequest struct { func (x *GetAttachmentRequest) Reset() { *x = GetAttachmentRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[5] + mi := &file_api_v1_attachment_service_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -535,7 +928,7 @@ func (x *GetAttachmentRequest) String() string { func (*GetAttachmentRequest) ProtoMessage() {} func (x *GetAttachmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[5] + mi := &file_api_v1_attachment_service_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -548,7 +941,7 @@ func (x *GetAttachmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetAttachmentRequest.ProtoReflect.Descriptor instead. func (*GetAttachmentRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{5} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{10} } func (x *GetAttachmentRequest) GetName() string { @@ -570,7 +963,7 @@ type UpdateAttachmentRequest struct { func (x *UpdateAttachmentRequest) Reset() { *x = UpdateAttachmentRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[6] + mi := &file_api_v1_attachment_service_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -582,7 +975,7 @@ func (x *UpdateAttachmentRequest) String() string { func (*UpdateAttachmentRequest) ProtoMessage() {} func (x *UpdateAttachmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[6] + mi := &file_api_v1_attachment_service_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -595,7 +988,7 @@ func (x *UpdateAttachmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateAttachmentRequest.ProtoReflect.Descriptor instead. func (*UpdateAttachmentRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{6} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{11} } func (x *UpdateAttachmentRequest) GetAttachment() *Attachment { @@ -623,7 +1016,7 @@ type DeleteAttachmentRequest struct { func (x *DeleteAttachmentRequest) Reset() { *x = DeleteAttachmentRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[7] + mi := &file_api_v1_attachment_service_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -635,7 +1028,7 @@ func (x *DeleteAttachmentRequest) String() string { func (*DeleteAttachmentRequest) ProtoMessage() {} func (x *DeleteAttachmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[7] + mi := &file_api_v1_attachment_service_proto_msgTypes[12] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -648,7 +1041,7 @@ func (x *DeleteAttachmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteAttachmentRequest.ProtoReflect.Descriptor instead. func (*DeleteAttachmentRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{7} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{12} } func (x *DeleteAttachmentRequest) GetName() string { @@ -667,7 +1060,7 @@ type BatchDeleteAttachmentsRequest struct { func (x *BatchDeleteAttachmentsRequest) Reset() { *x = BatchDeleteAttachmentsRequest{} - mi := &file_api_v1_attachment_service_proto_msgTypes[8] + mi := &file_api_v1_attachment_service_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -679,7 +1072,7 @@ func (x *BatchDeleteAttachmentsRequest) String() string { func (*BatchDeleteAttachmentsRequest) ProtoMessage() {} func (x *BatchDeleteAttachmentsRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_attachment_service_proto_msgTypes[8] + mi := &file_api_v1_attachment_service_proto_msgTypes[13] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -692,7 +1085,7 @@ func (x *BatchDeleteAttachmentsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BatchDeleteAttachmentsRequest.ProtoReflect.Descriptor instead. func (*BatchDeleteAttachmentsRequest) Descriptor() ([]byte, []int) { - return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{8} + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{13} } func (x *BatchDeleteAttachmentsRequest) GetNames() []string { @@ -712,7 +1105,50 @@ const file_api_v1_attachment_service_proto_rawDesc = "" + "\x04role\x18\x02 \x01(\x0e2\x1d.memos.api.v1.MotionMediaRoleR\x04role\x12\x19\n" + "\bgroup_id\x18\x03 \x01(\tR\agroupId\x12:\n" + "\x19presentation_timestamp_us\x18\x04 \x01(\x03R\x17presentationTimestampUs\x12,\n" + - "\x12has_embedded_video\x18\x05 \x01(\bR\x10hasEmbeddedVideo\"\xbe\x03\n" + + "\x12has_embedded_video\x18\x05 \x01(\bR\x10hasEmbeddedVideo\"\xd1\x01\n" + + "\rMediaMetadata\x12\x19\n" + + "\x05width\x18\x01 \x01(\x05H\x01R\x05width\x88\x01\x01\x12\x1b\n" + + "\x06height\x18\x02 \x01(\x05H\x02R\x06height\x88\x01\x01\x123\n" + + "\x05photo\x18\x03 \x01(\v2\x1b.memos.api.v1.PhotoMetadataH\x00R\x05photo\x123\n" + + "\x05video\x18\x04 \x01(\v2\x1b.memos.api.v1.VideoMetadataH\x00R\x05videoB\t\n" + + "\adetailsB\b\n" + + "\x06_widthB\t\n" + + "\a_height\"\xa7\x04\n" + + "\rPhotoMetadata\x12A\n" + + "\fcapture_time\x18\x01 \x01(\v2\x1e.memos.api.v1.MediaCaptureTimeR\vcaptureTime\x127\n" + + "\blocation\x18\x02 \x01(\v2\x1b.memos.api.v1.MediaLocationR\blocation\x12;\n" + + "\x17source_exif_orientation\x18\x03 \x01(\x05H\x00R\x15sourceExifOrientation\x88\x01\x01\x12\x1f\n" + + "\vcamera_make\x18\x04 \x01(\tR\n" + + "cameraMake\x12!\n" + + "\fcamera_model\x18\x05 \x01(\tR\vcameraModel\x12\x1d\n" + + "\n" + + "lens_model\x18\x06 \x01(\tR\tlensModel\x12\x1e\n" + + "\bf_number\x18\a \x01(\x01H\x01R\afNumber\x88\x01\x01\x127\n" + + "\x15exposure_time_seconds\x18\b \x01(\x01H\x02R\x13exposureTimeSeconds\x88\x01\x01\x12\x15\n" + + "\x03iso\x18\t \x01(\x05H\x03R\x03iso\x88\x01\x01\x12+\n" + + "\x0ffocal_length_mm\x18\n" + + " \x01(\x01H\x04R\rfocalLengthMm\x88\x01\x01B\x1a\n" + + "\x18_source_exif_orientationB\v\n" + + "\t_f_numberB\x18\n" + + "\x16_exposure_time_secondsB\x06\n" + + "\x04_isoB\x12\n" + + "\x10_focal_length_mm\"m\n" + + "\x10MediaCaptureTime\x12&\n" + + "\x0flocal_date_time\x18\x01 \x01(\tR\rlocalDateTime\x12\"\n" + + "\n" + + "utc_offset\x18\x02 \x01(\tH\x00R\tutcOffset\x88\x01\x01B\r\n" + + "\v_utc_offset\"\xb0\x01\n" + + "\rMediaLocation\x12\x1f\n" + + "\blatitude\x18\x01 \x01(\x01H\x00R\blatitude\x88\x01\x01\x12!\n" + + "\tlongitude\x18\x02 \x01(\x01H\x01R\tlongitude\x88\x01\x01\x12,\n" + + "\x0faltitude_meters\x18\x03 \x01(\x01H\x02R\x0ealtitudeMeters\x88\x01\x01B\v\n" + + "\t_latitudeB\f\n" + + "\n" + + "_longitudeB\x12\n" + + "\x10_altitude_meters\"T\n" + + "\rVideoMetadata\x12.\n" + + "\x10duration_seconds\x18\x01 \x01(\x01H\x00R\x0fdurationSeconds\x88\x01\x01B\x13\n" + + "\x11_duration_seconds\"\x8a\x04\n" + "\n" + "Attachment\x12\x17\n" + "\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12@\n" + @@ -724,7 +1160,9 @@ const file_api_v1_attachment_service_proto_rawDesc = "" + "\x04type\x18\x06 \x01(\tB\x03\xe0A\x02R\x04type\x12\x17\n" + "\x04size\x18\a \x01(\x03B\x03\xe0A\x03R\x04size\x12\x1c\n" + "\x04memo\x18\b \x01(\tB\x03\xe0A\x01H\x00R\x04memo\x88\x01\x01\x12A\n" + - "\fmotion_media\x18\t \x01(\v2\x19.memos.api.v1.MotionMediaB\x03\xe0A\x01R\vmotionMedia:O\xeaAL\n" + + "\fmotion_media\x18\t \x01(\v2\x19.memos.api.v1.MotionMediaB\x03\xe0A\x01R\vmotionMedia\x12J\n" + + "\x0emedia_metadata\x18\n" + + " \x01(\v2\x1b.memos.api.v1.MediaMetadataB\x06\xe0A\x01\xe0A\x05R\rmediaMetadata:O\xeaAL\n" + "\x17memos.api.v1/Attachment\x12\x18attachments/{attachment}*\vattachments2\n" + "attachmentB\a\n" + "\x05_memo\"\x82\x01\n" + @@ -790,49 +1228,59 @@ func file_api_v1_attachment_service_proto_rawDescGZIP() []byte { } var file_api_v1_attachment_service_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_api_v1_attachment_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_api_v1_attachment_service_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_api_v1_attachment_service_proto_goTypes = []any{ (MotionMediaFamily)(0), // 0: memos.api.v1.MotionMediaFamily (MotionMediaRole)(0), // 1: memos.api.v1.MotionMediaRole (*MotionMedia)(nil), // 2: memos.api.v1.MotionMedia - (*Attachment)(nil), // 3: memos.api.v1.Attachment - (*CreateAttachmentRequest)(nil), // 4: memos.api.v1.CreateAttachmentRequest - (*ListAttachmentsRequest)(nil), // 5: memos.api.v1.ListAttachmentsRequest - (*ListAttachmentsResponse)(nil), // 6: memos.api.v1.ListAttachmentsResponse - (*GetAttachmentRequest)(nil), // 7: memos.api.v1.GetAttachmentRequest - (*UpdateAttachmentRequest)(nil), // 8: memos.api.v1.UpdateAttachmentRequest - (*DeleteAttachmentRequest)(nil), // 9: memos.api.v1.DeleteAttachmentRequest - (*BatchDeleteAttachmentsRequest)(nil), // 10: memos.api.v1.BatchDeleteAttachmentsRequest - (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp - (*fieldmaskpb.FieldMask)(nil), // 12: google.protobuf.FieldMask - (*emptypb.Empty)(nil), // 13: google.protobuf.Empty + (*MediaMetadata)(nil), // 3: memos.api.v1.MediaMetadata + (*PhotoMetadata)(nil), // 4: memos.api.v1.PhotoMetadata + (*MediaCaptureTime)(nil), // 5: memos.api.v1.MediaCaptureTime + (*MediaLocation)(nil), // 6: memos.api.v1.MediaLocation + (*VideoMetadata)(nil), // 7: memos.api.v1.VideoMetadata + (*Attachment)(nil), // 8: memos.api.v1.Attachment + (*CreateAttachmentRequest)(nil), // 9: memos.api.v1.CreateAttachmentRequest + (*ListAttachmentsRequest)(nil), // 10: memos.api.v1.ListAttachmentsRequest + (*ListAttachmentsResponse)(nil), // 11: memos.api.v1.ListAttachmentsResponse + (*GetAttachmentRequest)(nil), // 12: memos.api.v1.GetAttachmentRequest + (*UpdateAttachmentRequest)(nil), // 13: memos.api.v1.UpdateAttachmentRequest + (*DeleteAttachmentRequest)(nil), // 14: memos.api.v1.DeleteAttachmentRequest + (*BatchDeleteAttachmentsRequest)(nil), // 15: memos.api.v1.BatchDeleteAttachmentsRequest + (*timestamppb.Timestamp)(nil), // 16: google.protobuf.Timestamp + (*fieldmaskpb.FieldMask)(nil), // 17: google.protobuf.FieldMask + (*emptypb.Empty)(nil), // 18: google.protobuf.Empty } var file_api_v1_attachment_service_proto_depIdxs = []int32{ 0, // 0: memos.api.v1.MotionMedia.family:type_name -> memos.api.v1.MotionMediaFamily 1, // 1: memos.api.v1.MotionMedia.role:type_name -> memos.api.v1.MotionMediaRole - 11, // 2: memos.api.v1.Attachment.create_time:type_name -> google.protobuf.Timestamp - 2, // 3: memos.api.v1.Attachment.motion_media:type_name -> memos.api.v1.MotionMedia - 3, // 4: memos.api.v1.CreateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment - 3, // 5: memos.api.v1.ListAttachmentsResponse.attachments:type_name -> memos.api.v1.Attachment - 3, // 6: memos.api.v1.UpdateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment - 12, // 7: memos.api.v1.UpdateAttachmentRequest.update_mask:type_name -> google.protobuf.FieldMask - 4, // 8: memos.api.v1.AttachmentService.CreateAttachment:input_type -> memos.api.v1.CreateAttachmentRequest - 5, // 9: memos.api.v1.AttachmentService.ListAttachments:input_type -> memos.api.v1.ListAttachmentsRequest - 7, // 10: memos.api.v1.AttachmentService.GetAttachment:input_type -> memos.api.v1.GetAttachmentRequest - 8, // 11: memos.api.v1.AttachmentService.UpdateAttachment:input_type -> memos.api.v1.UpdateAttachmentRequest - 9, // 12: memos.api.v1.AttachmentService.DeleteAttachment:input_type -> memos.api.v1.DeleteAttachmentRequest - 10, // 13: memos.api.v1.AttachmentService.BatchDeleteAttachments:input_type -> memos.api.v1.BatchDeleteAttachmentsRequest - 3, // 14: memos.api.v1.AttachmentService.CreateAttachment:output_type -> memos.api.v1.Attachment - 6, // 15: memos.api.v1.AttachmentService.ListAttachments:output_type -> memos.api.v1.ListAttachmentsResponse - 3, // 16: memos.api.v1.AttachmentService.GetAttachment:output_type -> memos.api.v1.Attachment - 3, // 17: memos.api.v1.AttachmentService.UpdateAttachment:output_type -> memos.api.v1.Attachment - 13, // 18: memos.api.v1.AttachmentService.DeleteAttachment:output_type -> google.protobuf.Empty - 13, // 19: memos.api.v1.AttachmentService.BatchDeleteAttachments:output_type -> google.protobuf.Empty - 14, // [14:20] is the sub-list for method output_type - 8, // [8:14] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 4, // 2: memos.api.v1.MediaMetadata.photo:type_name -> memos.api.v1.PhotoMetadata + 7, // 3: memos.api.v1.MediaMetadata.video:type_name -> memos.api.v1.VideoMetadata + 5, // 4: memos.api.v1.PhotoMetadata.capture_time:type_name -> memos.api.v1.MediaCaptureTime + 6, // 5: memos.api.v1.PhotoMetadata.location:type_name -> memos.api.v1.MediaLocation + 16, // 6: memos.api.v1.Attachment.create_time:type_name -> google.protobuf.Timestamp + 2, // 7: memos.api.v1.Attachment.motion_media:type_name -> memos.api.v1.MotionMedia + 3, // 8: memos.api.v1.Attachment.media_metadata:type_name -> memos.api.v1.MediaMetadata + 8, // 9: memos.api.v1.CreateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment + 8, // 10: memos.api.v1.ListAttachmentsResponse.attachments:type_name -> memos.api.v1.Attachment + 8, // 11: memos.api.v1.UpdateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment + 17, // 12: memos.api.v1.UpdateAttachmentRequest.update_mask:type_name -> google.protobuf.FieldMask + 9, // 13: memos.api.v1.AttachmentService.CreateAttachment:input_type -> memos.api.v1.CreateAttachmentRequest + 10, // 14: memos.api.v1.AttachmentService.ListAttachments:input_type -> memos.api.v1.ListAttachmentsRequest + 12, // 15: memos.api.v1.AttachmentService.GetAttachment:input_type -> memos.api.v1.GetAttachmentRequest + 13, // 16: memos.api.v1.AttachmentService.UpdateAttachment:input_type -> memos.api.v1.UpdateAttachmentRequest + 14, // 17: memos.api.v1.AttachmentService.DeleteAttachment:input_type -> memos.api.v1.DeleteAttachmentRequest + 15, // 18: memos.api.v1.AttachmentService.BatchDeleteAttachments:input_type -> memos.api.v1.BatchDeleteAttachmentsRequest + 8, // 19: memos.api.v1.AttachmentService.CreateAttachment:output_type -> memos.api.v1.Attachment + 11, // 20: memos.api.v1.AttachmentService.ListAttachments:output_type -> memos.api.v1.ListAttachmentsResponse + 8, // 21: memos.api.v1.AttachmentService.GetAttachment:output_type -> memos.api.v1.Attachment + 8, // 22: memos.api.v1.AttachmentService.UpdateAttachment:output_type -> memos.api.v1.Attachment + 18, // 23: memos.api.v1.AttachmentService.DeleteAttachment:output_type -> google.protobuf.Empty + 18, // 24: memos.api.v1.AttachmentService.BatchDeleteAttachments:output_type -> google.protobuf.Empty + 19, // [19:25] is the sub-list for method output_type + 13, // [13:19] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_api_v1_attachment_service_proto_init() } @@ -840,14 +1288,22 @@ func file_api_v1_attachment_service_proto_init() { if File_api_v1_attachment_service_proto != nil { return } - file_api_v1_attachment_service_proto_msgTypes[1].OneofWrappers = []any{} + file_api_v1_attachment_service_proto_msgTypes[1].OneofWrappers = []any{ + (*MediaMetadata_Photo)(nil), + (*MediaMetadata_Video)(nil), + } + file_api_v1_attachment_service_proto_msgTypes[2].OneofWrappers = []any{} + file_api_v1_attachment_service_proto_msgTypes[3].OneofWrappers = []any{} + file_api_v1_attachment_service_proto_msgTypes[4].OneofWrappers = []any{} + file_api_v1_attachment_service_proto_msgTypes[5].OneofWrappers = []any{} + file_api_v1_attachment_service_proto_msgTypes[6].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_api_v1_attachment_service_proto_rawDesc), len(file_api_v1_attachment_service_proto_rawDesc)), NumEnums: 2, - NumMessages: 9, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/gen/api/v1/user_service.pb.go b/proto/gen/api/v1/user_service.pb.go index 5cbd81af..b1883e70 100644 --- a/proto/gen/api/v1/user_service.pb.go +++ b/proto/gen/api/v1/user_service.pb.go @@ -2997,9 +2997,11 @@ type UserSetting_GeneralSetting struct { // The preferred theme of the user. // This references a CSS file in the web/public/themes/ directory. // If not set, the default theme will be used. - Theme string `protobuf:"bytes,4,opt,name=theme,proto3" json:"theme,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + Theme string `protobuf:"bytes,4,opt,name=theme,proto3" json:"theme,omitempty"` + // Whether the official client should save metadata from future media uploads. + SaveMediaMetadata bool `protobuf:"varint,5,opt,name=save_media_metadata,json=saveMediaMetadata,proto3" json:"save_media_metadata,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *UserSetting_GeneralSetting) Reset() { @@ -3053,6 +3055,13 @@ func (x *UserSetting_GeneralSetting) GetTheme() string { return "" } +func (x *UserSetting_GeneralSetting) GetSaveMediaMetadata() bool { + if x != nil { + return x.SaveMediaMetadata + } + return false +} + // Tag metadata for user-specific display rules. type UserSetting_TagMetadata struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -3437,16 +3446,17 @@ const file_api_v1_user_service_proto_rawDesc = "" + "\x05state\x18\x01 \x01(\x0e2\x13.memos.api.v1.StateB\x03\xe0A\x01R\x05state\x12\x1b\n" + "\x06filter\x18\x02 \x01(\tB\x03\xe0A\x01R\x06filter\"I\n" + "\x18ListAllUserStatsResponse\x12-\n" + - "\x05stats\x18\x01 \x03(\v2\x17.memos.api.v1.UserStatsR\x05stats\"\xbb\a\n" + + "\x05stats\x18\x01 \x03(\v2\x17.memos.api.v1.UserStatsR\x05stats\"\xf1\a\n" + "\vUserSetting\x12\x17\n" + "\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12S\n" + "\x0fgeneral_setting\x18\x02 \x01(\v2(.memos.api.v1.UserSetting.GeneralSettingH\x00R\x0egeneralSetting\x12V\n" + "\x10webhooks_setting\x18\x05 \x01(\v2).memos.api.v1.UserSetting.WebhooksSettingH\x00R\x0fwebhooksSetting\x12J\n" + - "\ftags_setting\x18\x06 \x01(\v2%.memos.api.v1.UserSetting.TagsSettingH\x00R\vtagsSetting\x1av\n" + + "\ftags_setting\x18\x06 \x01(\v2%.memos.api.v1.UserSetting.TagsSettingH\x00R\vtagsSetting\x1a\xab\x01\n" + "\x0eGeneralSetting\x12\x1b\n" + "\x06locale\x18\x01 \x01(\tB\x03\xe0A\x01R\x06locale\x12,\n" + "\x0fmemo_visibility\x18\x03 \x01(\tB\x03\xe0A\x01R\x0ememoVisibility\x12\x19\n" + - "\x05theme\x18\x04 \x01(\tB\x03\xe0A\x01R\x05theme\x1ay\n" + + "\x05theme\x18\x04 \x01(\tB\x03\xe0A\x01R\x05theme\x123\n" + + "\x13save_media_metadata\x18\x05 \x01(\bB\x03\xe0A\x01R\x11saveMediaMetadata\x1ay\n" + "\vTagMetadata\x12B\n" + "\x10background_color\x18\x01 \x01(\v2\x12.google.type.ColorB\x03\xe0A\x01R\x0fbackgroundColor\x12&\n" + "\fblur_content\x18\x02 \x01(\bB\x03\xe0A\x01R\vblurContent\x1a\xb7\x01\n" + diff --git a/proto/gen/openapi.yaml b/proto/gen/openapi.yaml index da8b69a2..6fb5439c 100644 --- a/proto/gen/openapi.yaml +++ b/proto/gen/openapi.yaml @@ -2406,6 +2406,10 @@ components: allOf: - $ref: '#/components/schemas/MotionMedia' description: Optional. Motion media metadata. + mediaMetadata: + allOf: + - $ref: '#/components/schemas/MediaMetadata' + description: Optional. Immutable normalized media metadata explicitly supplied by the client at creation time. BatchDeleteAttachmentsRequest: required: - names @@ -3219,6 +3223,38 @@ components: type: number description: The longitude of the location. format: double + MediaCaptureTime: + type: object + properties: + localDateTime: + type: string + utcOffset: + type: string + MediaLocation: + type: object + properties: + latitude: + type: number + format: double + longitude: + type: number + format: double + altitudeMeters: + type: number + format: double + MediaMetadata: + type: object + properties: + width: + type: integer + format: int32 + height: + type: integer + format: int32 + photo: + $ref: '#/components/schemas/PhotoMetadata' + video: + $ref: '#/components/schemas/VideoMetadata' Memo: required: - state @@ -3504,6 +3540,34 @@ components: description: |- PersonalAccessToken represents a long-lived token for API/script access. PATs are distinct from short-lived JWT access tokens used for session authentication. + PhotoMetadata: + type: object + properties: + captureTime: + $ref: '#/components/schemas/MediaCaptureTime' + location: + $ref: '#/components/schemas/MediaLocation' + sourceExifOrientation: + type: integer + format: int32 + cameraMake: + type: string + cameraModel: + type: string + lensModel: + type: string + fNumber: + type: number + format: double + exposureTimeSeconds: + type: number + format: double + iso: + type: integer + format: int32 + focalLengthMm: + type: number + format: double Reaction: required: - contentId @@ -3922,6 +3986,9 @@ components: The preferred theme of the user. This references a CSS file in the web/public/themes/ directory. If not set, the default theme will be used. + saveMediaMetadata: + type: boolean + description: Whether the official client should save metadata from future media uploads. description: General user settings configuration. UserSetting_TagMetadata: type: object @@ -4050,6 +4117,12 @@ components: type: boolean description: Whether a signing secret is configured for this webhook. description: UserWebhook represents a webhook owned by a user. + VideoMetadata: + type: object + properties: + durationSeconds: + type: number + format: double tags: - name: AIService - name: AttachmentService diff --git a/proto/gen/store/attachment.pb.go b/proto/gen/store/attachment.pb.go index 605ff6c5..3c16abee 100644 --- a/proto/gen/store/attachment.pb.go +++ b/proto/gen/store/attachment.pb.go @@ -254,6 +254,376 @@ func (x *MotionMedia) GetHasEmbeddedVideo() bool { return false } +type MediaMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + Width *int32 `protobuf:"varint,1,opt,name=width,proto3,oneof" json:"width,omitempty"` + Height *int32 `protobuf:"varint,2,opt,name=height,proto3,oneof" json:"height,omitempty"` + // Types that are valid to be assigned to Details: + // + // *MediaMetadata_Photo + // *MediaMetadata_Video + Details isMediaMetadata_Details `protobuf_oneof:"details"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaMetadata) Reset() { + *x = MediaMetadata{} + mi := &file_store_attachment_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaMetadata) ProtoMessage() {} + +func (x *MediaMetadata) ProtoReflect() protoreflect.Message { + mi := &file_store_attachment_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaMetadata.ProtoReflect.Descriptor instead. +func (*MediaMetadata) Descriptor() ([]byte, []int) { + return file_store_attachment_proto_rawDescGZIP(), []int{1} +} + +func (x *MediaMetadata) GetWidth() int32 { + if x != nil && x.Width != nil { + return *x.Width + } + return 0 +} + +func (x *MediaMetadata) GetHeight() int32 { + if x != nil && x.Height != nil { + return *x.Height + } + return 0 +} + +func (x *MediaMetadata) GetDetails() isMediaMetadata_Details { + if x != nil { + return x.Details + } + return nil +} + +func (x *MediaMetadata) GetPhoto() *PhotoMetadata { + if x != nil { + if x, ok := x.Details.(*MediaMetadata_Photo); ok { + return x.Photo + } + } + return nil +} + +func (x *MediaMetadata) GetVideo() *VideoMetadata { + if x != nil { + if x, ok := x.Details.(*MediaMetadata_Video); ok { + return x.Video + } + } + return nil +} + +type isMediaMetadata_Details interface { + isMediaMetadata_Details() +} + +type MediaMetadata_Photo struct { + Photo *PhotoMetadata `protobuf:"bytes,3,opt,name=photo,proto3,oneof"` +} + +type MediaMetadata_Video struct { + Video *VideoMetadata `protobuf:"bytes,4,opt,name=video,proto3,oneof"` +} + +func (*MediaMetadata_Photo) isMediaMetadata_Details() {} + +func (*MediaMetadata_Video) isMediaMetadata_Details() {} + +type PhotoMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + CaptureTime *MediaCaptureTime `protobuf:"bytes,1,opt,name=capture_time,json=captureTime,proto3" json:"capture_time,omitempty"` + Location *MediaLocation `protobuf:"bytes,2,opt,name=location,proto3" json:"location,omitempty"` + SourceExifOrientation *int32 `protobuf:"varint,3,opt,name=source_exif_orientation,json=sourceExifOrientation,proto3,oneof" json:"source_exif_orientation,omitempty"` + CameraMake string `protobuf:"bytes,4,opt,name=camera_make,json=cameraMake,proto3" json:"camera_make,omitempty"` + CameraModel string `protobuf:"bytes,5,opt,name=camera_model,json=cameraModel,proto3" json:"camera_model,omitempty"` + LensModel string `protobuf:"bytes,6,opt,name=lens_model,json=lensModel,proto3" json:"lens_model,omitempty"` + FNumber *float64 `protobuf:"fixed64,7,opt,name=f_number,json=fNumber,proto3,oneof" json:"f_number,omitempty"` + ExposureTimeSeconds *float64 `protobuf:"fixed64,8,opt,name=exposure_time_seconds,json=exposureTimeSeconds,proto3,oneof" json:"exposure_time_seconds,omitempty"` + Iso *int32 `protobuf:"varint,9,opt,name=iso,proto3,oneof" json:"iso,omitempty"` + FocalLengthMm *float64 `protobuf:"fixed64,10,opt,name=focal_length_mm,json=focalLengthMm,proto3,oneof" json:"focal_length_mm,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PhotoMetadata) Reset() { + *x = PhotoMetadata{} + mi := &file_store_attachment_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PhotoMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PhotoMetadata) ProtoMessage() {} + +func (x *PhotoMetadata) ProtoReflect() protoreflect.Message { + mi := &file_store_attachment_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PhotoMetadata.ProtoReflect.Descriptor instead. +func (*PhotoMetadata) Descriptor() ([]byte, []int) { + return file_store_attachment_proto_rawDescGZIP(), []int{2} +} + +func (x *PhotoMetadata) GetCaptureTime() *MediaCaptureTime { + if x != nil { + return x.CaptureTime + } + return nil +} + +func (x *PhotoMetadata) GetLocation() *MediaLocation { + if x != nil { + return x.Location + } + return nil +} + +func (x *PhotoMetadata) GetSourceExifOrientation() int32 { + if x != nil && x.SourceExifOrientation != nil { + return *x.SourceExifOrientation + } + return 0 +} + +func (x *PhotoMetadata) GetCameraMake() string { + if x != nil { + return x.CameraMake + } + return "" +} + +func (x *PhotoMetadata) GetCameraModel() string { + if x != nil { + return x.CameraModel + } + return "" +} + +func (x *PhotoMetadata) GetLensModel() string { + if x != nil { + return x.LensModel + } + return "" +} + +func (x *PhotoMetadata) GetFNumber() float64 { + if x != nil && x.FNumber != nil { + return *x.FNumber + } + return 0 +} + +func (x *PhotoMetadata) GetExposureTimeSeconds() float64 { + if x != nil && x.ExposureTimeSeconds != nil { + return *x.ExposureTimeSeconds + } + return 0 +} + +func (x *PhotoMetadata) GetIso() int32 { + if x != nil && x.Iso != nil { + return *x.Iso + } + return 0 +} + +func (x *PhotoMetadata) GetFocalLengthMm() float64 { + if x != nil && x.FocalLengthMm != nil { + return *x.FocalLengthMm + } + return 0 +} + +type MediaCaptureTime struct { + state protoimpl.MessageState `protogen:"open.v1"` + LocalDateTime string `protobuf:"bytes,1,opt,name=local_date_time,json=localDateTime,proto3" json:"local_date_time,omitempty"` + UtcOffset *string `protobuf:"bytes,2,opt,name=utc_offset,json=utcOffset,proto3,oneof" json:"utc_offset,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaCaptureTime) Reset() { + *x = MediaCaptureTime{} + mi := &file_store_attachment_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaCaptureTime) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaCaptureTime) ProtoMessage() {} + +func (x *MediaCaptureTime) ProtoReflect() protoreflect.Message { + mi := &file_store_attachment_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaCaptureTime.ProtoReflect.Descriptor instead. +func (*MediaCaptureTime) Descriptor() ([]byte, []int) { + return file_store_attachment_proto_rawDescGZIP(), []int{3} +} + +func (x *MediaCaptureTime) GetLocalDateTime() string { + if x != nil { + return x.LocalDateTime + } + return "" +} + +func (x *MediaCaptureTime) GetUtcOffset() string { + if x != nil && x.UtcOffset != nil { + return *x.UtcOffset + } + return "" +} + +type MediaLocation struct { + state protoimpl.MessageState `protogen:"open.v1"` + Latitude *float64 `protobuf:"fixed64,1,opt,name=latitude,proto3,oneof" json:"latitude,omitempty"` + Longitude *float64 `protobuf:"fixed64,2,opt,name=longitude,proto3,oneof" json:"longitude,omitempty"` + AltitudeMeters *float64 `protobuf:"fixed64,3,opt,name=altitude_meters,json=altitudeMeters,proto3,oneof" json:"altitude_meters,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MediaLocation) Reset() { + *x = MediaLocation{} + mi := &file_store_attachment_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MediaLocation) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MediaLocation) ProtoMessage() {} + +func (x *MediaLocation) ProtoReflect() protoreflect.Message { + mi := &file_store_attachment_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MediaLocation.ProtoReflect.Descriptor instead. +func (*MediaLocation) Descriptor() ([]byte, []int) { + return file_store_attachment_proto_rawDescGZIP(), []int{4} +} + +func (x *MediaLocation) GetLatitude() float64 { + if x != nil && x.Latitude != nil { + return *x.Latitude + } + return 0 +} + +func (x *MediaLocation) GetLongitude() float64 { + if x != nil && x.Longitude != nil { + return *x.Longitude + } + return 0 +} + +func (x *MediaLocation) GetAltitudeMeters() float64 { + if x != nil && x.AltitudeMeters != nil { + return *x.AltitudeMeters + } + return 0 +} + +type VideoMetadata struct { + state protoimpl.MessageState `protogen:"open.v1"` + DurationSeconds *float64 `protobuf:"fixed64,1,opt,name=duration_seconds,json=durationSeconds,proto3,oneof" json:"duration_seconds,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *VideoMetadata) Reset() { + *x = VideoMetadata{} + mi := &file_store_attachment_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *VideoMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*VideoMetadata) ProtoMessage() {} + +func (x *VideoMetadata) ProtoReflect() protoreflect.Message { + mi := &file_store_attachment_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use VideoMetadata.ProtoReflect.Descriptor instead. +func (*VideoMetadata) Descriptor() ([]byte, []int) { + return file_store_attachment_proto_rawDescGZIP(), []int{5} +} + +func (x *VideoMetadata) GetDurationSeconds() float64 { + if x != nil && x.DurationSeconds != nil { + return *x.DurationSeconds + } + return 0 +} + type AttachmentPayload struct { state protoimpl.MessageState `protogen:"open.v1"` // Types that are valid to be assigned to Payload: @@ -261,13 +631,14 @@ type AttachmentPayload struct { // *AttachmentPayload_S3Object_ Payload isAttachmentPayload_Payload `protobuf_oneof:"payload"` MotionMedia *MotionMedia `protobuf:"bytes,10,opt,name=motion_media,json=motionMedia,proto3" json:"motion_media,omitempty"` + MediaMetadata *MediaMetadata `protobuf:"bytes,11,opt,name=media_metadata,json=mediaMetadata,proto3" json:"media_metadata,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *AttachmentPayload) Reset() { *x = AttachmentPayload{} - mi := &file_store_attachment_proto_msgTypes[1] + mi := &file_store_attachment_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -279,7 +650,7 @@ func (x *AttachmentPayload) String() string { func (*AttachmentPayload) ProtoMessage() {} func (x *AttachmentPayload) ProtoReflect() protoreflect.Message { - mi := &file_store_attachment_proto_msgTypes[1] + mi := &file_store_attachment_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -292,7 +663,7 @@ func (x *AttachmentPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use AttachmentPayload.ProtoReflect.Descriptor instead. func (*AttachmentPayload) Descriptor() ([]byte, []int) { - return file_store_attachment_proto_rawDescGZIP(), []int{1} + return file_store_attachment_proto_rawDescGZIP(), []int{6} } func (x *AttachmentPayload) GetPayload() isAttachmentPayload_Payload { @@ -318,6 +689,13 @@ func (x *AttachmentPayload) GetMotionMedia() *MotionMedia { return nil } +func (x *AttachmentPayload) GetMediaMetadata() *MediaMetadata { + if x != nil { + return x.MediaMetadata + } + return nil +} + type isAttachmentPayload_Payload interface { isAttachmentPayload_Payload() } @@ -342,7 +720,7 @@ type AttachmentPayload_S3Object struct { func (x *AttachmentPayload_S3Object) Reset() { *x = AttachmentPayload_S3Object{} - mi := &file_store_attachment_proto_msgTypes[2] + mi := &file_store_attachment_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -354,7 +732,7 @@ func (x *AttachmentPayload_S3Object) String() string { func (*AttachmentPayload_S3Object) ProtoMessage() {} func (x *AttachmentPayload_S3Object) ProtoReflect() protoreflect.Message { - mi := &file_store_attachment_proto_msgTypes[2] + mi := &file_store_attachment_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -367,7 +745,7 @@ func (x *AttachmentPayload_S3Object) ProtoReflect() protoreflect.Message { // Deprecated: Use AttachmentPayload_S3Object.ProtoReflect.Descriptor instead. func (*AttachmentPayload_S3Object) Descriptor() ([]byte, []int) { - return file_store_attachment_proto_rawDescGZIP(), []int{1, 0} + return file_store_attachment_proto_rawDescGZIP(), []int{6, 0} } func (x *AttachmentPayload_S3Object) GetS3Config() *StorageS3Config { @@ -401,11 +779,55 @@ const file_store_attachment_proto_rawDesc = "" + "\x04role\x18\x02 \x01(\x0e2\x1c.memos.store.MotionMediaRoleR\x04role\x12\x19\n" + "\bgroup_id\x18\x03 \x01(\tR\agroupId\x12:\n" + "\x19presentation_timestamp_us\x18\x04 \x01(\x03R\x17presentationTimestampUs\x12,\n" + - "\x12has_embedded_video\x18\x05 \x01(\bR\x10hasEmbeddedVideo\"\xc9\x02\n" + + "\x12has_embedded_video\x18\x05 \x01(\bR\x10hasEmbeddedVideo\"\xcf\x01\n" + + "\rMediaMetadata\x12\x19\n" + + "\x05width\x18\x01 \x01(\x05H\x01R\x05width\x88\x01\x01\x12\x1b\n" + + "\x06height\x18\x02 \x01(\x05H\x02R\x06height\x88\x01\x01\x122\n" + + "\x05photo\x18\x03 \x01(\v2\x1a.memos.store.PhotoMetadataH\x00R\x05photo\x122\n" + + "\x05video\x18\x04 \x01(\v2\x1a.memos.store.VideoMetadataH\x00R\x05videoB\t\n" + + "\adetailsB\b\n" + + "\x06_widthB\t\n" + + "\a_height\"\xa5\x04\n" + + "\rPhotoMetadata\x12@\n" + + "\fcapture_time\x18\x01 \x01(\v2\x1d.memos.store.MediaCaptureTimeR\vcaptureTime\x126\n" + + "\blocation\x18\x02 \x01(\v2\x1a.memos.store.MediaLocationR\blocation\x12;\n" + + "\x17source_exif_orientation\x18\x03 \x01(\x05H\x00R\x15sourceExifOrientation\x88\x01\x01\x12\x1f\n" + + "\vcamera_make\x18\x04 \x01(\tR\n" + + "cameraMake\x12!\n" + + "\fcamera_model\x18\x05 \x01(\tR\vcameraModel\x12\x1d\n" + + "\n" + + "lens_model\x18\x06 \x01(\tR\tlensModel\x12\x1e\n" + + "\bf_number\x18\a \x01(\x01H\x01R\afNumber\x88\x01\x01\x127\n" + + "\x15exposure_time_seconds\x18\b \x01(\x01H\x02R\x13exposureTimeSeconds\x88\x01\x01\x12\x15\n" + + "\x03iso\x18\t \x01(\x05H\x03R\x03iso\x88\x01\x01\x12+\n" + + "\x0ffocal_length_mm\x18\n" + + " \x01(\x01H\x04R\rfocalLengthMm\x88\x01\x01B\x1a\n" + + "\x18_source_exif_orientationB\v\n" + + "\t_f_numberB\x18\n" + + "\x16_exposure_time_secondsB\x06\n" + + "\x04_isoB\x12\n" + + "\x10_focal_length_mm\"m\n" + + "\x10MediaCaptureTime\x12&\n" + + "\x0flocal_date_time\x18\x01 \x01(\tR\rlocalDateTime\x12\"\n" + + "\n" + + "utc_offset\x18\x02 \x01(\tH\x00R\tutcOffset\x88\x01\x01B\r\n" + + "\v_utc_offset\"\xb0\x01\n" + + "\rMediaLocation\x12\x1f\n" + + "\blatitude\x18\x01 \x01(\x01H\x00R\blatitude\x88\x01\x01\x12!\n" + + "\tlongitude\x18\x02 \x01(\x01H\x01R\tlongitude\x88\x01\x01\x12,\n" + + "\x0faltitude_meters\x18\x03 \x01(\x01H\x02R\x0ealtitudeMeters\x88\x01\x01B\v\n" + + "\t_latitudeB\f\n" + + "\n" + + "_longitudeB\x12\n" + + "\x10_altitude_meters\"T\n" + + "\rVideoMetadata\x12.\n" + + "\x10duration_seconds\x18\x01 \x01(\x01H\x00R\x0fdurationSeconds\x88\x01\x01B\x13\n" + + "\x11_duration_seconds\"\x8c\x03\n" + "\x11AttachmentPayload\x12F\n" + "\ts3_object\x18\x01 \x01(\v2'.memos.store.AttachmentPayload.S3ObjectH\x00R\bs3Object\x12;\n" + "\fmotion_media\x18\n" + - " \x01(\v2\x18.memos.store.MotionMediaR\vmotionMedia\x1a\xa3\x01\n" + + " \x01(\v2\x18.memos.store.MotionMediaR\vmotionMedia\x12A\n" + + "\x0emedia_metadata\x18\v \x01(\v2\x1a.memos.store.MediaMetadataR\rmediaMetadata\x1a\xa3\x01\n" + "\bS3Object\x129\n" + "\ts3_config\x18\x01 \x01(\v2\x1c.memos.store.StorageS3ConfigR\bs3Config\x12\x10\n" + "\x03key\x18\x02 \x01(\tR\x03key\x12J\n" + @@ -440,29 +862,39 @@ func file_store_attachment_proto_rawDescGZIP() []byte { } var file_store_attachment_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_store_attachment_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_store_attachment_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_store_attachment_proto_goTypes = []any{ (AttachmentStorageType)(0), // 0: memos.store.AttachmentStorageType (MotionMediaFamily)(0), // 1: memos.store.MotionMediaFamily (MotionMediaRole)(0), // 2: memos.store.MotionMediaRole (*MotionMedia)(nil), // 3: memos.store.MotionMedia - (*AttachmentPayload)(nil), // 4: memos.store.AttachmentPayload - (*AttachmentPayload_S3Object)(nil), // 5: memos.store.AttachmentPayload.S3Object - (*StorageS3Config)(nil), // 6: memos.store.StorageS3Config - (*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp + (*MediaMetadata)(nil), // 4: memos.store.MediaMetadata + (*PhotoMetadata)(nil), // 5: memos.store.PhotoMetadata + (*MediaCaptureTime)(nil), // 6: memos.store.MediaCaptureTime + (*MediaLocation)(nil), // 7: memos.store.MediaLocation + (*VideoMetadata)(nil), // 8: memos.store.VideoMetadata + (*AttachmentPayload)(nil), // 9: memos.store.AttachmentPayload + (*AttachmentPayload_S3Object)(nil), // 10: memos.store.AttachmentPayload.S3Object + (*StorageS3Config)(nil), // 11: memos.store.StorageS3Config + (*timestamppb.Timestamp)(nil), // 12: google.protobuf.Timestamp } var file_store_attachment_proto_depIdxs = []int32{ - 1, // 0: memos.store.MotionMedia.family:type_name -> memos.store.MotionMediaFamily - 2, // 1: memos.store.MotionMedia.role:type_name -> memos.store.MotionMediaRole - 5, // 2: memos.store.AttachmentPayload.s3_object:type_name -> memos.store.AttachmentPayload.S3Object - 3, // 3: memos.store.AttachmentPayload.motion_media:type_name -> memos.store.MotionMedia - 6, // 4: memos.store.AttachmentPayload.S3Object.s3_config:type_name -> memos.store.StorageS3Config - 7, // 5: memos.store.AttachmentPayload.S3Object.last_presigned_time:type_name -> google.protobuf.Timestamp - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 1, // 0: memos.store.MotionMedia.family:type_name -> memos.store.MotionMediaFamily + 2, // 1: memos.store.MotionMedia.role:type_name -> memos.store.MotionMediaRole + 5, // 2: memos.store.MediaMetadata.photo:type_name -> memos.store.PhotoMetadata + 8, // 3: memos.store.MediaMetadata.video:type_name -> memos.store.VideoMetadata + 6, // 4: memos.store.PhotoMetadata.capture_time:type_name -> memos.store.MediaCaptureTime + 7, // 5: memos.store.PhotoMetadata.location:type_name -> memos.store.MediaLocation + 10, // 6: memos.store.AttachmentPayload.s3_object:type_name -> memos.store.AttachmentPayload.S3Object + 3, // 7: memos.store.AttachmentPayload.motion_media:type_name -> memos.store.MotionMedia + 4, // 8: memos.store.AttachmentPayload.media_metadata:type_name -> memos.store.MediaMetadata + 11, // 9: memos.store.AttachmentPayload.S3Object.s3_config:type_name -> memos.store.StorageS3Config + 12, // 10: memos.store.AttachmentPayload.S3Object.last_presigned_time:type_name -> google.protobuf.Timestamp + 11, // [11:11] is the sub-list for method output_type + 11, // [11:11] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_store_attachment_proto_init() } @@ -472,6 +904,14 @@ func file_store_attachment_proto_init() { } file_store_instance_setting_proto_init() file_store_attachment_proto_msgTypes[1].OneofWrappers = []any{ + (*MediaMetadata_Photo)(nil), + (*MediaMetadata_Video)(nil), + } + file_store_attachment_proto_msgTypes[2].OneofWrappers = []any{} + file_store_attachment_proto_msgTypes[3].OneofWrappers = []any{} + file_store_attachment_proto_msgTypes[4].OneofWrappers = []any{} + file_store_attachment_proto_msgTypes[5].OneofWrappers = []any{} + file_store_attachment_proto_msgTypes[6].OneofWrappers = []any{ (*AttachmentPayload_S3Object_)(nil), } type x struct{} @@ -480,7 +920,7 @@ func file_store_attachment_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_store_attachment_proto_rawDesc), len(file_store_attachment_proto_rawDesc)), NumEnums: 3, - NumMessages: 3, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/gen/store/user_setting.pb.go b/proto/gen/store/user_setting.pb.go index f05ba4d2..165f1ed3 100644 --- a/proto/gen/store/user_setting.pb.go +++ b/proto/gen/store/user_setting.pb.go @@ -260,9 +260,11 @@ type GeneralUserSetting struct { MemoVisibility string `protobuf:"bytes,2,opt,name=memo_visibility,json=memoVisibility,proto3" json:"memo_visibility,omitempty"` // The user's theme preference. // This references a CSS file in the web/public/themes/ directory. - Theme string `protobuf:"bytes,3,opt,name=theme,proto3" json:"theme,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + Theme string `protobuf:"bytes,3,opt,name=theme,proto3" json:"theme,omitempty"` + // Whether the official client should save metadata from future media uploads. + SaveMediaMetadata bool `protobuf:"varint,4,opt,name=save_media_metadata,json=saveMediaMetadata,proto3" json:"save_media_metadata,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *GeneralUserSetting) Reset() { @@ -316,6 +318,13 @@ func (x *GeneralUserSetting) GetTheme() string { return "" } +func (x *GeneralUserSetting) GetSaveMediaMetadata() bool { + if x != nil { + return x.SaveMediaMetadata + } + return false +} + type UserTagMetadata struct { state protoimpl.MessageState `protogen:"open.v1"` // Optional background color for the tag label. @@ -1004,11 +1013,12 @@ const file_store_user_setting_proto_rawDesc = "" + "\x0eREFRESH_TOKENS\x10\x06\x12\x1a\n" + "\x16PERSONAL_ACCESS_TOKENS\x10\a\x12\b\n" + "\x04TAGS\x10\bB\a\n" + - "\x05value\"k\n" + + "\x05value\"\x9b\x01\n" + "\x12GeneralUserSetting\x12\x16\n" + "\x06locale\x18\x01 \x01(\tR\x06locale\x12'\n" + "\x0fmemo_visibility\x18\x02 \x01(\tR\x0ememoVisibility\x12\x14\n" + - "\x05theme\x18\x03 \x01(\tR\x05theme\"s\n" + + "\x05theme\x18\x03 \x01(\tR\x05theme\x12.\n" + + "\x13save_media_metadata\x18\x04 \x01(\bR\x11saveMediaMetadata\"s\n" + "\x0fUserTagMetadata\x12=\n" + "\x10background_color\x18\x01 \x01(\v2\x12.google.type.ColorR\x0fbackgroundColor\x12!\n" + "\fblur_content\x18\x02 \x01(\bR\vblurContent\"\xa4\x01\n" + diff --git a/proto/store/attachment.proto b/proto/store/attachment.proto index 8438bf48..12927886 100644 --- a/proto/store/attachment.proto +++ b/proto/store/attachment.proto @@ -38,12 +38,51 @@ message MotionMedia { bool has_embedded_video = 5; } +message MediaMetadata { + optional int32 width = 1; + optional int32 height = 2; + + oneof details { + PhotoMetadata photo = 3; + VideoMetadata video = 4; + } +} + +message PhotoMetadata { + MediaCaptureTime capture_time = 1; + MediaLocation location = 2; + optional int32 source_exif_orientation = 3; + string camera_make = 4; + string camera_model = 5; + string lens_model = 6; + optional double f_number = 7; + optional double exposure_time_seconds = 8; + optional int32 iso = 9; + optional double focal_length_mm = 10; +} + +message MediaCaptureTime { + string local_date_time = 1; + optional string utc_offset = 2; +} + +message MediaLocation { + optional double latitude = 1; + optional double longitude = 2; + optional double altitude_meters = 3; +} + +message VideoMetadata { + optional double duration_seconds = 1; +} + message AttachmentPayload { oneof payload { S3Object s3_object = 1; } MotionMedia motion_media = 10; + MediaMetadata media_metadata = 11; message S3Object { StorageS3Config s3_config = 1; diff --git a/proto/store/user_setting.proto b/proto/store/user_setting.proto index d5e1bca7..3244f3b8 100644 --- a/proto/store/user_setting.proto +++ b/proto/store/user_setting.proto @@ -45,6 +45,8 @@ message GeneralUserSetting { // The user's theme preference. // This references a CSS file in the web/public/themes/ directory. string theme = 3; + // Whether the official client should save metadata from future media uploads. + bool save_media_metadata = 4; } message UserTagMetadata { diff --git a/server/router/api/v1/attachment_media_metadata.go b/server/router/api/v1/attachment_media_metadata.go new file mode 100644 index 00000000..2b4e0df2 --- /dev/null +++ b/server/router/api/v1/attachment_media_metadata.go @@ -0,0 +1,204 @@ +package v1 + +import ( + "math" + "regexp" + "strconv" + "strings" + "time" + "unicode" + + "github.com/pkg/errors" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + + v1pb "github.com/usememos/memos/proto/gen/api/v1" + storepb "github.com/usememos/memos/proto/gen/store" +) + +const maxMediaMetadataStringBytes = 256 + +var ( + mediaLocalDateTimePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$`) + mediaUTCOffsetPattern = regexp.MustCompile(`^[+-](\d{2}):(\d{2})$`) +) + +func validateClientMediaMetadata(metadata *v1pb.MediaMetadata, mimeType string) (*storepb.MediaMetadata, error) { + if metadata == nil { + return nil, nil + } + + normalizedMIMEType := strings.ToLower(mimeType) + isImage := strings.HasPrefix(normalizedMIMEType, "image/") + isVideo := strings.HasPrefix(normalizedMIMEType, "video/") + if !isImage && !isVideo { + return nil, status.Errorf(codes.InvalidArgument, "media_metadata is only supported for image and video attachments") + } + + if (metadata.Width == nil) != (metadata.Height == nil) { + return nil, status.Errorf(codes.InvalidArgument, "media_metadata width and height must be provided together") + } + if metadata.Width != nil && (*metadata.Width <= 0 || *metadata.Height <= 0) { + return nil, status.Errorf(codes.InvalidArgument, "media_metadata width and height must be positive") + } + + switch details := metadata.Details.(type) { + case nil: + if metadata.Width == nil { + return nil, status.Errorf(codes.InvalidArgument, "media_metadata must contain at least one value") + } + case *v1pb.MediaMetadata_Photo: + if !isImage { + return nil, status.Errorf(codes.InvalidArgument, "photo metadata requires an image MIME type") + } + if proto.Size(details.Photo) == 0 { + return nil, status.Errorf(codes.InvalidArgument, "photo metadata must contain at least one value") + } + if err := validatePhotoMetadata(details.Photo); err != nil { + return nil, err + } + case *v1pb.MediaMetadata_Video: + if !isVideo { + return nil, status.Errorf(codes.InvalidArgument, "video metadata requires a video MIME type") + } + if details.Video == nil || details.Video.DurationSeconds == nil { + return nil, status.Errorf(codes.InvalidArgument, "video metadata must contain at least one value") + } + if !isFinite(*details.Video.DurationSeconds) || *details.Video.DurationSeconds < 0 { + return nil, status.Errorf(codes.InvalidArgument, "video duration_seconds must be a finite non-negative number") + } + default: + return nil, status.Errorf(codes.InvalidArgument, "unsupported media_metadata details") + } + + storeMetadata := &storepb.MediaMetadata{} + if err := transcodeProto(metadata, storeMetadata); err != nil { + return nil, status.Errorf(codes.Internal, "failed to convert media_metadata: %v", err) + } + return storeMetadata, nil +} + +func validatePhotoMetadata(photo *v1pb.PhotoMetadata) error { + if photo.SourceExifOrientation != nil && (*photo.SourceExifOrientation < 1 || *photo.SourceExifOrientation > 8) { + return status.Errorf(codes.InvalidArgument, "photo source_exif_orientation must be between 1 and 8") + } + for _, field := range []struct { + name string + value string + }{ + {"camera_make", photo.CameraMake}, + {"camera_model", photo.CameraModel}, + {"lens_model", photo.LensModel}, + } { + if field.value == "" { + continue + } + if len(field.value) > maxMediaMetadataStringBytes { + return status.Errorf(codes.InvalidArgument, "photo %s exceeds %d bytes", field.name, maxMediaMetadataStringBytes) + } + if strings.TrimSpace(field.value) == "" { + return status.Errorf(codes.InvalidArgument, "photo %s must not be blank", field.name) + } + if strings.ContainsFunc(field.value, unicode.IsControl) { + return status.Errorf(codes.InvalidArgument, "photo %s must not contain control characters", field.name) + } + } + for _, field := range []struct { + name string + value *float64 + }{ + {"f_number", photo.FNumber}, + {"exposure_time_seconds", photo.ExposureTimeSeconds}, + {"focal_length_mm", photo.FocalLengthMm}, + } { + if field.value != nil && (!isFinite(*field.value) || *field.value <= 0) { + return status.Errorf(codes.InvalidArgument, "photo %s must be a finite positive number", field.name) + } + } + if photo.Iso != nil && *photo.Iso <= 0 { + return status.Errorf(codes.InvalidArgument, "photo iso must be positive") + } + if err := validateMediaCaptureTime(photo.CaptureTime); err != nil { + return err + } + return validateMediaLocation(photo.Location) +} + +func validateMediaCaptureTime(captureTime *v1pb.MediaCaptureTime) error { + if captureTime == nil { + return nil + } + if !mediaLocalDateTimePattern.MatchString(captureTime.LocalDateTime) { + return status.Errorf(codes.InvalidArgument, "capture_time local_date_time has an invalid format") + } + parsed, err := time.Parse("2006-01-02T15:04:05", captureTime.LocalDateTime) + if err != nil || parsed.Year() == 0 { + return status.Errorf(codes.InvalidArgument, "capture_time local_date_time is invalid") + } + if captureTime.UtcOffset == nil { + return nil + } + if *captureTime.UtcOffset == "Z" { + return nil + } + match := mediaUTCOffsetPattern.FindStringSubmatch(*captureTime.UtcOffset) + if match == nil { + return status.Errorf(codes.InvalidArgument, "capture_time utc_offset has an invalid format") + } + hours, _ := strconv.Atoi(match[1]) + minutes, _ := strconv.Atoi(match[2]) + if hours > 14 || minutes > 59 || (hours == 14 && minutes != 0) { + return status.Errorf(codes.InvalidArgument, "capture_time utc_offset is outside the supported range") + } + return nil +} + +func validateMediaLocation(location *v1pb.MediaLocation) error { + if location == nil { + return nil + } + if location.Latitude == nil || location.Longitude == nil { + return status.Errorf(codes.InvalidArgument, "location latitude and longitude must be provided together") + } + if !isFinite(*location.Latitude) || *location.Latitude < -90 || *location.Latitude > 90 { + return status.Errorf(codes.InvalidArgument, "location latitude must be between -90 and 90") + } + if !isFinite(*location.Longitude) || *location.Longitude < -180 || *location.Longitude > 180 { + return status.Errorf(codes.InvalidArgument, "location longitude must be between -180 and 180") + } + if location.AltitudeMeters != nil && !isFinite(*location.AltitudeMeters) { + return status.Errorf(codes.InvalidArgument, "location altitude_meters must be finite") + } + return nil +} + +func isFinite(value float64) bool { + return !math.IsNaN(value) && !math.IsInf(value, 0) +} + +// transcodeProto copies src into dst through the wire format. The API and +// store MediaMetadata message trees are declared field-for-field identical, so +// the round-trip is the entire conversion; unknown fields (e.g. from a newer +// client) are dropped rather than stored. +func transcodeProto(src, dst proto.Message) error { + data, err := proto.Marshal(src) + if err != nil { + return errors.Wrap(err, "failed to marshal source protobuf") + } + if err := (proto.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(data, dst); err != nil { + return errors.Wrap(err, "failed to unmarshal destination protobuf") + } + return nil +} + +func convertMediaMetadataFromStore(metadata *storepb.MediaMetadata) *v1pb.MediaMetadata { + if metadata == nil { + return nil + } + apiMetadata := &v1pb.MediaMetadata{} + if err := transcodeProto(metadata, apiMetadata); err != nil { + return nil + } + return apiMetadata +} diff --git a/server/router/api/v1/attachment_media_metadata_test.go b/server/router/api/v1/attachment_media_metadata_test.go new file mode 100644 index 00000000..431a06c4 --- /dev/null +++ b/server/router/api/v1/attachment_media_metadata_test.go @@ -0,0 +1,123 @@ +package v1 + +import ( + "math" + "strings" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + + v1pb "github.com/usememos/memos/proto/gen/api/v1" +) + +func TestValidateClientMediaMetadata(t *testing.T) { + t.Parallel() + + validPhoto := func() *v1pb.MediaMetadata { + return &v1pb.MediaMetadata{ + Width: proto.Int32(4032), + Height: proto.Int32(3024), + Details: &v1pb.MediaMetadata_Photo{Photo: &v1pb.PhotoMetadata{ + CaptureTime: &v1pb.MediaCaptureTime{ + LocalDateTime: "2026-08-10T14:32:18.123", + UtcOffset: proto.String("+08:00"), + }, + Location: &v1pb.MediaLocation{ + Latitude: proto.Float64(1.3521), + Longitude: proto.Float64(103.8198), + AltitudeMeters: proto.Float64(18.4), + }, + SourceExifOrientation: proto.Int32(6), + CameraMake: "Apple", + CameraModel: "iPhone", + LensModel: "Main Camera", + FNumber: proto.Float64(1.78), + ExposureTimeSeconds: proto.Float64(1.0 / 120.0), + Iso: proto.Int32(64), + FocalLengthMm: proto.Float64(6.86), + }}, + } + } + + t.Run("accepts photo metadata", func(t *testing.T) { + metadata, err := validateClientMediaMetadata(validPhoto(), "image/jpeg") + require.NoError(t, err) + require.Equal(t, int32(4032), metadata.GetWidth()) + require.Equal(t, "Apple", metadata.GetPhoto().GetCameraMake()) + }) + + t.Run("accepts dimensions without details", func(t *testing.T) { + metadata, err := validateClientMediaMetadata(&v1pb.MediaMetadata{ + Width: proto.Int32(1920), Height: proto.Int32(1080), + }, "video/mp4") + require.NoError(t, err) + require.Equal(t, int32(1920), metadata.GetWidth()) + }) + + t.Run("accepts video metadata", func(t *testing.T) { + metadata, err := validateClientMediaMetadata(&v1pb.MediaMetadata{ + Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{DurationSeconds: proto.Float64(12.5)}}, + }, "video/mp4") + require.NoError(t, err) + require.Equal(t, 12.5, metadata.GetVideo().GetDurationSeconds()) + }) + + t.Run("accepts uppercase MIME type", func(t *testing.T) { + metadata, err := validateClientMediaMetadata(validPhoto(), "IMAGE/JPEG") + require.NoError(t, err) + require.Equal(t, "Apple", metadata.GetPhoto().GetCameraMake()) + }) + + t.Run("accepts Z UTC offset", func(t *testing.T) { + metadata, err := validateClientMediaMetadata(photoOnly(&v1pb.PhotoMetadata{ + CaptureTime: &v1pb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: proto.String("Z")}, + }), "image/jpeg") + require.NoError(t, err) + require.Equal(t, "Z", metadata.GetPhoto().GetCaptureTime().GetUtcOffset()) + }) + + tests := []struct { + name string + mimeType string + metadata *v1pb.MediaMetadata + }{ + {name: "empty", mimeType: "image/jpeg", metadata: &v1pb.MediaMetadata{}}, + {name: "non-media MIME", mimeType: "application/pdf", metadata: validPhoto()}, + {name: "width without height", mimeType: "image/jpeg", metadata: &v1pb.MediaMetadata{Width: proto.Int32(100)}}, + {name: "non-positive dimension", mimeType: "image/jpeg", metadata: &v1pb.MediaMetadata{Width: proto.Int32(0), Height: proto.Int32(100)}}, + {name: "photo on video", mimeType: "video/mp4", metadata: validPhoto()}, + {name: "empty photo", mimeType: "image/jpeg", metadata: &v1pb.MediaMetadata{Details: &v1pb.MediaMetadata_Photo{Photo: &v1pb.PhotoMetadata{}}}}, + {name: "video on image", mimeType: "image/jpeg", metadata: &v1pb.MediaMetadata{Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{DurationSeconds: proto.Float64(1)}}}}, + {name: "empty video", mimeType: "video/mp4", metadata: &v1pb.MediaMetadata{Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{}}}}, + {name: "invalid source EXIF orientation", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{SourceExifOrientation: proto.Int32(9)})}, + {name: "blank camera make", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CameraMake: " "})}, + {name: "control character in camera make", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CameraMake: "Apple\nCo"})}, + {name: "null byte in lens model", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{LensModel: "Main\x00Camera"})}, + {name: "long camera model", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CameraModel: strings.Repeat("x", maxMediaMetadataStringBytes+1)})}, + {name: "non-finite aperture", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{FNumber: proto.Float64(math.NaN())})}, + {name: "zero exposure", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{ExposureTimeSeconds: proto.Float64(0)})}, + {name: "zero ISO", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{Iso: proto.Int32(0)})}, + {name: "invalid capture format", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CaptureTime: &v1pb.MediaCaptureTime{LocalDateTime: "2026:08:10 14:32:18"}})}, + {name: "invalid calendar date", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CaptureTime: &v1pb.MediaCaptureTime{LocalDateTime: "2026-02-30T14:32:18"}})}, + {name: "invalid offset", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{CaptureTime: &v1pb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: proto.String("+14:30")}})}, + {name: "missing longitude", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{Location: &v1pb.MediaLocation{Latitude: proto.Float64(1)}})}, + {name: "latitude out of range", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{Location: &v1pb.MediaLocation{Latitude: proto.Float64(91), Longitude: proto.Float64(1)}})}, + {name: "non-finite altitude", mimeType: "image/jpeg", metadata: photoOnly(&v1pb.PhotoMetadata{Location: &v1pb.MediaLocation{Latitude: proto.Float64(1), Longitude: proto.Float64(1), AltitudeMeters: proto.Float64(math.Inf(1))}})}, + {name: "negative duration", mimeType: "video/mp4", metadata: &v1pb.MediaMetadata{Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{DurationSeconds: proto.Float64(-1)}}}}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + _, err := validateClientMediaMetadata(test.metadata, test.mimeType) + require.Error(t, err) + require.Equal(t, codes.InvalidArgument, status.Code(err)) + }) + } +} + +func photoOnly(photo *v1pb.PhotoMetadata) *v1pb.MediaMetadata { + return &v1pb.MediaMetadata{Details: &v1pb.MediaMetadata_Photo{Photo: photo}} +} diff --git a/server/router/api/v1/attachment_service.go b/server/router/api/v1/attachment_service.go index 6602fe70..c56c8684 100644 --- a/server/router/api/v1/attachment_service.go +++ b/server/router/api/v1/attachment_service.go @@ -111,6 +111,14 @@ func (s *APIV1Service) CreateAttachment(ctx context.Context, request *v1pb.Creat create.Payload = ensureAttachmentPayload(create.Payload) create.Payload.MotionMedia = inputMotionMedia } + inputMediaMetadata, err := validateClientMediaMetadata(request.Attachment.MediaMetadata, request.Attachment.Type) + if err != nil { + return nil, err + } + if inputMediaMetadata != nil { + create.Payload = ensureAttachmentPayload(create.Payload) + create.Payload.MediaMetadata = inputMediaMetadata + } instanceStorageSetting, err := s.Store.GetInstanceStorageSetting(ctx) if err != nil { diff --git a/server/router/api/v1/attachment_service_storage.go b/server/router/api/v1/attachment_service_storage.go index a1738e9c..68a3c48c 100644 --- a/server/router/api/v1/attachment_service_storage.go +++ b/server/router/api/v1/attachment_service_storage.go @@ -25,12 +25,13 @@ import ( func convertAttachmentFromStore(attachment *store.Attachment) *v1pb.Attachment { attachmentMessage := &v1pb.Attachment{ - Name: fmt.Sprintf("%s%s", AttachmentNamePrefix, attachment.UID), - CreateTime: timestamppb.New(time.Unix(attachment.CreatedTs, 0)), - Filename: attachment.Filename, - Type: attachment.Type, - Size: attachment.Size, - MotionMedia: convertMotionMediaFromStore(getAttachmentMotionMedia(attachment)), + Name: fmt.Sprintf("%s%s", AttachmentNamePrefix, attachment.UID), + CreateTime: timestamppb.New(time.Unix(attachment.CreatedTs, 0)), + Filename: attachment.Filename, + Type: attachment.Type, + Size: attachment.Size, + MotionMedia: convertMotionMediaFromStore(getAttachmentMotionMedia(attachment)), + MediaMetadata: convertMediaMetadataFromStore(attachment.Payload.GetMediaMetadata()), } if attachment.MemoUID != nil && *attachment.MemoUID != "" { memoName := fmt.Sprintf("%s%s", MemoNamePrefix, *attachment.MemoUID) diff --git a/server/router/api/v1/gateway_marshaler_test.go b/server/router/api/v1/gateway_marshaler_test.go index 2df8a646..420f50d2 100644 --- a/server/router/api/v1/gateway_marshaler_test.go +++ b/server/router/api/v1/gateway_marshaler_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" v1pb "github.com/usememos/memos/proto/gen/api/v1" @@ -28,6 +29,7 @@ func TestGatewayMarshalerOmitsUnsetMessageFields(t *testing.T) { payload := marshalThroughGateway(t, attachment) require.NotContains(t, payload, "motionMedia", "an unset message field must be omitted, not emitted as null") + require.NotContains(t, payload, "mediaMetadata", "an unset message field must be omitted, not emitted as null") // Scalar defaults stay in the payload: the schema lists filename and type as // required, so dropping unpopulated scalars would break validation instead. require.Equal(t, "", payload["externalLink"]) @@ -36,6 +38,52 @@ func TestGatewayMarshalerOmitsUnsetMessageFields(t *testing.T) { require.Equal(t, "0", payload["size"]) } +func TestGatewayMarshalerKeepsMediaMetadataFieldNames(t *testing.T) { + attachment := &v1pb.Attachment{ + Name: "attachments/video1", + Filename: "clip.mp4", + Type: "video/mp4", + MediaMetadata: &v1pb.MediaMetadata{ + Width: proto.Int32(1920), + Height: proto.Int32(1080), + Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{ + DurationSeconds: proto.Float64(12.5), + }}, + }, + } + + payload := marshalThroughGateway(t, attachment) + + metadata, ok := payload["mediaMetadata"].(map[string]any) + require.True(t, ok) + require.Equal(t, float64(1920), metadata["width"]) + video, ok := metadata["video"].(map[string]any) + require.True(t, ok) + require.Equal(t, 12.5, video["durationSeconds"]) +} + +func TestGatewayMarshalerNamesSourceExifOrientationExplicitly(t *testing.T) { + attachment := &v1pb.Attachment{ + Name: "attachments/photo1", + Filename: "photo.jpg", + Type: "image/jpeg", + MediaMetadata: &v1pb.MediaMetadata{ + Details: &v1pb.MediaMetadata_Photo{Photo: &v1pb.PhotoMetadata{ + SourceExifOrientation: proto.Int32(6), + }}, + }, + } + + payload := marshalThroughGateway(t, attachment) + + metadata, ok := payload["mediaMetadata"].(map[string]any) + require.True(t, ok) + photo, ok := metadata["photo"].(map[string]any) + require.True(t, ok) + require.Equal(t, float64(6), photo["sourceExifOrientation"]) + require.NotContains(t, photo, "orientation") +} + func TestGatewayMarshalerKeepsPopulatedMessageFields(t *testing.T) { attachment := &v1pb.Attachment{ Name: "attachments/livephoto1", diff --git a/server/router/api/v1/test/attachment_service_test.go b/server/router/api/v1/test/attachment_service_test.go index 7e32554b..0a348630 100644 --- a/server/router/api/v1/test/attachment_service_test.go +++ b/server/router/api/v1/test/attachment_service_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" "github.com/usememos/memos/internal/testutil" v1pb "github.com/usememos/memos/proto/gen/api/v1" @@ -342,6 +343,112 @@ func TestCreateAttachmentMotionMedia(t *testing.T) { }) } +func TestCreateAttachmentMediaMetadata(t *testing.T) { + ts := NewTestService(t) + defer ts.Cleanup() + ctx := context.Background() + + user, err := ts.CreateRegularUser(ctx, "media_metadata_user") + require.NoError(t, err) + userCtx := ts.CreateUserContext(ctx, user.ID) + + photoMetadata := &v1pb.MediaMetadata{ + Width: proto.Int32(20), + Height: proto.Int32(10), + Details: &v1pb.MediaMetadata_Photo{Photo: &v1pb.PhotoMetadata{ + CaptureTime: &v1pb.MediaCaptureTime{ + LocalDateTime: "2026-08-10T14:32:18.123", + UtcOffset: proto.String("+08:00"), + }, + Location: &v1pb.MediaLocation{ + Latitude: proto.Float64(1.3521), + Longitude: proto.Float64(103.8198), + AltitudeMeters: proto.Float64(18.4), + }, + SourceExifOrientation: proto.Int32(6), + CameraMake: "Apple", + CameraModel: "iPhone", + LensModel: "Main Camera", + FNumber: proto.Float64(1.78), + ExposureTimeSeconds: proto.Float64(1.0 / 120.0), + Iso: proto.Int32(64), + FocalLengthMm: proto.Float64(6.86), + }}, + } + + photo, err := ts.Service.CreateAttachment(userCtx, &v1pb.CreateAttachmentRequest{ + Attachment: &v1pb.Attachment{ + Filename: "photo.jpg", + Type: "image/jpeg", + Content: testutil.BuildJPEG(20, 10), + MediaMetadata: photoMetadata, + }, + }) + require.NoError(t, err) + require.True(t, proto.Equal(photoMetadata, photo.MediaMetadata)) + + photoUID, err := apiv1.ExtractAttachmentUIDFromName(photo.Name) + require.NoError(t, err) + storedPhoto, err := ts.Store.GetAttachment(ctx, &store.FindAttachment{UID: &photoUID}) + require.NoError(t, err) + require.NotNil(t, storedPhoto.Payload.GetMediaMetadata()) + require.Equal(t, "Apple", storedPhoto.Payload.GetMediaMetadata().GetPhoto().GetCameraMake()) + require.Equal(t, int32(6), storedPhoto.Payload.GetMediaMetadata().GetPhoto().GetSourceExifOrientation()) + + gotPhoto, err := ts.Service.GetAttachment(userCtx, &v1pb.GetAttachmentRequest{Name: photo.Name}) + require.NoError(t, err) + require.True(t, proto.Equal(photoMetadata, gotPhoto.MediaMetadata)) + + listed, err := ts.Service.ListAttachments(userCtx, &v1pb.ListAttachmentsRequest{PageSize: 100}) + require.NoError(t, err) + var listedPhoto *v1pb.Attachment + for _, attachment := range listed.Attachments { + if attachment.Name == photo.Name { + listedPhoto = attachment + break + } + } + require.NotNil(t, listedPhoto) + require.True(t, proto.Equal(photoMetadata, listedPhoto.MediaMetadata)) + + memo, err := ts.Service.CreateMemo(userCtx, &v1pb.CreateMemoRequest{Memo: &v1pb.Memo{ + Content: "memo with metadata", + Visibility: v1pb.Visibility_PRIVATE, + Attachments: []*v1pb.Attachment{{Name: photo.Name}}, + }}) + require.NoError(t, err) + require.Len(t, memo.Attachments, 1) + require.True(t, proto.Equal(photoMetadata, memo.Attachments[0].MediaMetadata)) + + video, err := ts.Service.CreateAttachment(userCtx, &v1pb.CreateAttachmentRequest{ + Attachment: &v1pb.Attachment{ + Filename: "clip.mp4", + Type: "video/mp4", + Content: []byte("fake-video"), + MediaMetadata: &v1pb.MediaMetadata{ + Width: proto.Int32(1920), + Height: proto.Int32(1080), + Details: &v1pb.MediaMetadata_Video{Video: &v1pb.VideoMetadata{ + DurationSeconds: proto.Float64(12.5), + }}, + }, + }, + }) + require.NoError(t, err) + require.Equal(t, 12.5, video.MediaMetadata.GetVideo().GetDurationSeconds()) + + withoutMetadata, err := ts.Service.CreateAttachment(userCtx, &v1pb.CreateAttachmentRequest{ + Attachment: &v1pb.Attachment{Filename: "plain.png", Type: "image/png", Content: []byte("fake-png")}, + }) + require.NoError(t, err) + require.Nil(t, withoutMetadata.MediaMetadata) + plainUID, err := apiv1.ExtractAttachmentUIDFromName(withoutMetadata.Name) + require.NoError(t, err) + storedPlain, err := ts.Store.GetAttachment(ctx, &store.FindAttachment{UID: &plainUID}) + require.NoError(t, err) + require.Nil(t, storedPlain.Payload.GetMediaMetadata()) +} + func TestBatchDeleteAttachments(t *testing.T) { ts := NewTestService(t) defer ts.Cleanup() diff --git a/server/router/api/v1/test/user_setting_test.go b/server/router/api/v1/test/user_setting_test.go index 0036bf06..b2761e9a 100644 --- a/server/router/api/v1/test/user_setting_test.go +++ b/server/router/api/v1/test/user_setting_test.go @@ -59,6 +59,60 @@ func TestListUserSettingsOmitsInternalStoreSettings(t *testing.T) { require.Equal(t, "ja", resp.Settings[0].GetGeneralSetting().Locale) } +func TestGeneralUserSettingSaveMediaMetadata(t *testing.T) { + ctx := context.Background() + ts := NewTestService(t) + defer ts.Cleanup() + + user, err := ts.CreateRegularUser(ctx, "media-setting-user") + require.NoError(t, err) + userCtx := ts.CreateUserContext(ctx, user.ID) + settingName := "users/media-setting-user/settings/GENERAL" + + defaultSetting, err := ts.Service.GetUserSetting(userCtx, &apiv1.GetUserSettingRequest{Name: settingName}) + require.NoError(t, err) + require.False(t, defaultSetting.GetGeneralSetting().GetSaveMediaMetadata()) + + updated, err := ts.Service.UpdateUserSetting(userCtx, &apiv1.UpdateUserSettingRequest{ + Setting: &apiv1.UserSetting{ + Name: settingName, + Value: &apiv1.UserSetting_GeneralSetting_{ + GeneralSetting: &apiv1.UserSetting_GeneralSetting{SaveMediaMetadata: true}, + }, + }, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"save_media_metadata"}}, + }) + require.NoError(t, err) + require.True(t, updated.GetGeneralSetting().GetSaveMediaMetadata()) + require.Equal(t, "en", updated.GetGeneralSetting().GetLocale()) + require.Equal(t, "PRIVATE", updated.GetGeneralSetting().GetMemoVisibility()) + + updated, err = ts.Service.UpdateUserSetting(userCtx, &apiv1.UpdateUserSettingRequest{ + Setting: &apiv1.UserSetting{ + Name: settingName, + Value: &apiv1.UserSetting_GeneralSetting_{ + GeneralSetting: &apiv1.UserSetting_GeneralSetting{Locale: "ja"}, + }, + }, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"locale"}}, + }) + require.NoError(t, err) + require.Equal(t, "ja", updated.GetGeneralSetting().GetLocale()) + require.True(t, updated.GetGeneralSetting().GetSaveMediaMetadata()) + + updated, err = ts.Service.UpdateUserSetting(userCtx, &apiv1.UpdateUserSettingRequest{ + Setting: &apiv1.UserSetting{ + Name: settingName, + Value: &apiv1.UserSetting_GeneralSetting_{ + GeneralSetting: &apiv1.UserSetting_GeneralSetting{SaveMediaMetadata: false}, + }, + }, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"save_media_metadata"}}, + }) + require.NoError(t, err) + require.False(t, updated.GetGeneralSetting().GetSaveMediaMetadata()) +} + func TestUserTagSettings(t *testing.T) { ctx := context.Background() ts := NewTestService(t) diff --git a/server/router/api/v1/user_service_converters.go b/server/router/api/v1/user_service_converters.go index eb5c2dc4..f1470ec9 100644 --- a/server/router/api/v1/user_service_converters.go +++ b/server/router/api/v1/user_service_converters.go @@ -187,9 +187,10 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, user *store. if general := storeSetting.GetGeneral(); general != nil { setting.Value = &v1pb.UserSetting_GeneralSetting_{ GeneralSetting: &v1pb.UserSetting_GeneralSetting{ - Locale: general.Locale, - MemoVisibility: general.MemoVisibility, - Theme: general.Theme, + Locale: general.Locale, + MemoVisibility: general.MemoVisibility, + Theme: general.Theme, + SaveMediaMetadata: general.SaveMediaMetadata, }, } } else { @@ -240,9 +241,10 @@ func convertUserSettingToStore(apiSetting *v1pb.UserSetting, userID int32, key s if general := apiSetting.GetGeneralSetting(); general != nil { storeSetting.Value = &storepb.UserSetting_General{ General: &storepb.GeneralUserSetting{ - Locale: general.Locale, - MemoVisibility: general.MemoVisibility, - Theme: general.Theme, + Locale: general.Locale, + MemoVisibility: general.MemoVisibility, + Theme: general.Theme, + SaveMediaMetadata: general.SaveMediaMetadata, }, } } else { diff --git a/server/router/api/v1/user_service_settings.go b/server/router/api/v1/user_service_settings.go index ec6bf2f2..e659cfa1 100644 --- a/server/router/api/v1/user_service_settings.go +++ b/server/router/api/v1/user_service_settings.go @@ -84,22 +84,17 @@ func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.Upda var updatedSetting *v1pb.UserSetting switch storeKey { case storepb.UserSetting_GENERAL: - existingUserSetting, _ := s.Store.GetUserSetting(ctx, &store.FindUserSetting{ + existingUserSetting, err := s.Store.GetUserSetting(ctx, &store.FindUserSetting{ UserID: &userID, Key: storeKey, }) - - generalSetting := &storepb.GeneralUserSetting{} - if existingUserSetting != nil { - // Start with existing general setting values. - generalSetting = existingUserSetting.GetGeneral() + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get existing general setting: %v", err) } - updatedGeneral := &v1pb.UserSetting_GeneralSetting{ - MemoVisibility: generalSetting.GetMemoVisibility(), - Locale: generalSetting.GetLocale(), - Theme: generalSetting.GetTheme(), - } + // Seed the merge from the shared store→API converter, which already falls + // back to defaults when the setting (or its general value) is missing. + updatedGeneral := convertUserSettingFromStore(existingUserSetting, user, storeKey).GetGeneralSetting() incomingGeneral := request.Setting.GetGeneralSetting() if incomingGeneral == nil { @@ -113,6 +108,8 @@ func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.Upda updatedGeneral.Theme = incomingGeneral.Theme case "locale": updatedGeneral.Locale = incomingGeneral.Locale + case "save_media_metadata": + updatedGeneral.SaveMediaMetadata = incomingGeneral.SaveMediaMetadata default: // Ignore unsupported fields. } diff --git a/store/test/attachment_test.go b/store/test/attachment_test.go index 0b85c2c0..829983d3 100644 --- a/store/test/attachment_test.go +++ b/store/test/attachment_test.go @@ -8,6 +8,7 @@ import ( "github.com/lithammer/shortuuid/v4" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" storepb "github.com/usememos/memos/proto/gen/store" "github.com/usememos/memos/store" @@ -81,6 +82,24 @@ func TestAttachmentStore(t *testing.T) { Blob: []byte("test"), Type: "application/epub+zip", Size: 637607, + Payload: &storepb.AttachmentPayload{ + Payload: &storepb.AttachmentPayload_S3Object_{ + S3Object: &storepb.AttachmentPayload_S3Object{Key: "attachments/test.jpg"}, + }, + MotionMedia: &storepb.MotionMedia{ + Family: storepb.MotionMediaFamily_APPLE_LIVE_PHOTO, + Role: storepb.MotionMediaRole_STILL, + GroupId: "live-photo-pair", + }, + MediaMetadata: &storepb.MediaMetadata{ + Width: proto.Int32(1200), + Height: proto.Int32(800), + Details: &storepb.MediaMetadata_Photo{Photo: &storepb.PhotoMetadata{ + CameraMake: "Test Camera", + SourceExifOrientation: proto.Int32(6), + }}, + }, + }, }) require.NoError(t, err) @@ -92,6 +111,11 @@ func TestAttachmentStore(t *testing.T) { require.NoError(t, err) require.Equal(t, correctFilename, attachment.Filename) require.Equal(t, int32(1), attachment.ID) + require.Equal(t, int32(1200), attachment.Payload.GetMediaMetadata().GetWidth()) + require.Equal(t, "Test Camera", attachment.Payload.GetMediaMetadata().GetPhoto().GetCameraMake()) + require.Equal(t, int32(6), attachment.Payload.GetMediaMetadata().GetPhoto().GetSourceExifOrientation()) + require.Equal(t, "attachments/test.jpg", attachment.Payload.GetS3Object().GetKey()) + require.Equal(t, "live-photo-pair", attachment.Payload.GetMotionMedia().GetGroupId()) notFoundAttachment, err := ts.GetAttachment(ctx, &store.FindAttachment{ Filename: &incorrectFilename, diff --git a/web/package.json b/web/package.json index 4256b68b..a07731e0 100644 --- a/web/package.json +++ b/web/package.json @@ -36,6 +36,7 @@ "clsx": "^2.1.1", "copy-to-clipboard": "^4.0.2", "dayjs": "^1.11.20", + "exifr": "^7.1.3", "highlight.js": "^11.11.1", "html-to-image": "^1.11.13", "i18next": "^26.3.6", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 7d92b97f..46d2c7a0 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: dayjs: specifier: ^1.11.20 version: 1.11.20 + exifr: + specifier: ^7.1.3 + version: 7.1.3 highlight.js: specifier: ^11.11.1 version: 11.11.1 @@ -1572,6 +1575,9 @@ packages: estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + exifr@7.1.3: + resolution: {integrity: sha512-g/aje2noHivrRSLbAUtBPWFbxKdKhgj/xr1vATDdUXPOFYJlQ62Ft0oy+72V6XLIpDJfHs6gXLbBLAolqOXYRw==} + expect-type@1.3.0: resolution: {integrity: sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==} engines: {node: '>=12.0.0'} @@ -3817,6 +3823,8 @@ snapshots: dependencies: '@types/estree': 1.0.8 + exifr@7.1.3: {} + expect-type@1.3.0: {} extend@3.0.2: {} diff --git a/web/src/components/AttachmentIcon.tsx b/web/src/components/AttachmentIcon.tsx index 3b8f8f29..43d90c54 100644 --- a/web/src/components/AttachmentIcon.tsx +++ b/web/src/components/AttachmentIcon.tsx @@ -24,9 +24,8 @@ interface Props { const AttachmentIcon = (props: Props) => { const { attachment } = props; - const [previewImage, setPreviewImage] = useState<{ open: boolean; urls: string[]; index: number }>({ + const [previewImage, setPreviewImage] = useState<{ open: boolean; index: number }>({ open: false, - urls: [], index: 0, }); const resourceType = getAttachmentType(attachment); @@ -39,7 +38,7 @@ const AttachmentIcon = (props: Props) => { }; const handleImageClick = () => { - setPreviewImage({ open: true, urls: [attachmentUrl], index: 0 }); + setPreviewImage({ open: true, index: 0 }); }; if (resourceType === "image/*") { @@ -66,7 +65,16 @@ const AttachmentIcon = (props: Props) => { setPreviewImage((prev) => ({ ...prev, open }))} - imgUrls={previewImage.urls} + items={[ + { + id: attachment.name, + kind: "image", + sourceUrl: attachmentUrl, + posterUrl: getAttachmentThumbnailUrl(attachment), + filename: attachment.filename, + attachments: [attachment], + }, + ]} initialIndex={previewImage.index} /> diff --git a/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx b/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx index 6c7463cc..3e6c572a 100644 --- a/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx +++ b/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx @@ -3,7 +3,9 @@ import MotionPhotoPreview from "@/components/MotionPhotoPreview"; import { Badge } from "@/components/ui/badge"; import VideoPoster from "@/components/VideoPoster"; import type { AttachmentLibraryMediaItem, AttachmentLibraryMonthGroup } from "@/hooks/useAttachmentLibrary"; +import { cn } from "@/lib/utils"; import { useTranslate } from "@/utils/i18n"; +import { formatMediaDuration } from "@/utils/media-metadata"; import { AttachmentMetadataLine, AttachmentOpenButton, AttachmentSourceChip } from "./AttachmentLibraryPrimitives"; interface AttachmentMediaGridProps { @@ -13,6 +15,8 @@ interface AttachmentMediaGridProps { const AttachmentMediaCard = ({ item, onPreview }: { item: AttachmentLibraryMediaItem; onPreview: () => void }) => { const t = useTranslate(); + const videoDuration = item.attachments.map((attachment) => attachment.mediaMetadata?.details).find((details) => details?.case === "video") + ?.value.durationSeconds; return (
@@ -27,8 +31,14 @@ const AttachmentMediaCard = ({ item, onPreview }: { item: AttachmentLibraryMedia className="h-full w-full object-cover" />
- + + {videoDuration !== undefined && {formatMediaDuration(videoDuration)}} ) : item.kind === "motion" ? ( diff --git a/web/src/components/MediaMetadataDetails.tsx b/web/src/components/MediaMetadataDetails.tsx new file mode 100644 index 00000000..a5a013c1 --- /dev/null +++ b/web/src/components/MediaMetadataDetails.tsx @@ -0,0 +1,246 @@ +import { + ApertureIcon, + CalendarArrowUpIcon, + CalendarClockIcon, + CameraIcon, + CheckIcon, + CopyIcon, + FileType2Icon, + FocusIcon, + type LucideIcon, + MapIcon, + MapPinIcon, + RotateCwIcon, + ScanIcon, + TimerIcon, + XIcon, +} from "lucide-react"; +import { type ReactNode, useEffect, useMemo, useRef, useState } from "react"; +import { LazyLocationPicker } from "@/components/map/LazyLocationPicker"; +import { Button } from "@/components/ui/button"; +import i18n from "@/i18n"; +import { cn } from "@/lib/utils"; +import { useTranslate } from "@/utils/i18n"; +import type { PreviewMediaItem } from "@/utils/media-item"; +import { buildMediaMetadataDisplay } from "@/utils/media-metadata"; + +interface DetailRowProps { + icon: LucideIcon; + label: string; + value: string; + secondary?: string; + action?: ReactNode; +} + +interface MediaMetadataDetailsProps { + id: string; + item: PreviewMediaItem; + onClose: () => void; + className?: string; +} + +const DetailRow = ({ icon: Icon, label, value, secondary, action }: DetailRowProps) => ( +
+
+); + +const DetailSection = ({ title, children }: { title: string; children: ReactNode }) => ( +
+

{title}

+
{children}
+
+); + +const IconAction = ({ label, onClick, children }: { label: string; onClick: () => void; children: ReactNode }) => ( + +); + +const MediaMetadataDetails = ({ id, item, onClose, className }: MediaMetadataDetailsProps) => { + const t = useTranslate(); + const [showMap, setShowMap] = useState(false); + const [coordinatesCopied, setCoordinatesCopied] = useState(false); + const copyResetTimer = useRef(undefined); + const locale = i18n.language; + const details = useMemo(() => buildMediaMetadataDisplay(item.attachments, locale), [item.attachments, locale]); + + useEffect(() => { + setShowMap(false); + setCoordinatesCopied(false); + }, [item.id]); + + useEffect( + () => () => { + if (copyResetTimer.current !== undefined) { + window.clearTimeout(copyResetTimer.current); + } + }, + [], + ); + + const copyCoordinates = async () => { + if (!details.location || !navigator.clipboard) { + return; + } + try { + await navigator.clipboard.writeText(`${details.location.latitude}, ${details.location.longitude}`); + } catch { + return; + } + setCoordinatesCopied(true); + if (copyResetTimer.current !== undefined) { + window.clearTimeout(copyResetTimer.current); + } + copyResetTimer.current = window.setTimeout(() => setCoordinatesCopied(false), 1600); + }; + + const hasFileDetails = Boolean(details.file || details.dimensions || details.duration || details.uploaded); + const hasCaptureDetails = Boolean(details.captured); + const hasCameraDetails = Boolean(details.camera || details.lens || details.exposure); + + return ( + + ); +}; + +export default MediaMetadataDetails; diff --git a/web/src/components/MemoEditor/hooks/index.ts b/web/src/components/MemoEditor/hooks/index.ts index aa76e428..86623fab 100644 --- a/web/src/components/MemoEditor/hooks/index.ts +++ b/web/src/components/MemoEditor/hooks/index.ts @@ -6,7 +6,7 @@ export { useAutoSave } from "./useAutoSave"; export { useBlobUrls } from "./useBlobUrls"; export { useEditorActiveState } from "./useEditorActiveState"; export { COMPACT_TOOLBAR_WIDTH, isCompactWidth, useElementWidth } from "./useElementWidth"; -export { pairAppleLivePhotoFiles, useFileUpload } from "./useFileUpload"; +export { pairAppleLivePhotoFiles, toLocalFiles, useFileUpload } from "./useFileUpload"; export { useFocusMode } from "./useFocusMode"; export { splitInlineLocalFiles, useInlineImageUpload } from "./useInlineImageUpload"; export { useLinkMemo } from "./useLinkMemo"; diff --git a/web/src/components/MemoEditor/hooks/useFileUpload.ts b/web/src/components/MemoEditor/hooks/useFileUpload.ts index 5a03210e..12650e0b 100644 --- a/web/src/components/MemoEditor/hooks/useFileUpload.ts +++ b/web/src/components/MemoEditor/hooks/useFileUpload.ts @@ -1,15 +1,34 @@ import { create } from "@bufbuild/protobuf"; import { useRef } from "react"; +import { useAuth } from "@/contexts/AuthContext"; import { type MotionMedia, MotionMediaFamily, MotionMediaRole, MotionMediaSchema } from "@/types/proto/api/v1/attachment_service_pb"; +import { mediaMetadataService } from "../services/mediaMetadataService"; import type { LocalFile } from "../types/attachment"; import { useBlobUrls } from "./useBlobUrls"; +/** + * Single ingest point turning picked/pasted/dropped Files into LocalFiles. + * Media metadata extraction starts here (not at upload time) so every upload + * path inherits the preference from the LocalFile instead of threading it. + */ +export const toLocalFiles = (files: File[], options: { createBlobUrl: (file: File) => string; saveMediaMetadata: boolean }): LocalFile[] => + pairAppleLivePhotoFiles( + files.map((file) => ({ + file, + previewUrl: options.createBlobUrl(file), + origin: "upload", + mediaMetadata: options.saveMediaMetadata ? mediaMetadataService.extract(file) : undefined, + })), + ); + export const useFileUpload = (onFilesSelected: (localFiles: LocalFile[]) => void) => { const fileInputRef = useRef(null); const selectingFlagRef = useRef(false); // Track preview blob URLs so they're revoked on unmount instead of leaking // (matches the paste/drop/audio paths, which all go through useBlobUrls). const { createBlobUrl } = useBlobUrls(); + const { userGeneralSetting } = useAuth(); + const saveMediaMetadata = userGeneralSetting?.saveMediaMetadata ?? false; const handleFileInputChange = (event?: React.ChangeEvent) => { const files = Array.from(fileInputRef.current?.files || event?.target.files || []); @@ -17,13 +36,7 @@ export const useFileUpload = (onFilesSelected: (localFiles: LocalFile[]) => void return; } selectingFlagRef.current = true; - const localFiles: LocalFile[] = pairAppleLivePhotoFiles( - files.map((file) => ({ - file, - previewUrl: createBlobUrl(file), - origin: "upload", - })), - ); + const localFiles = toLocalFiles(files, { createBlobUrl, saveMediaMetadata }); onFilesSelected(localFiles); selectingFlagRef.current = false; // Optionally clear input value to allow re-selecting the same file diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index 15678007..dda23126 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -11,8 +11,8 @@ import { convertVisibilityFromString } from "@/utils/memo"; import { AudioRecorderPanel, EditorContent, EditorMetadata, FocusModeOverlay, TimestampPopover } from "./components"; import { FOCUS_MODE_STYLES, FORMATTING_TOOLBAR_STORAGE_KEY } from "./constants"; import { - pairAppleLivePhotoFiles, splitInlineLocalFiles, + toLocalFiles, useAudioRecorder, useAutoSave, useBlobUrls, @@ -60,6 +60,7 @@ const MemoEditorImpl: React.FC = ({ const [isAudioRecorderOpen, setIsAudioRecorderOpen] = useState(false); const [isTranscribingAudio, setIsTranscribingAudio] = useState(false); const { createBlobUrl } = useBlobUrls(); + const saveMediaMetadata = userGeneralSetting?.saveMediaMetadata ?? false; const inlineImageUpload = useInlineImageUpload(editorRef); // Persisted preference: also show the formatting toolbar in normal mode. Focus // mode always shows it regardless; this only governs the non-focus layout. @@ -232,27 +233,15 @@ const MemoEditorImpl: React.FC = ({ void handleStartAudioRecording(); }; - const toLocalFiles = useCallback( - (files: File[]): LocalFile[] => - pairAppleLivePhotoFiles( - files.map((file) => ({ - file, - previewUrl: createBlobUrl(file), - origin: "upload", - })), - ), - [createBlobUrl], - ); - /** Shared by the + menu (no position) and by editor paste/drop (drop position). */ const handleInsertImages = useCallback( (files: File[], position?: number) => { if (getState().ui.isLoading.saving) return; - const { inline, attachments } = splitInlineLocalFiles(toLocalFiles(files)); + const { inline, attachments } = splitInlineLocalFiles(toLocalFiles(files, { createBlobUrl, saveMediaMetadata })); attachments.forEach((file) => dispatch(actions.addLocalFile(file))); inlineImageUpload.insertLocalImages(inline, position); }, - [actions, dispatch, getState, inlineImageUpload.insertLocalImages, toLocalFiles], + [actions, createBlobUrl, dispatch, getState, inlineImageUpload.insertLocalImages, saveMediaMetadata], ); const handleCancelAudioRecording = () => { diff --git a/web/src/components/MemoEditor/services/cacheService.ts b/web/src/components/MemoEditor/services/cacheService.ts index 8a4733b9..92bd0585 100644 --- a/web/src/components/MemoEditor/services/cacheService.ts +++ b/web/src/components/MemoEditor/services/cacheService.ts @@ -4,7 +4,7 @@ import { AttachmentSchema } from "@/types/proto/api/v1/attachment_service_pb"; export const CACHE_DEBOUNCE_DELAY = 500; -const pendingSaves = new Map>(); +const pendingSaves = new Map(); const cursors = new Map(); const STRUCTURED_CACHE_ENTRY_KIND = "memos.editor-cache"; const STRUCTURED_CACHE_ENTRY_VERSION = 2; diff --git a/web/src/components/MemoEditor/services/mediaMetadataService.ts b/web/src/components/MemoEditor/services/mediaMetadataService.ts new file mode 100644 index 00000000..71890543 --- /dev/null +++ b/web/src/components/MemoEditor/services/mediaMetadataService.ts @@ -0,0 +1,352 @@ +import { create } from "@bufbuild/protobuf"; +import { + MediaCaptureTimeSchema, + MediaLocationSchema, + type MediaMetadata, + MediaMetadataSchema, + PhotoMetadataSchema, + VideoMetadataSchema, +} from "@/types/proto/api/v1/attachment_service_pb"; +import { isImage } from "@/utils/attachment"; + +const EXTRACTION_TIMEOUT_MS = 5_000; +const MAX_METADATA_STRING_BYTES = 256; +const EXIF_TAGS = [ + "Make", + "Model", + "Orientation", + "ImageWidth", + "ImageHeight", + "ExifImageWidth", + "ExifImageHeight", + "DateTimeOriginal", + "CreateDate", + "SubSecTimeOriginal", + "SubSecTimeDigitized", + "OffsetTimeOriginal", + "OffsetTimeDigitized", + "GPSLatitudeRef", + "GPSLatitude", + "GPSLongitudeRef", + "GPSLongitude", + "GPSAltitudeRef", + "GPSAltitude", + "LensModel", + "FNumber", + "ExposureTime", + "ISO", + "FocalLength", +]; +const EXIF_PARSE_OPTIONS = { + pick: EXIF_TAGS, + translateValues: false, + reviveValues: false, + makerNote: false, + userComment: false, + xmp: false, + icc: false, + iptc: false, + jfif: false, + ihdr: false, + ifd1: false, +}; + +const textEncoder = new TextEncoder(); + +type ExifTags = Record; +type Dimensions = { width: number; height: number }; + +export const mediaMetadataService = { + async extract(file: File): Promise { + try { + if (isImage(file.type)) { + return await extractImageMetadata(file); + } + if (file.type.startsWith("video/")) { + return await extractVideoMetadata(file); + } + } catch { + warnExtractionFailure(); + } + return undefined; + }, +}; + +async function extractImageMetadata(file: File): Promise { + let tags: ExifTags = {}; + try { + tags = await readExifTags(file); + } catch { + warnExtractionFailure(); + } + + const sourceExifOrientation = normalizeInteger(tags.Orientation, 1, 8); + // EXIF dimensions come from a cheap header read; decode the image only when they are absent. + const dimensions = readExifDimensions(tags, sourceExifOrientation) ?? (await readImageDimensions(file)); + + const photoFields = { + captureTime: readCaptureTime(tags), + location: readLocation(tags), + sourceExifOrientation, + cameraMake: normalizeMetadataString(tags.Make), + cameraModel: normalizeMetadataString(tags.Model), + lensModel: normalizeMetadataString(tags.LensModel), + fNumber: normalizePositiveNumber(tags.FNumber), + exposureTimeSeconds: normalizePositiveNumber(tags.ExposureTime), + iso: normalizeInteger(tags.ISO, 1), + focalLengthMm: normalizePositiveNumber(tags.FocalLength), + }; + const hasPhotoDetails = Object.values(photoFields).some((value) => value !== undefined); + + if (!dimensions && !hasPhotoDetails) { + return undefined; + } + + return create(MediaMetadataSchema, { + width: dimensions?.width, + height: dimensions?.height, + details: hasPhotoDetails ? { case: "photo", value: create(PhotoMetadataSchema, photoFields) } : { case: undefined }, + }); +} + +async function readExifTags(file: File): Promise { + const exifr = await import("exifr"); + const parsed = await withTimeout(exifr.parse(file, EXIF_PARSE_OPTIONS), EXTRACTION_TIMEOUT_MS); + return parsed && typeof parsed === "object" ? (parsed as ExifTags) : {}; +} + +function readExifDimensions(tags: ExifTags, orientation: number | undefined): Dimensions | undefined { + const width = normalizeInteger(tags.ExifImageWidth ?? tags.ImageWidth, 1); + const height = normalizeInteger(tags.ExifImageHeight ?? tags.ImageHeight, 1); + if (width === undefined || height === undefined) { + return undefined; + } + if (orientation !== undefined && orientation >= 5) { + return { width: height, height: width }; + } + return { width, height }; +} + +async function readImageDimensions(file: File): Promise { + if (typeof createImageBitmap !== "function") { + return undefined; + } + const bitmapPromise = createImageBitmap(file); + try { + const bitmap = await withTimeout(bitmapPromise, EXTRACTION_TIMEOUT_MS); + const dimensions = normalizeDimensions(bitmap.width, bitmap.height); + bitmap.close(); + return dimensions; + } catch { + void bitmapPromise.then((bitmap) => bitmap.close()).catch(() => undefined); + return undefined; + } +} + +async function extractVideoMetadata(file: File): Promise { + const { dimensions, durationSeconds } = await readVideoMetadata(file); + if (!dimensions && durationSeconds === undefined) { + return undefined; + } + + return create(MediaMetadataSchema, { + width: dimensions?.width, + height: dimensions?.height, + details: + durationSeconds === undefined ? { case: undefined } : { case: "video", value: create(VideoMetadataSchema, { durationSeconds }) }, + }); +} + +async function readVideoMetadata(file: File): Promise<{ dimensions?: Dimensions; durationSeconds?: number }> { + return await new Promise((resolve, reject) => { + const url = URL.createObjectURL(file); + const video = document.createElement("video"); + video.preload = "metadata"; + + const cleanup = () => { + window.clearTimeout(timeout); + video.removeEventListener("loadedmetadata", handleLoadedMetadata); + video.removeEventListener("error", fail); + video.removeAttribute("src"); + video.load(); + URL.revokeObjectURL(url); + }; + const fail = () => { + cleanup(); + reject(new Error("video metadata extraction failed")); + }; + const handleLoadedMetadata = () => { + const dimensions = normalizeDimensions(video.videoWidth, video.videoHeight); + const durationSeconds = Number.isFinite(video.duration) && video.duration >= 0 ? video.duration : undefined; + cleanup(); + resolve({ dimensions, durationSeconds }); + }; + const timeout = window.setTimeout(fail, EXTRACTION_TIMEOUT_MS); + + video.addEventListener("loadedmetadata", handleLoadedMetadata); + video.addEventListener("error", fail); + video.src = url; + video.load(); + }); +} + +function readCaptureTime(tags: ExifTags) { + return ( + normalizeCaptureTime(tags.DateTimeOriginal, tags.SubSecTimeOriginal, tags.OffsetTimeOriginal) ?? + normalizeCaptureTime(tags.CreateDate, tags.SubSecTimeDigitized, tags.OffsetTimeDigitized) + ); +} + +function normalizeCaptureTime(dateValue: unknown, subsecondValue: unknown, offsetValue: unknown) { + if (typeof dateValue !== "string") { + return undefined; + } + const match = cleanExifString(dateValue).match(/^(\d{4}):(\d{2}):(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/); + if (!match) { + return undefined; + } + const [, yearText, monthText, dayText, hourText, minuteText, secondText] = match; + if (!Number(yearText)) { + return undefined; + } + const base = `${yearText}-${monthText}-${dayText}T${hourText}:${minuteText}:${secondText}`; + // Round-trip through Date to reject impossible calendar dates: an invalid + // component either yields NaN or rolls over so the ISO form no longer matches. + const parsed = new Date(`${base}Z`); + if (Number.isNaN(parsed.getTime()) || !parsed.toISOString().startsWith(base)) { + return undefined; + } + + const cleanedSubseconds = typeof subsecondValue === "string" ? cleanExifString(subsecondValue) : ""; + const subseconds = /^\d{1,9}$/.test(cleanedSubseconds) ? cleanedSubseconds : undefined; + const localDateTime = subseconds ? `${base}.${subseconds}` : base; + const utcOffset = normalizeUTCOffset(offsetValue); + return create(MediaCaptureTimeSchema, { localDateTime, utcOffset }); +} + +function normalizeUTCOffset(value: unknown): string | undefined { + if (typeof value !== "string") { + return undefined; + } + const offset = cleanExifString(value); + if (offset === "Z") { + return offset; + } + const match = offset.match(/^[+-](\d{2}):(\d{2})$/); + if (!match) { + return undefined; + } + const hours = Number(match[1]); + const minutes = Number(match[2]); + return hours <= 14 && minutes <= 59 && (hours !== 14 || minutes === 0) ? offset : undefined; +} + +function readLocation(tags: ExifTags) { + const latitude = normalizeCoordinate(tags.latitude, tags.GPSLatitude, tags.GPSLatitudeRef, 90, "N", "S"); + const longitude = normalizeCoordinate(tags.longitude, tags.GPSLongitude, tags.GPSLongitudeRef, 180, "E", "W"); + if (latitude === undefined || longitude === undefined) { + return undefined; + } + const rawAltitude = normalizeFiniteNumber(tags.GPSAltitude); + const altitudeRef = normalizeFiniteNumber(tags.GPSAltitudeRef); + const altitudeMeters = rawAltitude === undefined ? undefined : altitudeRef === 1 ? -rawAltitude : rawAltitude; + return create(MediaLocationSchema, { latitude, longitude, altitudeMeters }); +} + +function normalizeCoordinate( + computed: unknown, + dms: unknown, + ref: unknown, + maximum: number, + positiveRef: string, + negativeRef: string, +): number | undefined { + const computedNumber = normalizeFiniteNumber(computed); + if (computedNumber !== undefined && computedNumber >= -maximum && computedNumber <= maximum) { + return computedNumber; + } + const direction = typeof ref === "string" ? cleanExifString(ref).toUpperCase() : ""; + if (!Array.isArray(dms) || dms.length < 3 || (direction !== positiveRef && direction !== negativeRef)) { + return undefined; + } + const degrees = normalizeFiniteNumber(dms[0]); + const minutes = normalizeFiniteNumber(dms[1]); + const seconds = normalizeFiniteNumber(dms[2]); + if ( + degrees === undefined || + minutes === undefined || + seconds === undefined || + degrees < 0 || + minutes < 0 || + minutes >= 60 || + seconds < 0 || + seconds >= 60 + ) { + return undefined; + } + const sign = direction === negativeRef ? -1 : 1; + const result = sign * (degrees + minutes / 60 + seconds / 3600); + return result >= -maximum && result <= maximum ? result : undefined; +} + +function normalizeMetadataString(value: unknown): string | undefined { + if (typeof value !== "string") { + return undefined; + } + // Strip Unicode Cc control characters to match server-side validation. + const normalized = value.replace(/\p{Cc}/gu, "").trim(); + if (!normalized || normalized.length > MAX_METADATA_STRING_BYTES) { + return undefined; + } + return textEncoder.encode(normalized).byteLength > MAX_METADATA_STRING_BYTES ? undefined : normalized; +} + +function cleanExifString(value: string): string { + return value.replace(/[\0\s]+$/g, "").trimStart(); +} + +function normalizeFiniteNumber(value: unknown): number | undefined { + if (typeof value === "number") { + return Number.isFinite(value) ? value : undefined; + } + if (Array.isArray(value) || value instanceof Uint8Array) { + return normalizeFiniteNumber(value[0]); + } + return undefined; +} + +function normalizePositiveNumber(value: unknown): number | undefined { + const number = normalizeFiniteNumber(value); + return number !== undefined && number > 0 ? number : undefined; +} + +function normalizeInteger(value: unknown, minimum: number, maximum = Number.MAX_SAFE_INTEGER): number | undefined { + const number = normalizeFiniteNumber(value); + return number !== undefined && Number.isInteger(number) && number >= minimum && number <= maximum ? number : undefined; +} + +function normalizeDimensions(width: number, height: number): Dimensions | undefined { + return Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0 ? { width, height } : undefined; +} + +async function withTimeout(promise: Promise, timeoutMs: number): Promise { + let timeout: number | undefined; + try { + return await Promise.race([ + promise, + new Promise((_, reject) => { + timeout = window.setTimeout(() => reject(new Error("media metadata extraction timed out")), timeoutMs); + }), + ]); + } finally { + if (timeout !== undefined) { + window.clearTimeout(timeout); + } + } +} + +function warnExtractionFailure() { + if (import.meta.env.DEV) { + console.warn("Media metadata extraction failed; continuing without metadata."); + } +} diff --git a/web/src/components/MemoEditor/services/uploadService.ts b/web/src/components/MemoEditor/services/uploadService.ts index 1d4880c3..9063b56f 100644 --- a/web/src/components/MemoEditor/services/uploadService.ts +++ b/web/src/components/MemoEditor/services/uploadService.ts @@ -7,7 +7,8 @@ import type { LocalFile } from "../types/attachment"; export const uploadService = { async uploadFile(localFile: LocalFile): Promise { const { file, motionMedia } = localFile; - const buffer = new Uint8Array(await file.arrayBuffer()); + const [mediaMetadata, arrayBuffer] = await Promise.all([localFile.mediaMetadata, file.arrayBuffer()]); + const buffer = new Uint8Array(arrayBuffer); return attachmentServiceClient.createAttachment({ attachment: create(AttachmentSchema, { filename: file.name, @@ -15,6 +16,7 @@ export const uploadService = { type: file.type, content: buffer, motionMedia: motionMedia ? create(MotionMediaSchema, motionMedia) : undefined, + mediaMetadata, }), }); }, diff --git a/web/src/components/MemoEditor/types/attachment.ts b/web/src/components/MemoEditor/types/attachment.ts index 2cb0d675..d947ba00 100644 --- a/web/src/components/MemoEditor/types/attachment.ts +++ b/web/src/components/MemoEditor/types/attachment.ts @@ -1,4 +1,4 @@ -import type { Attachment, MotionMedia } from "@/types/proto/api/v1/attachment_service_pb"; +import type { Attachment, MediaMetadata, MotionMedia } from "@/types/proto/api/v1/attachment_service_pb"; import { MotionMediaFamily, MotionMediaRole } from "@/types/proto/api/v1/attachment_service_pb"; import { getAttachmentThumbnailUrl, getAttachmentType, getAttachmentUrl } from "@/utils/attachment"; import { buildAttachmentVisualItems } from "@/utils/media-item"; @@ -27,6 +27,12 @@ export interface LocalFile { readonly durationSeconds: number; }; readonly motionMedia?: MotionMedia; + /** + * Extraction started at file ingest when the user's save-media-metadata + * preference was on; absent means the preference was off (or the file came + * from a source with nothing to extract). The promise never rejects. + */ + readonly mediaMetadata?: Promise; } const AUDIO_RECORDING_FILENAME_RE = /^(?:voice-(?:recording|note)|audio-recording)-(\d{8})-(\d{4,6})/i; diff --git a/web/src/components/MemoMetadata/Attachment/AttachmentListEditor.tsx b/web/src/components/MemoMetadata/Attachment/AttachmentListEditor.tsx index 6c396110..6de5eed6 100644 --- a/web/src/components/MemoMetadata/Attachment/AttachmentListEditor.tsx +++ b/web/src/components/MemoMetadata/Attachment/AttachmentListEditor.tsx @@ -282,24 +282,46 @@ const AttachmentListEditor: FC = ({ const previewItems = useMemo( () => items.reduce((acc, item) => { + const itemAttachments = item.isLocal ? undefined : collectMembers(attachmentsByName, item.memberIds); if (item.category === "image") { - acc.push({ id: item.id, kind: "image", sourceUrl: item.sourceUrl, posterUrl: item.thumbnailUrl, filename: item.filename }); + acc.push({ + id: item.id, + kind: "image", + sourceUrl: item.sourceUrl, + posterUrl: item.thumbnailUrl, + filename: item.filename, + attachments: itemAttachments, + }); return acc; } if (item.category === "video") { - acc.push({ id: item.id, kind: "video", sourceUrl: item.sourceUrl, posterUrl: item.thumbnailUrl, filename: item.filename }); + acc.push({ + id: item.id, + kind: "video", + sourceUrl: item.sourceUrl, + posterUrl: item.thumbnailUrl, + filename: item.filename, + attachments: itemAttachments, + }); return acc; } if (item.category === "motion") { - acc.push({ id: item.id, kind: "motion", motionUrl: item.sourceUrl, posterUrl: item.thumbnailUrl, filename: item.filename }); + acc.push({ + id: item.id, + kind: "motion", + motionUrl: item.sourceUrl, + posterUrl: item.thumbnailUrl, + filename: item.filename, + attachments: itemAttachments, + }); return acc; } return acc; }, []), - [items], + [attachmentsByName, items], ); // Items address their members by id, so index once instead of re-scanning both diff --git a/web/src/components/PreviewImageDialog.tsx b/web/src/components/PreviewImageDialog.tsx index 684fcee3..e87a9821 100644 --- a/web/src/components/PreviewImageDialog.tsx +++ b/web/src/components/PreviewImageDialog.tsx @@ -1,11 +1,13 @@ -import { ChevronLeft, ChevronRight, RotateCcw, X, ZoomIn, ZoomOut } from "lucide-react"; +import { ChevronLeft, ChevronRight, InfoIcon, RotateCcw, X, ZoomIn, ZoomOut } from "lucide-react"; import React, { useEffect, useMemo, useState } from "react"; +import MediaMetadataDetails from "@/components/MediaMetadataDetails"; import MotionPhotoPreview from "@/components/MotionPhotoPreview"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; import { VisuallyHidden } from "@/components/ui/visually-hidden"; import useMediaQuery from "@/hooks/useMediaQuery"; import { cn } from "@/lib/utils"; +import { useTranslate } from "@/utils/i18n"; import type { PreviewMediaItem } from "@/utils/media-item"; interface Props { @@ -24,9 +26,11 @@ const DOUBLE_TAP_ZOOM = 2; const clampZoom = (scale: number) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, scale)); function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIndex = 0 }: Props) { + const t = useTranslate(); const sm = useMediaQuery("sm"); const [currentIndex, setCurrentIndex] = useState(initialIndex); const [zoomScale, setZoomScale] = useState(MIN_ZOOM); + const [showDetails, setShowDetails] = useState(false); const previewItems = useMemo( () => items ?? imgUrls.map((url) => ({ id: url, kind: "image" as const, sourceUrl: url, posterUrl: url, filename: "Image" })), [imgUrls, items], @@ -35,6 +39,7 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn useEffect(() => { if (open) { setCurrentIndex(initialIndex); + setShowDetails(false); } }, [initialIndex, open]); @@ -54,11 +59,6 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn return; } - if (event.key === "Escape") { - onOpenChange(false); - return; - } - if (event.key === "ArrowLeft") { setCurrentIndex((prev) => Math.max(prev - 1, 0)); return; @@ -71,7 +71,7 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); - }, [itemCount, onOpenChange, open]); + }, [itemCount, open]); useEffect(() => { setZoomScale(MIN_ZOOM); @@ -104,7 +104,17 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn } return ( - + { + if (!nextOpen && showDetails && eventDetails.reason === "escape-key") { + eventDetails.cancel(); + setShowDetails(false); + return; + } + onOpenChange(nextOpen); + }} + > -
+
{currentItem.filename || "Attachment"}
@@ -128,16 +143,30 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn )}
- +
+ + +
@@ -146,11 +175,16 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn className={cn( "flex h-full w-full items-center justify-center px-3 pb-20 pt-16 sm:px-16 sm:pb-8 sm:pt-20", isImagePreview && "cursor-zoom-in", + showDetails && "lg:pr-[26rem]", )} onWheel={handleWheel} onClick={(event) => { if (event.target === event.currentTarget && !isZoomed) { - handleClose(); + if (showDetails) { + setShowDetails(false); + } else { + handleClose(); + } } }} > @@ -160,7 +194,10 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn key={currentItem.id} src={currentItem.sourceUrl} poster={currentItem.posterUrl} - className="max-h-[calc(100vh-8rem)] max-w-[calc(100vw-1.5rem)] rounded-md object-contain sm:max-h-[calc(100vh-7rem)] sm:max-w-[calc(100vw-8rem)]" + className={cn( + "max-h-[calc(100vh-8rem)] max-w-[calc(100vw-1.5rem)] rounded-md object-contain sm:max-h-[calc(100vh-7rem)] sm:max-w-[calc(100vw-8rem)]", + showDetails && "lg:max-w-[calc(100vw-30rem)]", + )} controls autoPlay playsInline @@ -173,13 +210,19 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn alt={`Preview live photo ${safeIndex + 1} of ${itemCount}`} presentationTimestampUs={currentItem.presentationTimestampUs} badgeClassName="left-3 top-3 sm:left-4 sm:top-4" - mediaClassName="max-h-[calc(100vh-8rem)] max-w-[calc(100vw-1.5rem)] rounded-md object-contain sm:max-h-[calc(100vh-7rem)] sm:max-w-[calc(100vw-8rem)]" + mediaClassName={cn( + "max-h-[calc(100vh-8rem)] max-w-[calc(100vw-1.5rem)] rounded-md object-contain sm:max-h-[calc(100vh-7rem)] sm:max-w-[calc(100vw-8rem)]", + showDetails && "lg:max-w-[calc(100vw-30rem)]", + )} /> ) : ( {`Preview {isImagePreview && ( -
+
{hasMultiple && !sm && ( <> @@ -241,11 +284,12 @@ function PreviewImageDialog({ open, onOpenChange, imgUrls = [], items, initialIn label="Next item" onClick={handleNext} icon={} + detailsOpen={showDetails} /> )} - {hasMultiple && !sm && !isImagePreview && ( + {hasMultiple && !sm && !isImagePreview && !showDetails && (
)} + + {showDetails && setShowDetails(false)} />}
); @@ -285,9 +331,10 @@ interface NavButtonProps { label: string; onClick: () => void; icon: React.ReactNode; + detailsOpen?: boolean; } -const NavButton = ({ side, disabled, label, onClick, icon }: NavButtonProps) => ( +const NavButton = ({ side, disabled, label, onClick, icon, detailsOpen = false }: NavButtonProps) => (