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 @@ @@ -26,6 +26,7 @@
let loading = $state(true);
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 currentPath = $state('');
let currentFile = $state<string | null>(null);
@ -112,6 +113,7 @@ @@ -112,6 +113,7 @@
let repoBanner = $state<string | null>(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 @@ @@ -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 @@ @@ -453,7 +460,7 @@
}
async function checkMaintainerStatus() {
if (!userPubkey) {
if (repoNotFound || !userPubkey) {
isMaintainer = false;
return;
}
@ -474,6 +481,7 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -824,6 +843,7 @@
}
async function loadTags() {
if (repoNotFound) return;
try {
const response = await fetch(`/api/repos/${npub}/${repo}/tags`);
if (response.ok) {

19
src/routes/search/+page.svelte

@ -20,17 +20,28 @@ @@ -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 @@ @@ -77,10 +88,10 @@
{#if results}
<div class="results">
<div class="results-header">
<h2>Results ({results.total})</h2>
<h2>Results ({results.total || 0})</h2>
</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">
<h3>Repositories ({results.repos.length})</h3>
<div class="repo-list">
@ -112,7 +123,7 @@ @@ -112,7 +123,7 @@
</section>
{/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">
<h3>Code Files ({results.code.length})</h3>
<div class="code-list">

Loading…
Cancel
Save