mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
|
|
import { getExifCount } from '$lib/utils/exif-utils';
|
||
|
|
import type { AssetResponseDto } from '@immich/sdk';
|
||
|
|
import { sortBy } from 'lodash-es';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Suggests the best duplicate asset to keep from a list of duplicates.
|
||
|
|
*
|
||
|
|
* The best asset is determined by the following criteria:
|
||
|
|
* - Largest image file size in bytes
|
||
|
|
* - Largest count of exif data
|
||
|
|
*
|
||
|
|
* @param assets List of duplicate assets
|
||
|
|
* @returns The best asset to keep
|
||
|
|
*/
|
||
|
|
export const suggestDuplicate = (assets: AssetResponseDto[]): AssetResponseDto | undefined => {
|
||
|
|
let duplicateAssets = sortBy(assets, (asset) => asset.exifInfo?.fileSizeInByte ?? 0);
|
||
|
|
|
||
|
|
// Update the list to only include assets with the largest file size
|
||
|
|
duplicateAssets = duplicateAssets.filter(
|
||
|
|
(asset) => asset.exifInfo?.fileSizeInByte === duplicateAssets.at(-1)?.exifInfo?.fileSizeInByte,
|
||
|
|
);
|
||
|
|
|
||
|
|
// If there are multiple assets with the same file size, sort the list by the count of exif data
|
||
|
|
if (duplicateAssets.length >= 2) {
|
||
|
|
duplicateAssets = sortBy(duplicateAssets, getExifCount);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Return the last asset in the list
|
||
|
|
return duplicateAssets.pop();
|
||
|
|
};
|