diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index 4a7d516a9d..fc733c15cd 100644 --- a/mobile/openapi/README.md +++ b/mobile/openapi/README.md @@ -341,6 +341,7 @@ Class | Method | HTTP request | Description - [AssetMetadataUpsertItemDto](doc//AssetMetadataUpsertItemDto.md) - [AssetOrder](doc//AssetOrder.md) - [AssetResponseDto](doc//AssetResponseDto.md) + - [AssetSearchResponseDto](doc//AssetSearchResponseDto.md) - [AssetStackResponseDto](doc//AssetStackResponseDto.md) - [AssetStatsResponseDto](doc//AssetStatsResponseDto.md) - [AssetTypeEnum](doc//AssetTypeEnum.md) diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index df2c2226b1..526066dee7 100644 --- a/mobile/openapi/lib/api.dart +++ b/mobile/openapi/lib/api.dart @@ -112,6 +112,7 @@ part 'model/asset_metadata_upsert_dto.dart'; part 'model/asset_metadata_upsert_item_dto.dart'; part 'model/asset_order.dart'; part 'model/asset_response_dto.dart'; +part 'model/asset_search_response_dto.dart'; part 'model/asset_stack_response_dto.dart'; part 'model/asset_stats_response_dto.dart'; part 'model/asset_type_enum.dart'; diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index 06d27593c9..4434e062f1 100644 --- a/mobile/openapi/lib/api_client.dart +++ b/mobile/openapi/lib/api_client.dart @@ -278,6 +278,8 @@ class ApiClient { return AssetOrderTypeTransformer().decode(value); case 'AssetResponseDto': return AssetResponseDto.fromJson(value); + case 'AssetSearchResponseDto': + return AssetSearchResponseDto.fromJson(value); case 'AssetStackResponseDto': return AssetStackResponseDto.fromJson(value); case 'AssetStatsResponseDto': diff --git a/mobile/openapi/lib/model/asset_search_response_dto.dart b/mobile/openapi/lib/model/asset_search_response_dto.dart new file mode 100644 index 0000000000..62eb6ad431 --- /dev/null +++ b/mobile/openapi/lib/model/asset_search_response_dto.dart @@ -0,0 +1,421 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.18 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: constant_identifier_names +// ignore_for_file: lines_longer_than_80_chars + +part of openapi.api; + +class AssetSearchResponseDto { + /// Returns a new [AssetSearchResponseDto] instance. + AssetSearchResponseDto({ + required this.checksum, + required this.createdAt, + required this.deviceAssetId, + required this.deviceId, + this.distance, + this.duplicateId, + required this.duration, + this.exifInfo, + required this.fileCreatedAt, + required this.fileModifiedAt, + required this.hasMetadata, + required this.id, + required this.isArchived, + required this.isFavorite, + required this.isOffline, + required this.isTrashed, + this.libraryId, + this.livePhotoVideoId, + required this.localDateTime, + required this.originalFileName, + this.originalMimeType, + required this.originalPath, + this.owner, + required this.ownerId, + this.people = const [], + this.resized, + this.stack, + this.tags = const [], + required this.thumbhash, + required this.type, + this.unassignedFaces = const [], + required this.updatedAt, + required this.visibility, + }); + + /// base64 encoded sha1 hash + String checksum; + + /// The UTC timestamp when the asset was originally uploaded to Immich. + DateTime createdAt; + + String deviceAssetId; + + String deviceId; + + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + num? distance; + + String? duplicateId; + + String duration; + + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + ExifResponseDto? exifInfo; + + /// The actual UTC timestamp when the file was created/captured, preserving timezone information. This is the authoritative timestamp for chronological sorting within timeline groups. Combined with timezone data, this can be used to determine the exact moment the photo was taken. + DateTime fileCreatedAt; + + /// The UTC timestamp when the file was last modified on the filesystem. This reflects the last time the physical file was changed, which may be different from when the photo was originally taken. + DateTime fileModifiedAt; + + bool hasMetadata; + + String id; + + bool isArchived; + + bool isFavorite; + + bool isOffline; + + bool isTrashed; + + /// This property was deprecated in v1.106.0 + String? libraryId; + + String? livePhotoVideoId; + + /// The local date and time when the photo/video was taken, derived from EXIF metadata. This represents the photographer's local time regardless of timezone, stored as a timezone-agnostic timestamp. Used for timeline grouping by \"local\" days and months. + DateTime localDateTime; + + String originalFileName; + + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + String? originalMimeType; + + String originalPath; + + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + UserResponseDto? owner; + + String ownerId; + + List people; + + /// This property was deprecated in v1.113.0 + /// + /// Please note: This property should have been non-nullable! Since the specification file + /// does not include a default value (using the "default:" property), however, the generated + /// source code must fall back to having a nullable type. + /// Consider adding a "default:" property in the specification file to hide this note. + /// + bool? resized; + + AssetStackResponseDto? stack; + + List tags; + + String? thumbhash; + + AssetTypeEnum type; + + List unassignedFaces; + + /// The UTC timestamp when the asset record was last updated in the database. This is automatically maintained by the database and reflects when any field in the asset was last modified. + DateTime updatedAt; + + AssetVisibility visibility; + + @override + bool operator ==(Object other) => identical(this, other) || other is AssetSearchResponseDto && + other.checksum == checksum && + other.createdAt == createdAt && + other.deviceAssetId == deviceAssetId && + other.deviceId == deviceId && + other.distance == distance && + other.duplicateId == duplicateId && + other.duration == duration && + other.exifInfo == exifInfo && + other.fileCreatedAt == fileCreatedAt && + other.fileModifiedAt == fileModifiedAt && + other.hasMetadata == hasMetadata && + other.id == id && + other.isArchived == isArchived && + other.isFavorite == isFavorite && + other.isOffline == isOffline && + other.isTrashed == isTrashed && + other.libraryId == libraryId && + other.livePhotoVideoId == livePhotoVideoId && + other.localDateTime == localDateTime && + other.originalFileName == originalFileName && + other.originalMimeType == originalMimeType && + other.originalPath == originalPath && + other.owner == owner && + other.ownerId == ownerId && + _deepEquality.equals(other.people, people) && + other.resized == resized && + other.stack == stack && + _deepEquality.equals(other.tags, tags) && + other.thumbhash == thumbhash && + other.type == type && + _deepEquality.equals(other.unassignedFaces, unassignedFaces) && + other.updatedAt == updatedAt && + other.visibility == visibility; + + @override + int get hashCode => + // ignore: unnecessary_parenthesis + (checksum.hashCode) + + (createdAt.hashCode) + + (deviceAssetId.hashCode) + + (deviceId.hashCode) + + (distance == null ? 0 : distance!.hashCode) + + (duplicateId == null ? 0 : duplicateId!.hashCode) + + (duration.hashCode) + + (exifInfo == null ? 0 : exifInfo!.hashCode) + + (fileCreatedAt.hashCode) + + (fileModifiedAt.hashCode) + + (hasMetadata.hashCode) + + (id.hashCode) + + (isArchived.hashCode) + + (isFavorite.hashCode) + + (isOffline.hashCode) + + (isTrashed.hashCode) + + (libraryId == null ? 0 : libraryId!.hashCode) + + (livePhotoVideoId == null ? 0 : livePhotoVideoId!.hashCode) + + (localDateTime.hashCode) + + (originalFileName.hashCode) + + (originalMimeType == null ? 0 : originalMimeType!.hashCode) + + (originalPath.hashCode) + + (owner == null ? 0 : owner!.hashCode) + + (ownerId.hashCode) + + (people.hashCode) + + (resized == null ? 0 : resized!.hashCode) + + (stack == null ? 0 : stack!.hashCode) + + (tags.hashCode) + + (thumbhash == null ? 0 : thumbhash!.hashCode) + + (type.hashCode) + + (unassignedFaces.hashCode) + + (updatedAt.hashCode) + + (visibility.hashCode); + + @override + String toString() => 'AssetSearchResponseDto[checksum=$checksum, createdAt=$createdAt, deviceAssetId=$deviceAssetId, deviceId=$deviceId, distance=$distance, duplicateId=$duplicateId, duration=$duration, exifInfo=$exifInfo, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, hasMetadata=$hasMetadata, id=$id, isArchived=$isArchived, isFavorite=$isFavorite, isOffline=$isOffline, isTrashed=$isTrashed, libraryId=$libraryId, livePhotoVideoId=$livePhotoVideoId, localDateTime=$localDateTime, originalFileName=$originalFileName, originalMimeType=$originalMimeType, originalPath=$originalPath, owner=$owner, ownerId=$ownerId, people=$people, resized=$resized, stack=$stack, tags=$tags, thumbhash=$thumbhash, type=$type, unassignedFaces=$unassignedFaces, updatedAt=$updatedAt, visibility=$visibility]'; + + Map toJson() { + final json = {}; + json[r'checksum'] = this.checksum; + json[r'createdAt'] = this.createdAt.toUtc().toIso8601String(); + json[r'deviceAssetId'] = this.deviceAssetId; + json[r'deviceId'] = this.deviceId; + if (this.distance != null) { + json[r'distance'] = this.distance; + } else { + // json[r'distance'] = null; + } + if (this.duplicateId != null) { + json[r'duplicateId'] = this.duplicateId; + } else { + // json[r'duplicateId'] = null; + } + json[r'duration'] = this.duration; + if (this.exifInfo != null) { + json[r'exifInfo'] = this.exifInfo; + } else { + // json[r'exifInfo'] = null; + } + json[r'fileCreatedAt'] = this.fileCreatedAt.toUtc().toIso8601String(); + json[r'fileModifiedAt'] = this.fileModifiedAt.toUtc().toIso8601String(); + json[r'hasMetadata'] = this.hasMetadata; + json[r'id'] = this.id; + json[r'isArchived'] = this.isArchived; + json[r'isFavorite'] = this.isFavorite; + json[r'isOffline'] = this.isOffline; + json[r'isTrashed'] = this.isTrashed; + if (this.libraryId != null) { + json[r'libraryId'] = this.libraryId; + } else { + // json[r'libraryId'] = null; + } + if (this.livePhotoVideoId != null) { + json[r'livePhotoVideoId'] = this.livePhotoVideoId; + } else { + // json[r'livePhotoVideoId'] = null; + } + json[r'localDateTime'] = this.localDateTime.toUtc().toIso8601String(); + json[r'originalFileName'] = this.originalFileName; + if (this.originalMimeType != null) { + json[r'originalMimeType'] = this.originalMimeType; + } else { + // json[r'originalMimeType'] = null; + } + json[r'originalPath'] = this.originalPath; + if (this.owner != null) { + json[r'owner'] = this.owner; + } else { + // json[r'owner'] = null; + } + json[r'ownerId'] = this.ownerId; + json[r'people'] = this.people; + if (this.resized != null) { + json[r'resized'] = this.resized; + } else { + // json[r'resized'] = null; + } + if (this.stack != null) { + json[r'stack'] = this.stack; + } else { + // json[r'stack'] = null; + } + json[r'tags'] = this.tags; + if (this.thumbhash != null) { + json[r'thumbhash'] = this.thumbhash; + } else { + // json[r'thumbhash'] = null; + } + json[r'type'] = this.type; + json[r'unassignedFaces'] = this.unassignedFaces; + json[r'updatedAt'] = this.updatedAt.toUtc().toIso8601String(); + json[r'visibility'] = this.visibility; + return json; + } + + /// Returns a new [AssetSearchResponseDto] instance and imports its values from + /// [value] if it's a [Map], null otherwise. + // ignore: prefer_constructors_over_static_methods + static AssetSearchResponseDto? fromJson(dynamic value) { + upgradeDto(value, "AssetSearchResponseDto"); + if (value is Map) { + final json = value.cast(); + + return AssetSearchResponseDto( + checksum: mapValueOfType(json, r'checksum')!, + createdAt: mapDateTime(json, r'createdAt', r'')!, + deviceAssetId: mapValueOfType(json, r'deviceAssetId')!, + deviceId: mapValueOfType(json, r'deviceId')!, + distance: num.parse('${json[r'distance']}'), + duplicateId: mapValueOfType(json, r'duplicateId'), + duration: mapValueOfType(json, r'duration')!, + exifInfo: ExifResponseDto.fromJson(json[r'exifInfo']), + fileCreatedAt: mapDateTime(json, r'fileCreatedAt', r'')!, + fileModifiedAt: mapDateTime(json, r'fileModifiedAt', r'')!, + hasMetadata: mapValueOfType(json, r'hasMetadata')!, + id: mapValueOfType(json, r'id')!, + isArchived: mapValueOfType(json, r'isArchived')!, + isFavorite: mapValueOfType(json, r'isFavorite')!, + isOffline: mapValueOfType(json, r'isOffline')!, + isTrashed: mapValueOfType(json, r'isTrashed')!, + libraryId: mapValueOfType(json, r'libraryId'), + livePhotoVideoId: mapValueOfType(json, r'livePhotoVideoId'), + localDateTime: mapDateTime(json, r'localDateTime', r'')!, + originalFileName: mapValueOfType(json, r'originalFileName')!, + originalMimeType: mapValueOfType(json, r'originalMimeType'), + originalPath: mapValueOfType(json, r'originalPath')!, + owner: UserResponseDto.fromJson(json[r'owner']), + ownerId: mapValueOfType(json, r'ownerId')!, + people: PersonWithFacesResponseDto.listFromJson(json[r'people']), + resized: mapValueOfType(json, r'resized'), + stack: AssetStackResponseDto.fromJson(json[r'stack']), + tags: TagResponseDto.listFromJson(json[r'tags']), + thumbhash: mapValueOfType(json, r'thumbhash'), + type: AssetTypeEnum.fromJson(json[r'type'])!, + unassignedFaces: AssetFaceWithoutPersonResponseDto.listFromJson(json[r'unassignedFaces']), + updatedAt: mapDateTime(json, r'updatedAt', r'')!, + visibility: AssetVisibility.fromJson(json[r'visibility'])!, + ); + } + return null; + } + + static List listFromJson(dynamic json, {bool growable = false,}) { + final result = []; + if (json is List && json.isNotEmpty) { + for (final row in json) { + final value = AssetSearchResponseDto.fromJson(row); + if (value != null) { + result.add(value); + } + } + } + return result.toList(growable: growable); + } + + static Map mapFromJson(dynamic json) { + final map = {}; + if (json is Map && json.isNotEmpty) { + json = json.cast(); // ignore: parameter_assignments + for (final entry in json.entries) { + final value = AssetSearchResponseDto.fromJson(entry.value); + if (value != null) { + map[entry.key] = value; + } + } + } + return map; + } + + // maps a json object with a list of AssetSearchResponseDto-objects as value to a dart map + static Map> mapListFromJson(dynamic json, {bool growable = false,}) { + final map = >{}; + if (json is Map && json.isNotEmpty) { + // ignore: parameter_assignments + json = json.cast(); + for (final entry in json.entries) { + map[entry.key] = AssetSearchResponseDto.listFromJson(entry.value, growable: growable,); + } + } + return map; + } + + /// The list of required keys that must be present in a JSON. + static const requiredKeys = { + 'checksum', + 'createdAt', + 'deviceAssetId', + 'deviceId', + 'duration', + 'fileCreatedAt', + 'fileModifiedAt', + 'hasMetadata', + 'id', + 'isArchived', + 'isFavorite', + 'isOffline', + 'isTrashed', + 'localDateTime', + 'originalFileName', + 'originalPath', + 'ownerId', + 'thumbhash', + 'type', + 'updatedAt', + 'visibility', + }; +} + diff --git a/mobile/openapi/lib/model/search_asset_response_dto.dart b/mobile/openapi/lib/model/search_asset_response_dto.dart index 3d214e61d9..a7b08f8566 100644 --- a/mobile/openapi/lib/model/search_asset_response_dto.dart +++ b/mobile/openapi/lib/model/search_asset_response_dto.dart @@ -24,7 +24,7 @@ class SearchAssetResponseDto { List facets; - List items; + List items; String? nextPage; @@ -75,7 +75,7 @@ class SearchAssetResponseDto { return SearchAssetResponseDto( count: mapValueOfType(json, r'count')!, facets: SearchFacetResponseDto.listFromJson(json[r'facets']), - items: AssetResponseDto.listFromJson(json[r'items']), + items: AssetSearchResponseDto.listFromJson(json[r'items']), nextPage: mapValueOfType(json, r'nextPage'), total: mapValueOfType(json, r'total')!, ); diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index b574bc6624..88900661a7 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -11220,6 +11220,179 @@ ], "type": "object" }, + "AssetSearchResponseDto": { + "properties": { + "checksum": { + "description": "base64 encoded sha1 hash", + "type": "string" + }, + "createdAt": { + "description": "The UTC timestamp when the asset was originally uploaded to Immich.", + "example": "2024-01-15T20:30:00.000Z", + "format": "date-time", + "type": "string" + }, + "deviceAssetId": { + "type": "string" + }, + "deviceId": { + "type": "string" + }, + "distance": { + "type": "number" + }, + "duplicateId": { + "nullable": true, + "type": "string" + }, + "duration": { + "type": "string" + }, + "exifInfo": { + "$ref": "#/components/schemas/ExifResponseDto" + }, + "fileCreatedAt": { + "description": "The actual UTC timestamp when the file was created/captured, preserving timezone information. This is the authoritative timestamp for chronological sorting within timeline groups. Combined with timezone data, this can be used to determine the exact moment the photo was taken.", + "example": "2024-01-15T19:30:00.000Z", + "format": "date-time", + "type": "string" + }, + "fileModifiedAt": { + "description": "The UTC timestamp when the file was last modified on the filesystem. This reflects the last time the physical file was changed, which may be different from when the photo was originally taken.", + "example": "2024-01-16T10:15:00.000Z", + "format": "date-time", + "type": "string" + }, + "hasMetadata": { + "type": "boolean" + }, + "id": { + "type": "string" + }, + "isArchived": { + "type": "boolean" + }, + "isFavorite": { + "type": "boolean" + }, + "isOffline": { + "type": "boolean" + }, + "isTrashed": { + "type": "boolean" + }, + "libraryId": { + "deprecated": true, + "description": "This property was deprecated in v1.106.0", + "nullable": true, + "type": "string" + }, + "livePhotoVideoId": { + "nullable": true, + "type": "string" + }, + "localDateTime": { + "description": "The local date and time when the photo/video was taken, derived from EXIF metadata. This represents the photographer's local time regardless of timezone, stored as a timezone-agnostic timestamp. Used for timeline grouping by \"local\" days and months.", + "example": "2024-01-15T14:30:00.000Z", + "format": "date-time", + "type": "string" + }, + "originalFileName": { + "type": "string" + }, + "originalMimeType": { + "type": "string" + }, + "originalPath": { + "type": "string" + }, + "owner": { + "$ref": "#/components/schemas/UserResponseDto" + }, + "ownerId": { + "type": "string" + }, + "people": { + "items": { + "$ref": "#/components/schemas/PersonWithFacesResponseDto" + }, + "type": "array" + }, + "resized": { + "deprecated": true, + "description": "This property was deprecated in v1.113.0", + "type": "boolean" + }, + "stack": { + "allOf": [ + { + "$ref": "#/components/schemas/AssetStackResponseDto" + } + ], + "nullable": true + }, + "tags": { + "items": { + "$ref": "#/components/schemas/TagResponseDto" + }, + "type": "array" + }, + "thumbhash": { + "nullable": true, + "type": "string" + }, + "type": { + "allOf": [ + { + "$ref": "#/components/schemas/AssetTypeEnum" + } + ] + }, + "unassignedFaces": { + "items": { + "$ref": "#/components/schemas/AssetFaceWithoutPersonResponseDto" + }, + "type": "array" + }, + "updatedAt": { + "description": "The UTC timestamp when the asset record was last updated in the database. This is automatically maintained by the database and reflects when any field in the asset was last modified.", + "example": "2024-01-16T12:45:30.000Z", + "format": "date-time", + "type": "string" + }, + "visibility": { + "allOf": [ + { + "$ref": "#/components/schemas/AssetVisibility" + } + ] + } + }, + "required": [ + "checksum", + "createdAt", + "deviceAssetId", + "deviceId", + "duration", + "fileCreatedAt", + "fileModifiedAt", + "hasMetadata", + "id", + "isArchived", + "isFavorite", + "isOffline", + "isTrashed", + "localDateTime", + "originalFileName", + "originalPath", + "ownerId", + "thumbhash", + "type", + "updatedAt", + "visibility" + ], + "type": "object" + }, "AssetStackResponseDto": { "properties": { "assetCount": { @@ -13750,7 +13923,7 @@ }, "items": { "items": { - "$ref": "#/components/schemas/AssetResponseDto" + "$ref": "#/components/schemas/AssetSearchResponseDto" }, "type": "array" }, diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index c8a69dfe8c..4dd887d3c6 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -946,10 +946,53 @@ export type SearchAlbumResponseDto = { items: AlbumResponseDto[]; total: number; }; +export type AssetSearchResponseDto = { + /** base64 encoded sha1 hash */ + checksum: string; + /** The UTC timestamp when the asset was originally uploaded to Immich. */ + createdAt: string; + deviceAssetId: string; + deviceId: string; + distance?: number; + duplicateId?: string | null; + duration: string; + exifInfo?: ExifResponseDto; + /** The actual UTC timestamp when the file was created/captured, preserving timezone information. This is the authoritative timestamp for chronological sorting within timeline groups. Combined with timezone data, this can be used to determine the exact moment the photo was taken. */ + fileCreatedAt: string; + /** The UTC timestamp when the file was last modified on the filesystem. This reflects the last time the physical file was changed, which may be different from when the photo was originally taken. */ + fileModifiedAt: string; + hasMetadata: boolean; + id: string; + isArchived: boolean; + isFavorite: boolean; + isOffline: boolean; + isTrashed: boolean; + /** This property was deprecated in v1.106.0 */ + libraryId?: string | null; + livePhotoVideoId?: string | null; + /** The local date and time when the photo/video was taken, derived from EXIF metadata. This represents the photographer's local time regardless of timezone, stored as a timezone-agnostic timestamp. Used for timeline grouping by "local" days and months. */ + localDateTime: string; + originalFileName: string; + originalMimeType?: string; + originalPath: string; + owner?: UserResponseDto; + ownerId: string; + people?: PersonWithFacesResponseDto[]; + /** This property was deprecated in v1.113.0 */ + resized?: boolean; + stack?: (AssetStackResponseDto) | null; + tags?: TagResponseDto[]; + thumbhash: string | null; + "type": AssetTypeEnum; + unassignedFaces?: AssetFaceWithoutPersonResponseDto[]; + /** The UTC timestamp when the asset record was last updated in the database. This is automatically maintained by the database and reflects when any field in the asset was last modified. */ + updatedAt: string; + visibility: AssetVisibility; +}; export type SearchAssetResponseDto = { count: number; facets: SearchFacetResponseDto[]; - items: AssetResponseDto[]; + items: AssetSearchResponseDto[]; nextPage: string | null; total: number; }; diff --git a/server/src/dtos/asset-response.dto.ts b/server/src/dtos/asset-response.dto.ts index f60f2a8824..1f4a4b5c95 100644 --- a/server/src/dtos/asset-response.dto.ts +++ b/server/src/dtos/asset-response.dto.ts @@ -130,6 +130,7 @@ export type MapAsset = { tags?: Tag[]; thumbhash: Buffer | null; type: AssetType; + distance?: number; }; export class AssetStackResponseDto { diff --git a/server/src/dtos/search.dto.ts b/server/src/dtos/search.dto.ts index 5f8b018afe..33e0779836 100644 --- a/server/src/dtos/search.dto.ts +++ b/server/src/dtos/search.dto.ts @@ -296,12 +296,16 @@ class SearchAlbumResponseDto { facets!: SearchFacetResponseDto[]; } +class AssetSearchResponseDto extends AssetResponseDto { + distance?: number; +} + class SearchAssetResponseDto { @ApiProperty({ type: 'integer' }) total!: number; @ApiProperty({ type: 'integer' }) count!: number; - items!: AssetResponseDto[]; + items!: AssetSearchResponseDto[]; facets!: SearchFacetResponseDto[]; nextPage!: string | null; } diff --git a/server/src/repositories/search.repository.ts b/server/src/repositories/search.repository.ts index 88de2fb06f..67c513286d 100644 --- a/server/src/repositories/search.repository.ts +++ b/server/src/repositories/search.repository.ts @@ -284,8 +284,9 @@ export class SearchRepository { await sql`set local vchordrq.probes = ${sql.lit(probes[VectorIndex.Clip])}`.execute(trx); const items = await searchAssetBuilder(trx, options) .selectAll('asset') + .select(sql`smart_search.embedding <=> ${options.embedding}`.as('distance')) .innerJoin('smart_search', 'asset.id', 'smart_search.assetId') - .orderBy(sql`smart_search.embedding <=> ${options.embedding}`) + .orderBy('distance') .limit(pagination.size + 1) .offset((pagination.page - 1) * pagination.size) .execute(); diff --git a/server/src/services/search.service.ts b/server/src/services/search.service.ts index fea1670e27..8e837caa31 100644 --- a/server/src/services/search.service.ts +++ b/server/src/services/search.service.ts @@ -198,7 +198,7 @@ export class SearchService extends BaseService { assets: { total: assets.length, count: assets.length, - items: assets.map((asset) => mapAsset(asset, options)), + items: assets.map((asset) => ({ ...mapAsset(asset, options), distance: asset.distance })), facets: [], nextPage, },