mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
- updated dtos
- added inAlbums to search builder - only check isNotInAlbum if albumIds is blank/empty
This commit is contained in:
@@ -10824,6 +10824,13 @@
|
|||||||
},
|
},
|
||||||
"MetadataSearchDto": {
|
"MetadataSearchDto": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"albumIds": {
|
||||||
|
"items": {
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
"checksum": {
|
"checksum": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -11743,6 +11750,13 @@
|
|||||||
},
|
},
|
||||||
"RandomSearchDto": {
|
"RandomSearchDto": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"albumIds": {
|
||||||
|
"items": {
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
"city": {
|
"city": {
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -12780,6 +12794,13 @@
|
|||||||
},
|
},
|
||||||
"SmartSearchDto": {
|
"SmartSearchDto": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"albumIds": {
|
||||||
|
"items": {
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
"city": {
|
"city": {
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ class BaseSearchDto {
|
|||||||
@ValidateUUID({ each: true, optional: true })
|
@ValidateUUID({ each: true, optional: true })
|
||||||
tagIds?: string[];
|
tagIds?: string[];
|
||||||
|
|
||||||
|
@ValidateUUID({each: true, optional: true})
|
||||||
|
albumIds?: string[];
|
||||||
|
|
||||||
@Optional()
|
@Optional()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@Max(5)
|
@Max(5)
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ export interface SearchTagOptions {
|
|||||||
tagIds?: string[];
|
tagIds?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SearchAlbumOptions {
|
||||||
|
albumIds?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface SearchOrderOptions {
|
export interface SearchOrderOptions {
|
||||||
orderDirection?: 'asc' | 'desc';
|
orderDirection?: 'asc' | 'desc';
|
||||||
}
|
}
|
||||||
@@ -108,7 +112,8 @@ type BaseAssetSearchOptions = SearchDateOptions &
|
|||||||
SearchStatusOptions &
|
SearchStatusOptions &
|
||||||
SearchUserIdOptions &
|
SearchUserIdOptions &
|
||||||
SearchPeopleOptions &
|
SearchPeopleOptions &
|
||||||
SearchTagOptions;
|
SearchTagOptions &
|
||||||
|
SearchAlbumOptions;
|
||||||
|
|
||||||
export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions;
|
export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions;
|
||||||
|
|
||||||
|
|||||||
@@ -228,6 +228,20 @@ export function hasPeople<O>(qb: SelectQueryBuilder<DB, 'assets', O>, personIds:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function inAlbums<O>(qb: SelectQueryBuilder<DB, 'assets', O>, albumIds: string[]) {
|
||||||
|
return qb.innerJoin(
|
||||||
|
(eb) =>
|
||||||
|
eb
|
||||||
|
.selectFrom('albums_assets_assets')
|
||||||
|
.select('assetsId')
|
||||||
|
.where('albumsId', '=', anyUuid(albumIds!))
|
||||||
|
.groupBy('assetsId')
|
||||||
|
.having((eb) => eb.fn.count('albumsId').distinct(), '=', albumIds.length)
|
||||||
|
.as('has_album'),
|
||||||
|
(join) => join.onRef('has_album.assetsId', '=', 'assets.id'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function hasTags<O>(qb: SelectQueryBuilder<DB, 'assets', O>, tagIds: string[]) {
|
export function hasTags<O>(qb: SelectQueryBuilder<DB, 'assets', O>, tagIds: string[]) {
|
||||||
return qb.innerJoin(
|
return qb.innerJoin(
|
||||||
(eb) =>
|
(eb) =>
|
||||||
@@ -293,6 +307,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
|
|||||||
.selectFrom('assets')
|
.selectFrom('assets')
|
||||||
.selectAll('assets')
|
.selectAll('assets')
|
||||||
.where('assets.visibility', '=', visibility)
|
.where('assets.visibility', '=', visibility)
|
||||||
|
.$if(!!options.albumIds && options.albumIds.length > 0, (qb) => inAlbums(qb, options.albumIds!))
|
||||||
.$if(!!options.tagIds && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!))
|
.$if(!!options.tagIds && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!))
|
||||||
.$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!))
|
.$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!))
|
||||||
.$if(!!options.createdBefore, (qb) => qb.where('assets.createdAt', '<=', options.createdBefore!))
|
.$if(!!options.createdBefore, (qb) => qb.where('assets.createdAt', '<=', options.createdBefore!))
|
||||||
@@ -369,7 +384,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
|
|||||||
.$if(options.isMotion !== undefined, (qb) =>
|
.$if(options.isMotion !== undefined, (qb) =>
|
||||||
qb.where('assets.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null),
|
qb.where('assets.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null),
|
||||||
)
|
)
|
||||||
.$if(!!options.isNotInAlbum, (qb) =>
|
.$if(!!options.isNotInAlbum && (!options.albumIds || options.albumIds.length == 0), (qb) =>
|
||||||
qb.where((eb) =>
|
qb.where((eb) =>
|
||||||
eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))),
|
eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user