Browse Source

more bug-fixes

main
Silberengel 4 weeks ago
parent
commit
75d34ec03c
  1. 22
      src/routes/repos/[npub]/[repo]/+page.svelte
  2. 19
      src/routes/search/+page.svelte

22
src/routes/repos/[npub]/[repo]/+page.svelte

@ -26,6 +26,7 @@
let loading = $state(true); let loading = $state(true);
let error = $state<string | null>(null); let error = $state<string | null>(null);
let repoNotFound = $state(false); // Track if repository doesn't exist
let files = $state<Array<{ name: string; path: string; type: 'file' | 'directory'; size?: number }>>([]); let files = $state<Array<{ name: string; path: string; type: 'file' | 'directory'; size?: number }>>([]);
let currentPath = $state(''); let currentPath = $state('');
let currentFile = $state<string | null>(null); let currentFile = $state<string | null>(null);
@ -112,6 +113,7 @@
let repoBanner = $state<string | null>(null); let repoBanner = $state<string | null>(null);
async function loadReadme() { async function loadReadme() {
if (repoNotFound) return;
loadingReadme = true; loadingReadme = true;
try { try {
const response = await fetch(`/api/repos/${npub}/${repo}/readme?ref=${currentBranch}`); const response = await fetch(`/api/repos/${npub}/${repo}/readme?ref=${currentBranch}`);
@ -409,6 +411,11 @@
onMount(async () => { onMount(async () => {
await loadBranches(); await loadBranches();
// Skip other API calls if repository doesn't exist
if (repoNotFound) {
loading = false;
return;
}
await loadFiles(); await loadFiles();
await checkAuth(); await checkAuth();
await loadTags(); await loadTags();
@ -453,7 +460,7 @@
} }
async function checkMaintainerStatus() { async function checkMaintainerStatus() {
if (!userPubkey) { if (repoNotFound || !userPubkey) {
isMaintainer = false; isMaintainer = false;
return; return;
} }
@ -474,6 +481,7 @@
} }
async function checkVerification() { async function checkVerification() {
if (repoNotFound) return;
loadingVerification = true; loadingVerification = true;
try { try {
const response = await fetch(`/api/repos/${npub}/${repo}/verify`); const response = await fetch(`/api/repos/${npub}/${repo}/verify`);
@ -497,6 +505,10 @@
if (branches.length > 0 && !branches.includes(currentBranch)) { if (branches.length > 0 && !branches.includes(currentBranch)) {
currentBranch = branches[0]; 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) { } catch (err) {
console.error('Failed to load branches:', err); console.error('Failed to load branches:', err);
@ -504,6 +516,9 @@
} }
async function loadFiles(path: string = '') { async function loadFiles(path: string = '') {
// Skip if repository doesn't exist
if (repoNotFound) return;
loading = true; loading = true;
error = null; error = null;
try { try {
@ -511,6 +526,10 @@
const response = await fetch(url); const response = await fetch(url);
if (!response.ok) { 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}`); throw new Error(`Failed to load files: ${response.statusText}`);
} }
@ -824,6 +843,7 @@
} }
async function loadTags() { async function loadTags() {
if (repoNotFound) return;
try { try {
const response = await fetch(`/api/repos/${npub}/${repo}/tags`); const response = await fetch(`/api/repos/${npub}/${repo}/tags`);
if (response.ok) { if (response.ok) {

19
src/routes/search/+page.svelte

@ -20,17 +20,28 @@
loading = true; loading = true;
error = null; error = null;
results = null; // Reset results
try { try {
const response = await fetch(`/api/search?q=${encodeURIComponent(query)}&type=${searchType}`); const response = await fetch(`/api/search?q=${encodeURIComponent(query)}&type=${searchType}`);
if (response.ok) { 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 { } else {
const data = await response.json(); const data = await response.json();
error = data.error || 'Search failed'; error = data.error || 'Search failed';
results = null; // Clear results on error
} }
} catch (err) { } catch (err) {
error = err instanceof Error ? err.message : 'Search failed'; error = err instanceof Error ? err.message : 'Search failed';
results = null; // Clear results on error
} finally { } finally {
loading = false; loading = false;
} }
@ -77,10 +88,10 @@
{#if results} {#if results}
<div class="results"> <div class="results">
<div class="results-header"> <div class="results-header">
<h2>Results ({results.total})</h2> <h2>Results ({results.total || 0})</h2>
</div> </div>
{#if (searchType === 'repos' || searchType === 'all') && results.repos.length > 0} {#if (searchType === 'repos' || searchType === 'all') && results.repos && results.repos.length > 0}
<section class="results-section"> <section class="results-section">
<h3>Repositories ({results.repos.length})</h3> <h3>Repositories ({results.repos.length})</h3>
<div class="repo-list"> <div class="repo-list">
@ -112,7 +123,7 @@
</section> </section>
{/if} {/if}
{#if (searchType === 'code' || searchType === 'all') && results.code.length > 0} {#if (searchType === 'code' || searchType === 'all') && results.code && results.code.length > 0}
<section class="results-section"> <section class="results-section">
<h3>Code Files ({results.code.length})</h3> <h3>Code Files ({results.code.length})</h3>
<div class="code-list"> <div class="code-list">

Loading…
Cancel
Save