update references to description

This commit is contained in:
mertalev 2025-05-05 09:12:07 -04:00
parent ef9245487c
commit 1d885c1a20
No known key found for this signature in database
GPG Key ID: DF6ABC77AAD98C95
4 changed files with 25 additions and 40 deletions

View File

@ -1,6 +1,6 @@
import { sdkMock } from '$lib/__mocks__/sdk.mock'; import { sdkMock } from '$lib/__mocks__/sdk.mock';
import { AbortError } from '$lib/utils'; import { AbortError } from '$lib/utils';
import { type AssetResponseDto, type TimeBucketResponseDto } from '@immich/sdk'; import { type AssetResponseDto, type TimeBucketAssetResponseDto } from '@immich/sdk';
import { timelineAssetFactory, toResponseDto } from '@test-data/factories/asset-factory'; import { timelineAssetFactory, toResponseDto } from '@test-data/factories/asset-factory';
import { AssetStore, type TimelineAsset } from './assets-store.svelte'; import { AssetStore, type TimelineAsset } from './assets-store.svelte';
@ -23,7 +23,7 @@ describe('AssetStore', () => {
.map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })), .map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })),
}; };
const bucketAssetsResponse: Record<string, TimeBucketResponseDto> = Object.fromEntries( const bucketAssetsResponse: Record<string, TimeBucketAssetResponseDto> = Object.fromEntries(
Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]), Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]),
); );
@ -75,7 +75,7 @@ describe('AssetStore', () => {
.buildList(3) .buildList(3)
.map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })), .map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })),
}; };
const bucketAssetsResponse: Record<string, TimeBucketResponseDto> = Object.fromEntries( const bucketAssetsResponse: Record<string, TimeBucketAssetResponseDto> = Object.fromEntries(
Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]), Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]),
); );
beforeEach(async () => { beforeEach(async () => {
@ -362,7 +362,7 @@ describe('AssetStore', () => {
.buildList(3) .buildList(3)
.map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })), .map((asset) => ({ ...asset, localDateTime: '2024-01-01T00:00:00.000Z' })),
}; };
const bucketAssetsResponse: Record<string, TimeBucketResponseDto> = Object.fromEntries( const bucketAssetsResponse: Record<string, TimeBucketAssetResponseDto> = Object.fromEntries(
Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]), Object.entries(bucketAssets).map(([key, assets]) => [key, toResponseDto(...assets)]),
); );

View File

