From 75d34ec03c9d64461d8ac223c4b8c15b8ad56f36 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Tue, 17 Feb 2026 20:56:20 +0100 Subject: [PATCH] more bug-fixes --- src/routes/repos/[npub]/[repo]/+page.svelte | 22 ++++++++++++++++++++- src/routes/search/+page.svelte | 19 ++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/routes/repos/[npub]/[repo]/+page.svelte b/src/routes/repos/[npub]/[repo]/+page.svelte index 8d59154..4e4ad06 100644 --- a/src/routes/repos/[npub]/[repo]/+page.svelte +++ b/src/routes/repos/[npub]/[repo]/+page.svelte @@ -26,6 +26,7 @@ let loading = $state(true); let error = $state(null); + let repoNotFound = $state(false); // Track if repository doesn't exist let files = $state>([]); let currentPath = $state(''); let currentFile = $state(null); @@ -112,6 +113,7 @@ let repoBanner = $state(null); async function loadReadme() { + if (repoNotFound) return; loadingReadme = true; try { const response = await fetch(`/api/repos/${npub}/${repo}/readme?ref=${currentBranch}`); @@ -409,6 +411,11 @@ onMount(async () => { await loadBranches(); + // Skip other API calls if repository doesn't exist + if (repoNotFound) { + loading = false; + return; + } await loadFiles(); await checkAuth(); await loadTags(); @@ -453,7 +460,7 @@ } async function checkMaintainerStatus() { - if (!userPubkey) { + if (repoNotFound || !userPubkey) { isMaintainer = false; return; } @@ -474,6 +481,7 @@ } async function checkVerification() { + if (repoNotFound) return; loadingVerification = true; try { const response = await fetch(`/api/repos/${npub}/${repo}/verify`); @@ -497,6 +505,10 @@ if (branches.length > 0 && !branches.includes(currentBranch)) { currentBranch = branches[0]; } + } else if (response.status === 404) { + // Repository not provisioned yet - set error message and flag + repoNotFound = true; + error = `Repository not found. This repository exists in Nostr but hasn't been provisioned on this server yet. The server will automatically provision it soon, or you can contact the server administrator.`; } } catch (err) { console.error('Failed to load branches:', err); @@ -504,6 +516,9 @@ } async function loadFiles(path: string = '') { + // Skip if repository doesn't exist + if (repoNotFound) return; + loading = true; error = null; try { @@ -511,6 +526,10 @@ const response = await fetch(url); if (!response.ok) { + if (response.status === 404) { + repoNotFound = true; + throw new Error(`Repository not found. This repository exists in Nostr but hasn't been provisioned on this server yet. The server will automatically provision it soon, or you can contact the server administrator.`); + } throw new Error(`Failed to load files: ${response.statusText}`); } @@ -824,6 +843,7 @@ } async function loadTags() { + if (repoNotFound) return; try { const response = await fetch(`/api/repos/${npub}/${repo}/tags`); if (response.ok) { diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index 250ed61..5509681 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -20,17 +20,28 @@ loading = true; error = null; + results = null; // Reset results try { const response = await fetch(`/api/search?q=${encodeURIComponent(query)}&type=${searchType}`); if (response.ok) { - results = await response.json(); + const data = await response.json(); + // The API returns { query, type, results: { repos, code }, total } + // Extract the nested results structure + const apiResults = data.results || {}; + results = { + repos: Array.isArray(apiResults.repos) ? apiResults.repos : [], + code: Array.isArray(apiResults.code) ? apiResults.code : [], + total: typeof data.total === 'number' ? data.total : (apiResults.repos?.length || 0) + (apiResults.code?.length || 0) + }; } else { const data = await response.json(); error = data.error || 'Search failed'; + results = null; // Clear results on error } } catch (err) { error = err instanceof Error ? err.message : 'Search failed'; + results = null; // Clear results on error } finally { loading = false; } @@ -77,10 +88,10 @@ {#if results}
-

Results ({results.total})

+

Results ({results.total || 0})

- {#if (searchType === 'repos' || searchType === 'all') && results.repos.length > 0} + {#if (searchType === 'repos' || searchType === 'all') && results.repos && results.repos.length > 0}

Repositories ({results.repos.length})

@@ -112,7 +123,7 @@
{/if} - {#if (searchType === 'code' || searchType === 'all') && results.code.length > 0} + {#if (searchType === 'code' || searchType === 'all') && results.code && results.code.length > 0}

Code Files ({results.code.length})