Skip to content

High performance self-hosted photo and video management solution.

fix(web): access /search throw error (#5834)

Alex9834693fabc9
diff --git a/web/src/routes/(user)/search/+page.svelte b/web/src/routes/(user)/search/+page.svelte
index eb8341a799..e8bc0c08d4 100644
--- a/web/src/routes/(user)/search/+page.svelte
+++ b/web/src/routes/(user)/search/+page.svelte
@@ -36,7 +36,7 @@
// behavior for history.back(). To prevent that we store the previous page
// manually and navigate back to that.
let previousRoute = AppRoute.EXPLORE as string;
- $: albums = data.results.albums.items;
+ $: albums = data.results?.albums.items;
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
@@ -98,10 +98,10 @@
$: isMultiSelectionMode = selectedAssets.size > 0;
$: isAllArchived = Array.from(selectedAssets).every((asset) => asset.isArchived);
$: isAllFavorite = Array.from(selectedAssets).every((asset) => asset.isFavorite);
- $: searchResultAssets = data.results.assets.items;
+ $: searchResultAssets = data.results?.assets.items;
const onAssetDelete = (assetId: string) => {
- searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => a.id !== assetId);
+ searchResultAssets = searchResultAssets?.filter((a: AssetResponseDto) => a.id !== assetId);
};
const handleSelectAll = () => {
selectedAssets = new Set(searchResultAssets);
@@ -140,7 +140,7 @@
<section class="relative mb-12 bg-immich-bg pt-32 dark:bg-immich-dark-bg">
<section class="immich-scrollbar relative overflow-y-auto">
- {#if albums.length}
+ {#if albums && albums.length}
<section>
<div class="ml-6 text-4xl font-medium text-black/70 dark:text-white/80">ALBUMS</div>
<div class="grid grid-cols-[repeat(auto-fill,minmax(14rem,1fr))]">
@@ -161,7 +161,7 @@
</section>
{/if}
<section id="search-content" class="relative bg-immich-bg dark:bg-immich-dark-bg">
- {#if searchResultAssets.length > 0}
+ {#if searchResultAssets && searchResultAssets.length > 0}
<div class="pl-4">
<GalleryViewer assets={searchResultAssets} bind:selectedAssets showArchiveIcon={true} />
</div>
diff --git a/web/src/routes/(user)/search/+page.ts b/web/src/routes/(user)/search/+page.ts
index 1f2cffcbaf..c76de05d0c 100644
--- a/web/src/routes/(user)/search/+page.ts
+++ b/web/src/routes/(user)/search/+page.ts
@@ -1,12 +1,16 @@
import { authenticate } from '$lib/utils/auth';
-import { api } from '@api';
+import { SearchResponseDto, api } from '@api';
import type { PageLoad } from './$types';
export const load = (async (data) => {
await authenticate();
const url = new URL(data.url.href);
const term = url.searchParams.get('q') || url.searchParams.get('query') || undefined;
- const { data: results } = await api.searchApi.search({}, { params: url.searchParams });
+ let results: SearchResponseDto | null = null;
+ if (term) {
+ const { data } = await api.searchApi.search({}, { params: url.searchParams });
+ results = data;
+ }
return {
term,