2026-02-14 00:59:57 +01:00
|
|
|
/**
|
|
|
|
|
* Server-side URL helpers for generating public-facing asset URLs.
|
|
|
|
|
* These use encoded tokens instead of raw Immich UUIDs.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { encodeAssetId } from './tokens';
|
2026-02-14 10:30:27 +01:00
|
|
|
import { thumbHashToBlurDataUrl, thumbHashToDominantHex } from './thumbhash';
|
|
|
|
|
import type { ImmichAsset } from './immich';
|
2026-02-14 00:59:57 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a public image proxy URL for an asset.
|
|
|
|
|
*/
|
2026-02-14 11:47:26 +01:00
|
|
|
export function imageUrl(
|
|
|
|
|
assetId: string,
|
|
|
|
|
size: 'thumbnail' | 'preview' | 'original' = 'preview',
|
|
|
|
|
): string {
|
|
|
|
|
return `/api/image/${encodeAssetId(assetId)}?size=${size}`;
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a public EXIF API URL for an asset.
|
|
|
|
|
*/
|
|
|
|
|
export function exifUrl(assetId: string): string {
|
2026-02-14 11:47:26 +01:00
|
|
|
return `/api/exif/${encodeAssetId(assetId)}`;
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-05-29 17:04:57 +02:00
|
|
|
/**
|
|
|
|
|
* Generate a public video proxy URL for an asset.
|
|
|
|
|
*/
|
|
|
|
|
export function videoUrl(assetId: string): string {
|
|
|
|
|
return `/api/video/${encodeAssetId(assetId)}`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 10:30:27 +01:00
|
|
|
/**
|
|
|
|
|
* Placeholder data derived from an asset's ThumbHash.
|
|
|
|
|
*/
|
|
|
|
|
export interface PlaceholderData {
|
2026-02-14 11:47:26 +01:00
|
|
|
blurDataURL: string;
|
|
|
|
|
dominantColor: string;
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate blur placeholder and dominant color from an asset's ThumbHash.
|
|
|
|
|
* Returns null if the asset has no ThumbHash.
|
|
|
|
|
*/
|
|
|
|
|
export function assetPlaceholder(asset: Pick<ImmichAsset, 'thumbhash'>): PlaceholderData | null {
|
2026-02-14 11:47:26 +01:00
|
|
|
if (!asset.thumbhash) return null;
|
|
|
|
|
try {
|
|
|
|
|
return {
|
|
|
|
|
blurDataURL: thumbHashToBlurDataUrl(asset.thumbhash),
|
|
|
|
|
dominantColor: thumbHashToDominantHex(asset.thumbhash),
|
|
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compact EXIF summary for hover overlays.
|
|
|
|
|
*/
|
|
|
|
|
export interface ExifSummary {
|
2026-02-14 11:47:26 +01:00
|
|
|
camera?: string;
|
|
|
|
|
lens?: string;
|
|
|
|
|
focalLength?: string;
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a compact EXIF summary from an asset's exifInfo.
|
|
|
|
|
* Returns undefined if no relevant EXIF data is available.
|
|
|
|
|
*/
|
|
|
|
|
export function assetExifSummary(asset: Pick<ImmichAsset, 'exifInfo'>): ExifSummary | undefined {
|
2026-02-14 11:47:26 +01:00
|
|
|
const exif = asset.exifInfo;
|
|
|
|
|
if (!exif) return undefined;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const camera = exif.model || undefined;
|
|
|
|
|
const lens = exif.lensModel || undefined;
|
|
|
|
|
const focalLength = exif.focalLength ? `${exif.focalLength}mm` : undefined;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
if (!camera && !lens && !focalLength) return undefined;
|
|
|
|
|
return { camera, lens, focalLength };
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compute the natural aspect ratio (width / height) from EXIF dimensions.
|
|
|
|
|
* Returns undefined if dimensions are not available.
|
|
|
|
|
*/
|
|
|
|
|
export function assetAspectRatio(asset: Pick<ImmichAsset, 'exifInfo'>): number | undefined {
|
2026-02-14 11:47:26 +01:00
|
|
|
const w = asset.exifInfo?.exifImageWidth;
|
|
|
|
|
const h = asset.exifInfo?.exifImageHeight;
|
|
|
|
|
if (w && h && h > 0) return w / h;
|
|
|
|
|
return undefined;
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|