@ -41,19 +41,18 @@ export function getThumbnailSize(assetCount: number, viewWidth: number): number
export const getAltText = derived(t, ($t) => { export const getAltText = derived(t, ($t) => {
return (asset: TimelineAsset) => { return (asset: TimelineAsset) => {
const date = fromLocalDateTime(asset.localDateTime).toLocaleString({ dateStyle: 'long' }, { locale: get(locale) }); const date = fromLocalDateTime(asset.localDateTime).toLocaleString({ dateStyle: 'long' }, { locale: get(locale) });
const { city, country, people: names } = asset.description; const hasPlace = asset.city && asset.country;
const hasPlace = city && country;
const peopleCount = names.length; const peopleCount = asset.people.length;
const isVideo = asset.isVideo; const isVideo = asset.isVideo;
const values = { const values = {
date, date,
city, city: asset.city,
country, country: asset.country,
person1: names[0], person1: peopleCount > 0 ? asset.people[0] : undefined,
person2: names[1], person2: peopleCount > 1 ? asset.people[1] : undefined,
person3: names[2], person3: peopleCount > 2 ? asset.people[2] : undefined,
isVideo, isVideo,
additionalCount: peopleCount > 3 ? peopleCount - 2 : 0, additionalCount: peopleCount > 3 ? peopleCount - 2 : 0,
}; };

View File

@ -72,11 +72,6 @@ export const toTimelineAsset = (unknownAsset: AssetResponseDto | TimelineAsset):
const country = assetResponse.exifInfo?.country; const country = assetResponse.exifInfo?.country;
const people = assetResponse.people?.map((person) => person.name) || []; const people = assetResponse.people?.map((person) => person.name) || [];
const description = {
city: city || null,
country: country || null,
people,
};
return { return {
id: assetResponse.id, id: assetResponse.id,
ownerId: assetResponse.ownerId, ownerId: assetResponse.ownerId,
@ -92,7 +87,9 @@ export const toTimelineAsset = (unknownAsset: AssetResponseDto | TimelineAsset):
duration: assetResponse.duration || null, duration: assetResponse.duration || null,
projectionType: assetResponse.exifInfo?.projectionType || null, projectionType: assetResponse.exifInfo?.projectionType || null,
livePhotoVideoId: assetResponse.livePhotoVideoId || null, livePhotoVideoId: assetResponse.livePhotoVideoId || null,
description, city: city || null,
country: country || null,
people,
}; };
}; };
export const isTimelineAsset = (arg: AssetResponseDto | TimelineAsset): arg is TimelineAsset => export const isTimelineAsset = (arg: AssetResponseDto | TimelineAsset): arg is TimelineAsset =>

View File

@ -1,12 +1,6 @@
import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; import type { TimelineAsset } from '$lib/stores/assets-store.svelte';
import { faker } from '@faker-js/faker'; import { faker } from '@faker-js/faker';
import { import { AssetTypeEnum, type AssetResponseDto, type TimeBucketAssetResponseDto } from '@immich/sdk';
AssetTypeEnum,
type AssetResponseDto,
type TimeBucketAssetResponseDto,
type TimeBucketResponseDto,
type TimelineStackResponseDto,
} from '@immich/sdk';
import { Sync } from 'factory.ts'; import { Sync } from 'factory.ts';
export const assetFactory = Sync.makeFactory<AssetResponseDto>({ export const assetFactory = Sync.makeFactory<AssetResponseDto>({
@ -48,23 +42,21 @@ export const timelineAssetFactory = Sync.makeFactory<TimelineAsset>({
stack: null, stack: null,
projectionType: null, projectionType: null,
livePhotoVideoId: Sync.each(() => faker.string.uuid()), livePhotoVideoId: Sync.each(() => faker.string.uuid()),
description: Sync.each(() => ({ city: faker.location.city(),
city: faker.location.city(), country: faker.location.country(),
country: faker.location.country(), people: [faker.person.fullName()],
people: [faker.person.fullName()],
})),
}); });
export const toResponseDto = (...timelineAsset: TimelineAsset[]) => { export const toResponseDto = (...timelineAsset: TimelineAsset[]) => {
const bucketAssets: TimeBucketAssetResponseDto = { const bucketAssets: TimeBucketAssetResponseDto = {
description: [], city: [],
country: [],
duration: [], duration: [],
id: [], id: [],
isArchived: [], isArchived: [],
isFavorite: [], isFavorite: [],
isImage: [], isImage: [],
isTrashed: [], isTrashed: [],
isVideo: [],
livePhotoVideoId: [], livePhotoVideoId: [],
localDateTime: [], localDateTime: [],
ownerId: [], ownerId: [],
@ -74,25 +66,22 @@ export const toResponseDto = (...timelineAsset: TimelineAsset[]) => {
thumbhash: [], thumbhash: [],
}; };
for (const asset of timelineAsset) { for (const asset of timelineAsset) {
bucketAssets.description.push(asset.description); bucketAssets.city.push(asset.city);
bucketAssets.country.push(asset.country);
bucketAssets.duration.push(asset.duration!); bucketAssets.duration.push(asset.duration!);
bucketAssets.id.push(asset.id); bucketAssets.id.push(asset.id);
bucketAssets.isArchived.push(asset.isArchived ? 1 : 0); bucketAssets.isArchived.push(asset.isArchived ? 1 : 0);
bucketAssets.isFavorite.push(asset.isFavorite ? 1 : 0); bucketAssets.isFavorite.push(asset.isFavorite ? 1 : 0);
bucketAssets.isImage.push(asset.isImage ? 1 : 0); bucketAssets.isImage.push(asset.isImage ? 1 : 0);
bucketAssets.isTrashed.push(asset.isTrashed ? 1 : 0); bucketAssets.isTrashed.push(asset.isTrashed ? 1 : 0);
bucketAssets.isVideo.push(asset.isVideo ? 1 : 0);
bucketAssets.livePhotoVideoId.push(asset.livePhotoVideoId!); bucketAssets.livePhotoVideoId.push(asset.livePhotoVideoId!);
bucketAssets.localDateTime.push(asset.localDateTime); bucketAssets.localDateTime.push(asset.localDateTime);
bucketAssets.ownerId.push(asset.ownerId); bucketAssets.ownerId.push(asset.ownerId);
bucketAssets.projectionType.push(asset.projectionType!); bucketAssets.projectionType.push(asset.projectionType!);
bucketAssets.ratio.push(asset.ratio); bucketAssets.ratio.push(asset.ratio);
bucketAssets.stack.push(asset.stack as TimelineStackResponseDto); bucketAssets.stack?.push(asset.stack ? [asset.stack.id, asset.stack.assetCount] : null);
bucketAssets.thumbhash.push(asset.thumbhash!); bucketAssets.thumbhash.push(asset.thumbhash!);
} }
const response: TimeBucketResponseDto = {
bucketAssets, return bucketAssets;
hasNextPage: false,
};
return response;
}; };