mirror of
https://github.com/immich-app/immich.git
synced 2025-01-28 00:59:18 -05:00
fix(server): checkExistingAssets (#10192)
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
52170423be
commit
9dbf5db72e
5 changed files with 37 additions and 7 deletions
|
@ -1148,4 +1148,29 @@ describe('/asset', () => {
|
||||||
expect(video.checksum).toStrictEqual(checksum);
|
expect(video.checksum).toStrictEqual(checksum);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('POST /assets/exist', () => {
|
||||||
|
it('ignores invalid deviceAssetIds', async () => {
|
||||||
|
const response = await utils.checkExistingAssets(user1.accessToken, {
|
||||||
|
deviceId: 'test-assets-exist',
|
||||||
|
deviceAssetIds: ['invalid', 'INVALID'],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.existingIds).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the IDs of existing assets', async () => {
|
||||||
|
await utils.createAsset(user1.accessToken, {
|
||||||
|
deviceId: 'test-assets-exist',
|
||||||
|
deviceAssetId: 'test-asset-0',
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await utils.checkExistingAssets(user1.accessToken, {
|
||||||
|
deviceId: 'test-assets-exist',
|
||||||
|
deviceAssetIds: ['test-asset-0'],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.existingIds).toEqual(['test-asset-0']);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
AssetMediaCreateDto,
|
AssetMediaCreateDto,
|
||||||
AssetMediaResponseDto,
|
AssetMediaResponseDto,
|
||||||
AssetResponseDto,
|
AssetResponseDto,
|
||||||
|
CheckExistingAssetsDto,
|
||||||
CreateAlbumDto,
|
CreateAlbumDto,
|
||||||
CreateLibraryDto,
|
CreateLibraryDto,
|
||||||
MetadataSearchDto,
|
MetadataSearchDto,
|
||||||
|
@ -10,6 +11,7 @@ import {
|
||||||
SharedLinkCreateDto,
|
SharedLinkCreateDto,
|
||||||
UserAdminCreateDto,
|
UserAdminCreateDto,
|
||||||
ValidateLibraryDto,
|
ValidateLibraryDto,
|
||||||
|
checkExistingAssets,
|
||||||
createAlbum,
|
createAlbum,
|
||||||
createApiKey,
|
createApiKey,
|
||||||
createLibrary,
|
createLibrary,
|
||||||
|
@ -374,6 +376,9 @@ export const utils = {
|
||||||
|
|
||||||
getAssetInfo: (accessToken: string, id: string) => getAssetInfo({ id }, { headers: asBearerAuth(accessToken) }),
|
getAssetInfo: (accessToken: string, id: string) => getAssetInfo({ id }, { headers: asBearerAuth(accessToken) }),
|
||||||
|
|
||||||
|
checkExistingAssets: (accessToken: string, checkExistingAssetsDto: CheckExistingAssetsDto) =>
|
||||||
|
checkExistingAssets({ checkExistingAssetsDto }, { headers: asBearerAuth(accessToken) }),
|
||||||
|
|
||||||
metadataSearch: async (accessToken: string, dto: MetadataSearchDto) => {
|
metadataSearch: async (accessToken: string, dto: MetadataSearchDto) => {
|
||||||
return searchMetadata({ metadataSearchDto: dto }, { headers: asBearerAuth(accessToken) });
|
return searchMetadata({ metadataSearchDto: dto }, { headers: asBearerAuth(accessToken) });
|
||||||
},
|
},
|
||||||
|
|
|
@ -156,7 +156,7 @@ export interface IAssetRepository {
|
||||||
getByChecksums(userId: string, checksums: Buffer[]): Promise<AssetEntity[]>;
|
getByChecksums(userId: string, checksums: Buffer[]): Promise<AssetEntity[]>;
|
||||||
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
||||||
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
||||||
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<AssetEntity[]>;
|
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]>;
|
||||||
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
||||||
getById(
|
getById(
|
||||||
id: string,
|
id: string,
|
||||||
|
|
|
@ -155,8 +155,8 @@ export class AssetRepository implements IAssetRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<AssetEntity[]> {
|
async getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]> {
|
||||||
return this.repository.find({
|
const assets = await this.repository.find({
|
||||||
select: { deviceAssetId: true },
|
select: { deviceAssetId: true },
|
||||||
where: {
|
where: {
|
||||||
deviceAssetId: In(deviceAssetIds),
|
deviceAssetId: In(deviceAssetIds),
|
||||||
|
@ -165,6 +165,8 @@ export class AssetRepository implements IAssetRepository {
|
||||||
},
|
},
|
||||||
withDeleted: true,
|
withDeleted: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return assets.map((asset) => asset.deviceAssetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getByUserId(
|
getByUserId(
|
||||||
|
|
|
@ -277,14 +277,12 @@ export class AssetMediaService {
|
||||||
auth: AuthDto,
|
auth: AuthDto,
|
||||||
checkExistingAssetsDto: CheckExistingAssetsDto,
|
checkExistingAssetsDto: CheckExistingAssetsDto,
|
||||||
): Promise<CheckExistingAssetsResponseDto> {
|
): Promise<CheckExistingAssetsResponseDto> {
|
||||||
const assets = await this.assetRepository.getByDeviceIds(
|
const existingIds = await this.assetRepository.getByDeviceIds(
|
||||||
auth.user.id,
|
auth.user.id,
|
||||||
checkExistingAssetsDto.deviceId,
|
checkExistingAssetsDto.deviceId,
|
||||||
checkExistingAssetsDto.deviceAssetIds,
|
checkExistingAssetsDto.deviceAssetIds,
|
||||||
);
|
);
|
||||||
return {
|
return { existingIds };
|
||||||
existingIds: assets.map((asset) => asset.id),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async bulkUploadCheck(auth: AuthDto, dto: AssetBulkUploadCheckDto): Promise<AssetBulkUploadCheckResponseDto> {
|
async bulkUploadCheck(auth: AuthDto, dto: AssetBulkUploadCheckDto): Promise<AssetBulkUploadCheckResponseDto> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue