mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix: withFilePath select edited or unedited file (#27328)
* fix: withFilePath select edited or unedited file * chore: test
This commit is contained in:
@@ -437,12 +437,13 @@ select
|
|||||||
"asset_file"
|
"asset_file"
|
||||||
where
|
where
|
||||||
"asset_file"."assetId" = "asset"."id"
|
"asset_file"."assetId" = "asset"."id"
|
||||||
and "asset_file"."type" = $1
|
and "asset_file"."type" = 'preview'
|
||||||
|
and "asset_file"."isEdited" = false
|
||||||
) as "previewFile"
|
) as "previewFile"
|
||||||
from
|
from
|
||||||
"asset"
|
"asset"
|
||||||
where
|
where
|
||||||
"asset"."id" = $2
|
"asset"."id" = $1
|
||||||
|
|
||||||
-- AssetJobRepository.getForSyncAssets
|
-- AssetJobRepository.getForSyncAssets
|
||||||
select
|
select
|
||||||
|
|||||||
@@ -637,13 +637,14 @@ select
|
|||||||
"asset_file"
|
"asset_file"
|
||||||
where
|
where
|
||||||
"asset_file"."assetId" = "asset"."id"
|
"asset_file"."assetId" = "asset"."id"
|
||||||
and "asset_file"."type" = $1
|
and "asset_file"."type" = 'encoded_video'
|
||||||
|
and "asset_file"."isEdited" = false
|
||||||
) as "encodedVideoPath"
|
) as "encodedVideoPath"
|
||||||
from
|
from
|
||||||
"asset"
|
"asset"
|
||||||
where
|
where
|
||||||
"asset"."id" = $2
|
"asset"."id" = $1
|
||||||
and "asset"."type" = $3
|
and "asset"."type" = $2
|
||||||
|
|
||||||
-- AssetRepository.getForOcr
|
-- AssetRepository.getForOcr
|
||||||
select
|
select
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ select
|
|||||||
where
|
where
|
||||||
"asset_file"."assetId" = "asset"."id"
|
"asset_file"."assetId" = "asset"."id"
|
||||||
and "asset_file"."type" = 'preview'
|
and "asset_file"."type" = 'preview'
|
||||||
and "asset_file"."isEdited" = $1
|
and "asset_file"."isEdited" = false
|
||||||
) as "previewPath"
|
) as "previewPath"
|
||||||
from
|
from
|
||||||
"person"
|
"person"
|
||||||
@@ -184,7 +184,7 @@ from
|
|||||||
inner join "asset" on "asset_face"."assetId" = "asset"."id"
|
inner join "asset" on "asset_face"."assetId" = "asset"."id"
|
||||||
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
|
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
|
||||||
where
|
where
|
||||||
"person"."id" = $2
|
"person"."id" = $1
|
||||||
and "asset_face"."deletedAt" is null
|
and "asset_face"."deletedAt" is null
|
||||||
|
|
||||||
-- PersonRepository.reassignFace
|
-- PersonRepository.reassignFace
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { DB } from 'src/schema';
|
|||||||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||||
import { FaceSearchTable } from 'src/schema/tables/face-search.table';
|
import { FaceSearchTable } from 'src/schema/tables/face-search.table';
|
||||||
import { PersonTable } from 'src/schema/tables/person.table';
|
import { PersonTable } from 'src/schema/tables/person.table';
|
||||||
import { removeUndefinedKeys } from 'src/utils/database';
|
import { removeUndefinedKeys, withFilePath } from 'src/utils/database';
|
||||||
import { paginationHelper, PaginationOptions } from 'src/utils/pagination';
|
import { paginationHelper, PaginationOptions } from 'src/utils/pagination';
|
||||||
|
|
||||||
export interface PersonSearchOptions {
|
export interface PersonSearchOptions {
|
||||||
@@ -282,15 +282,7 @@ export class PersonRepository {
|
|||||||
'asset.originalPath',
|
'asset.originalPath',
|
||||||
'asset_exif.orientation as exifOrientation',
|
'asset_exif.orientation as exifOrientation',
|
||||||
])
|
])
|
||||||
.select((eb) =>
|
.select((eb) => withFilePath(eb, AssetFileType.Preview).as('previewPath'))
|
||||||
eb
|
|
||||||
.selectFrom('asset_file')
|
|
||||||
.select('asset_file.path')
|
|
||||||
.whereRef('asset_file.assetId', '=', 'asset.id')
|
|
||||||
.where('asset_file.type', '=', sql.lit(AssetFileType.Preview))
|
|
||||||
.where('asset_file.isEdited', '=', false)
|
|
||||||
.as('previewPath'),
|
|
||||||
)
|
|
||||||
.where('person.id', '=', id)
|
.where('person.id', '=', id)
|
||||||
.where('asset_face.deletedAt', 'is', null)
|
.where('asset_face.deletedAt', 'is', null)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|||||||
@@ -126,12 +126,13 @@ export function withFiles(eb: ExpressionBuilder<DB, 'asset'>, type?: AssetFileTy
|
|||||||
).as('files');
|
).as('files');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withFilePath(eb: ExpressionBuilder<DB, 'asset'>, type: AssetFileType) {
|
export function withFilePath(eb: ExpressionBuilder<DB, 'asset'>, type: AssetFileType, isEdited = false) {
|
||||||
return eb
|
return eb
|
||||||
.selectFrom('asset_file')
|
.selectFrom('asset_file')
|
||||||
.select('asset_file.path')
|
.select('asset_file.path')
|
||||||
.whereRef('asset_file.assetId', '=', 'asset.id')
|
.whereRef('asset_file.assetId', '=', 'asset.id')
|
||||||
.where('asset_file.type', '=', type);
|
.where('asset_file.type', '=', sql.lit(type))
|
||||||
|
.where('asset_file.isEdited', '=', sql.lit(isEdited));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withFacesAndPeople(
|
export function withFacesAndPeople(
|
||||||
|
|||||||
@@ -115,4 +115,33 @@ describe(AssetJobRepository.name, () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getForOcr', () => {
|
||||||
|
it('should not return the edited preview file', async () => {
|
||||||
|
const { ctx, sut } = setup();
|
||||||
|
const { user } = await ctx.newUser();
|
||||||
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
||||||
|
|
||||||
|
await ctx.newAssetFile({
|
||||||
|
assetId: asset.id,
|
||||||
|
type: AssetFileType.Preview,
|
||||||
|
path: 'preview_edited.jpg',
|
||||||
|
isEdited: true,
|
||||||
|
});
|
||||||
|
await ctx.newAssetFile({
|
||||||
|
assetId: asset.id,
|
||||||
|
type: AssetFileType.Preview,
|
||||||
|
path: 'preview_unedited.jpg',
|
||||||
|
isEdited: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await sut.getForOcr(asset.id);
|
||||||
|
|
||||||
|
expect(result).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
previewFile: 'preview_unedited.jpg',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user