mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-03 10:45:52 +00:00
* feat(web): lighter timeline buckets * GalleryViewer * weird ssr * Remove generics from AssetInteraction * ensure keys on getAssetInfo, alt-text * empty - trigger ci * re-add alt-text * test fix * update tests * tests * missing import * feat(server): lighter buckets * fix: flappy e2e test * lint * revert settings * unneeded cast * fix after merge * Adapt web client to consume new server response format * test * missing import * lint * Use nulls, make-sql * openapi battle * date->string * tests * tests * lint/tests * lint * test * push aggregation to query * openapi * stack as tuple * openapi * update references to description * update alt text tests * update sql * update sql * update timeline tests * linting, fix expected response * string tuple * fix spec * fix * silly generator * rename patch * minimize sorting * review * lint * lint * sql * test * avoid abbreviations * review comment - type safety in test * merge conflicts * lint * lint/abbreviations * remove unncessary code * review comments * sql * re-add package-lock * use booleans, fix visibility in openapi spec, less cursed controller * update sql * no need to use sql template * array access actually doesn't seem to matter * remove redundant code * re-add sql decorator * unused type * remove null assertions * bad merge * Fix test * shave * extra clean shave * use decorator for content type * redundant types * redundant comment * update comment * unnecessary res --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
import type { TimelineAsset } from '$lib/stores/assets-store.svelte';
|
|
import { locale } from '$lib/stores/preferences.store';
|
|
import { getAssetRatio } from '$lib/utils/asset-utils';
|
|
|
|
import { AssetTypeEnum, AssetVisibility, type AssetResponseDto } from '@immich/sdk';
|
|
|
|
import { memoize } from 'lodash-es';
|
|
import { DateTime, type LocaleOptions } from 'luxon';
|
|
import { get } from 'svelte/store';
|
|
|
|
export type ScrubberListener = (
|
|
bucketDate: string | undefined,
|
|
overallScrollPercent: number,
|
|
bucketScrollPercent: number,
|
|
) => void | Promise<void>;
|
|
|
|
export const fromLocalDateTime = (localDateTime: string) =>
|
|
DateTime.fromISO(localDateTime, { zone: 'UTC', locale: get(locale) });
|
|
|
|
export const fromDateTimeOriginal = (dateTimeOriginal: string, timeZone: string) =>
|
|
DateTime.fromISO(dateTimeOriginal, { zone: timeZone });
|
|
|
|
export function formatGroupTitle(_date: DateTime): string {
|
|
if (!_date.isValid) {
|
|
return _date.toString();
|
|
}
|
|
const date = _date as DateTime<true>;
|
|
const today = DateTime.now().startOf('day');
|
|
|
|
// Today
|
|
if (today.hasSame(date, 'day')) {
|
|
return date.toRelativeCalendar();
|
|
}
|
|
|
|
// Yesterday
|
|
if (today.minus({ days: 1 }).hasSame(date, 'day')) {
|
|
return date.toRelativeCalendar();
|
|
}
|
|
|
|
// Last week
|
|
if (date >= today.minus({ days: 6 }) && date < today) {
|
|
return date.toLocaleString({ weekday: 'long' }, { locale: get(locale) });
|
|
}
|
|
|
|
// This year
|
|
if (today.hasSame(date, 'year')) {
|
|
return date.toLocaleString(
|
|
{
|
|
weekday: 'short',
|
|
month: 'short',
|
|
day: 'numeric',
|
|
},
|
|
{ locale: get(locale) },
|
|
);
|
|
}
|
|
|
|
return getDateLocaleString(date, { locale: get(locale) });
|
|
}
|
|
|
|
export const getDateLocaleString = (date: DateTime, opts?: LocaleOptions): string =>
|
|
date.toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY, opts);
|
|
|
|
export const formatDateGroupTitle = memoize(formatGroupTitle);
|
|
|
|
export const toTimelineAsset = (unknownAsset: AssetResponseDto | TimelineAsset): TimelineAsset => {
|
|
if (isTimelineAsset(unknownAsset)) {
|
|
return unknownAsset;
|
|
}
|
|
const assetResponse = unknownAsset;
|
|
const { width, height } = getAssetRatio(assetResponse);
|
|
const ratio = width / height;
|
|
const city = assetResponse.exifInfo?.city;
|
|
const country = assetResponse.exifInfo?.country;
|
|
const people = assetResponse.people?.map((person) => person.name) || [];
|
|
return {
|
|
id: assetResponse.id,
|
|
ownerId: assetResponse.ownerId,
|
|
ratio,
|
|
thumbhash: assetResponse.thumbhash,
|
|
localDateTime: assetResponse.localDateTime,
|
|
isFavorite: assetResponse.isFavorite,
|
|
visibility: assetResponse.isArchived ? AssetVisibility.Archive : AssetVisibility.Timeline,
|
|
isTrashed: assetResponse.isTrashed,
|
|
isVideo: assetResponse.type == AssetTypeEnum.Video,
|
|
isImage: assetResponse.type == AssetTypeEnum.Image,
|
|
stack: assetResponse.stack || null,
|
|
duration: assetResponse.duration || null,
|
|
projectionType: assetResponse.exifInfo?.projectionType || null,
|
|
livePhotoVideoId: assetResponse.livePhotoVideoId || null,
|
|
city: city || null,
|
|
country: country || null,
|
|
people,
|
|
};
|
|
};
|
|
export const isTimelineAsset = (unknownAsset: AssetResponseDto | TimelineAsset): unknownAsset is TimelineAsset =>
|
|
(unknownAsset as TimelineAsset).ratio !== undefined;
|