0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 00:50:23 -05:00
This commit is contained in:
Sese Schneider 2024-12-27 09:18:56 +01:00
parent 2315466be3
commit 48bf55dad8
No known key found for this signature in database
GPG key ID: 1414BDF9A6FA09A9
5 changed files with 104 additions and 111 deletions

View file

@ -105,7 +105,8 @@
{/if} {/if}
{/await} {/await}
- -
{getExifCount(asset)} {$t('exif')} {getExifCount(asset)}
{$t('exif')}
</span> </span>
</div> </div>
</div> </div>

View file

@ -2,7 +2,6 @@ import { suggestDuplicate } from '$lib/utils/duplicate-utils';
import type { AssetResponseDto } from '@immich/sdk'; import type { AssetResponseDto } from '@immich/sdk';
describe('choosing a duplicate', () => { describe('choosing a duplicate', () => {
it('picks the asset with the largest file size', () => { it('picks the asset with the largest file size', () => {
const assets = [ const assets = [
{ exifInfo: { fileSizeInByte: 300 } }, { exifInfo: { fileSizeInByte: 300 } },
@ -27,19 +26,12 @@ describe('choosing a duplicate', () => {
}); });
it('handles assets with no exifInfo', () => { it('handles assets with no exifInfo', () => {
const assets = [ const assets = [{ exifInfo: { fileSizeInByte: 200 } }, {}];
{ exifInfo: { fileSizeInByte: 200 } },
{},
];
expect(suggestDuplicate(assets as AssetResponseDto[])).toEqual(assets[0]); expect(suggestDuplicate(assets as AssetResponseDto[])).toEqual(assets[0]);
}); });
it('handles assets with exifInfo but no fileSizeInByte', () => { it('handles assets with exifInfo but no fileSizeInByte', () => {
const assets = [ const assets = [{ exifInfo: { rating: 5, fNumber: 1 } }, { exifInfo: { rating: 5 } }];
{ exifInfo: { rating: 5, fNumber: 1 } },
{ exifInfo: { rating: 5 } },
];
expect(suggestDuplicate(assets as AssetResponseDto[])).toEqual(assets[0]); expect(suggestDuplicate(assets as AssetResponseDto[])).toEqual(assets[0]);
}); });
}); });

View file

@ -1,6 +1,6 @@
import { getExifCount } from '$lib/utils/exif-utils';
import type { AssetResponseDto } from '@immich/sdk'; import type { AssetResponseDto } from '@immich/sdk';
import { sortBy } from 'lodash-es'; import { sortBy } from 'lodash-es';
import { getExifCount } from '$lib/utils/exif-utils';
/** /**
* Suggests the best duplicate asset to keep from a list of duplicates. * Suggests the best duplicate asset to keep from a list of duplicates.
@ -16,10 +16,12 @@ export const suggestDuplicate = (assets: AssetResponseDto[]): AssetResponseDto |
const assetsBySize = sortBy(assets, (asset) => asset.exifInfo?.fileSizeInByte ?? 0); const assetsBySize = sortBy(assets, (asset) => asset.exifInfo?.fileSizeInByte ?? 0);
// All assets with the same file size as the largest asset // All assets with the same file size as the largest asset
const highestSizeAssets = assetsBySize.filter((asset) => asset.exifInfo?.fileSizeInByte === assetsBySize.at(-1)?.exifInfo?.fileSizeInByte); const highestSizeAssets = assetsBySize.filter(
(asset) => asset.exifInfo?.fileSizeInByte === assetsBySize.at(-1)?.exifInfo?.fileSizeInByte,
);
// If there are multiple assets with the same file size, return the one with the most exif data // If there are multiple assets with the same file size, return the one with the most exif data
if(highestSizeAssets.length >= 2) { if (highestSizeAssets.length >= 2) {
const assetsByExifCount = sortBy(highestSizeAssets, getExifCount); const assetsByExifCount = sortBy(highestSizeAssets, getExifCount);
return assetsByExifCount.pop(); return assetsByExifCount.pop();
} }

View file

@ -2,7 +2,6 @@ import { getExifCount } from '$lib/utils/exif-utils';
import type { AssetResponseDto } from '@immich/sdk'; import type { AssetResponseDto } from '@immich/sdk';
describe('getting the exif count', () => { describe('getting the exif count', () => {
it('returns 0 when exifInfo is undefined', () => { it('returns 0 when exifInfo is undefined', () => {
const asset = {}; const asset = {};
expect(getExifCount(asset as AssetResponseDto)).toBe(0); expect(getExifCount(asset as AssetResponseDto)).toBe(0);
@ -27,5 +26,4 @@ describe('getting the exif count', () => {
const asset = { exifInfo: { fileSizeInByte: 200, rating: 5, fNumber: 1, description: 'test' } }; const asset = { exifInfo: { fileSizeInByte: 200, rating: 5, fNumber: 1, description: 'test' } };
expect(getExifCount(asset as AssetResponseDto)).toBe(4); expect(getExifCount(asset as AssetResponseDto)).toBe(4);
}); });
}); });