refactor: asset from param (#25041)

This commit is contained in:
Jason Rasmussen 2026-01-05 11:26:58 -05:00 committed by GitHub
parent 1874557b95
commit 62cc12be3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 27 additions and 65 deletions

View file

@ -0,0 +1,10 @@
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { LayoutLoad } from './$types';
export const load = (async ({ params }) => {
const asset = await getAssetInfoFromParam(params);
return {
asset,
};
}) satisfies LayoutLoad;

View file

@ -1,18 +1,13 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getAlbumInfo } from '@immich/sdk'; import { getAlbumInfo } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ params, url }) => {
await authenticate(url); await authenticate(url);
const [album, asset] = await Promise.all([ const album = await getAlbumInfo({ id: params.albumId, withoutAssets: true });
getAlbumInfo({ id: params.albumId, withoutAssets: true }),
getAssetInfoFromParam(params),
]);
return { return {
album, album,
asset,
meta: { meta: {
title: album.albumName, title: album.albumName,
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('archive'), title: $t('archive'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('favorites'), title: $t('favorites'),
}, },

View file

@ -2,12 +2,11 @@ import { QueryParameter } from '$lib/constants';
import { foldersStore } from '$lib/stores/folders.svelte'; import { foldersStore } from '$lib/stores/folders.svelte';
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const [, asset, $t] = await Promise.all([foldersStore.fetchTree(), getAssetInfoFromParam(params), getFormatter()]); const [, $t] = await Promise.all([foldersStore.fetchTree(), getFormatter()]);
let tree = foldersStore.folders!; let tree = foldersStore.folders!;
const path = url.searchParams.get(QueryParameter.PATH); const path = url.searchParams.get(QueryParameter.PATH);
@ -23,7 +22,6 @@ export const load = (async ({ params, url }) => {
const pathAssets = tree.hasAssets ? await foldersStore.fetchAssetsByPath(tree.path) : null; const pathAssets = tree.hasAssets ? await foldersStore.fetchAssetsByPath(tree.path) : null;
return { return {
asset,
tree, tree,
pathAssets, pathAssets,
meta: { meta: {

View file

@ -1,12 +1,11 @@
import { AppRoute } from '$lib/constants'; import { AppRoute } from '$lib/constants';
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getAuthStatus } from '@immich/sdk'; import { getAuthStatus } from '@immich/sdk';
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const { isElevated, pinCode } = await getAuthStatus(); const { isElevated, pinCode } = await getAuthStatus();
@ -14,11 +13,9 @@ export const load = (async ({ params, url }) => {
redirect(302, `${AppRoute.AUTH_PIN_PROMPT}?continue=${encodeURIComponent(url.pathname + url.search)}`); redirect(302, `${AppRoute.AUTH_PIN_PROMPT}?continue=${encodeURIComponent(url.pathname + url.search)}`);
} }
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('locked_folder'), title: $t('locked_folder'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('map'), title: $t('map'),
}, },

View file

@ -1,16 +1,13 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
const user = await authenticate(url); const user = await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
user, user,
asset,
meta: { meta: {
title: $t('memory'), title: $t('memory'),
}, },

View file

@ -1,6 +1,5 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getUser } from '@immich/sdk'; import { getUser } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
@ -8,11 +7,9 @@ export const load = (async ({ params, url }) => {
await authenticate(url); await authenticate(url);
const partner = await getUser({ id: params.userId }); const partner = await getUser({ id: params.userId });
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
partner, partner,
meta: { meta: {
title: $t('partner'), title: $t('partner'),

View file

@ -1,23 +1,20 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getPerson, getPersonStatistics } from '@immich/sdk'; import { getPerson, getPersonStatistics } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ params, url }) => {
await authenticate(url); await authenticate(url);
const [person, statistics, asset] = await Promise.all([ const [person, statistics] = await Promise.all([
getPerson({ id: params.personId }), getPerson({ id: params.personId }),
getPersonStatistics({ id: params.personId }), getPersonStatistics({ id: params.personId }),
getAssetInfoFromParam(params),
]); ]);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
person, person,
statistics, statistics,
asset,
meta: { meta: {
title: person.name || $t('person'), title: person.name || $t('person'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('photos'), title: $t('photos'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('search'), title: $t('search'),
}, },

View file

@ -1,13 +1,11 @@
import { QueryParameter } from '$lib/constants'; import { QueryParameter } from '$lib/constants';
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getAllTags } from '@immich/sdk'; import { getAllTags } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
const tags = await getAllTags(); const tags = await getAllTags();
@ -15,7 +13,6 @@ export const load = (async ({ params, url }) => {
return { return {
path: url.searchParams.get(QueryParameter.PATH) ?? '', path: url.searchParams.get(QueryParameter.PATH) ?? '',
tags, tags,
asset,
meta: { meta: {
title: $t('tags'), title: $t('tags'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('trash'), title: $t('trash'),
}, },

View file

@ -1,15 +1,12 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
meta: { meta: {
title: $t('utilities'), title: $t('utilities'),
}, },

View file

@ -1,17 +1,14 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getAssetDuplicates } from '@immich/sdk'; import { getAssetDuplicates } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const asset = await getAssetInfoFromParam(params);
const duplicates = await getAssetDuplicates(); const duplicates = await getAssetDuplicates();
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
asset,
duplicates, duplicates,
meta: { meta: {
title: $t('duplicates'), title: $t('duplicates'),

View file

@ -1,17 +1,15 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { searchLargeAssets } from '@immich/sdk'; import { searchLargeAssets } from '@immich/sdk';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
const [assets, asset] = await Promise.all([searchLargeAssets({ minFileSize: 0 }), getAssetInfoFromParam(params)]); const assets = await searchLargeAssets({ minFileSize: 0 });
const $t = await getFormatter(); const $t = await getFormatter();
return { return {
assets, assets,
asset,
meta: { meta: {
title: $t('large_files'), title: $t('large_files'),
}, },