Skip to content

Commit

Permalink
use immich SDK to determine asset path
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr committed Jun 15, 2024
1 parent d2e68fd commit 4f918a7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/server/immich.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { error } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import {
AssetMediaSize,
AssetTypeEnum,
defaults,
getAlbumInfo,
getAllAlbums,
getAssetThumbnailPath,
init,
type AssetResponseDto,
type ExifResponseDto
} from '@immich/sdk';
Expand Down Expand Up @@ -38,8 +40,10 @@ function isLandscape(exif?: ExifResponseDto) {
}

function assetToImage(asset: AssetResponseDto): SlideImage {
const params = new URLSearchParams({ size: AssetMediaSize.Preview, apiKey: IMMICH_API_KEY });
const src = `${IMMICH_HOST}/api${getAssetThumbnailPath(asset.id)}?${params}`;
return {
src: `${IMMICH_HOST}/api/assets/${asset.id}/thumbnail?size=preview&apiKey=${IMMICH_API_KEY}`,
src,
location: getLocation(asset.exifInfo),
date: new Date(asset.localDateTime),
isLandscape: isLandscape(asset.exifInfo)
Expand All @@ -57,8 +61,7 @@ export async function getImmichAlbums(): Promise<SlideImage[]> {
throw error(500, 'Please set the IMMICH_ALBUMS environment variable.');
}

defaults.baseUrl = `${IMMICH_HOST}/api`;
defaults.headers = { 'x-api-key': IMMICH_API_KEY };
init({ baseUrl: `${IMMICH_HOST}/api`, apiKey: IMMICH_API_KEY });

const albumNames = IMMICH_ALBUMS.split(',');
const allAlbums = await getAllAlbums({});
Expand Down

0 comments on commit 4f918a7

Please sign in to comment.