From c2172acc2d0cd5e928b488be3a50df9e2e84caed Mon Sep 17 00:00:00 2001 From: Silberengel Date: Sat, 14 Feb 2026 17:51:43 +0100 Subject: [PATCH] bug-fixes --- src/lib/services/nostr/event-hierarchy.ts | 3 +- src/lib/services/nostr/nostr-client.ts | 45 +++++++++++++++++++ .../api/gitea-proxy/[...path]/+server.ts | 25 +++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/lib/services/nostr/event-hierarchy.ts b/src/lib/services/nostr/event-hierarchy.ts index 8727493..6cb5969 100644 --- a/src/lib/services/nostr/event-hierarchy.ts +++ b/src/lib/services/nostr/event-hierarchy.ts @@ -75,7 +75,8 @@ export async function buildEventHierarchy(event: NostrEvent): Promise 0 ? parts.join(' ') : 'empty filter'; } + /** + * Validate that a string is a valid hex pubkey (64 hex characters) + */ + private isValidPubkey(pubkey: string): boolean { + return typeof pubkey === 'string' && /^[a-f0-9]{64}$/i.test(pubkey); + } + + /** + * Sanitize filters by removing invalid pubkeys to prevent relay errors + */ + private sanitizeFilters(filters: Filter[]): Filter[] { + return filters.map(filter => { + if (filter.authors && filter.authors.length > 0) { + // Filter out invalid pubkeys + const validAuthors = filter.authors.filter(author => this.isValidPubkey(author)); + if (validAuthors.length === 0) { + // If no valid authors remain, remove the authors field entirely + const { authors, ...rest } = filter; + return rest; + } + return { ...filter, authors: validAuthors }; + } + return filter; + }).filter(filter => { + // Remove filters that have no valid query parameters + return (filter.ids && filter.ids.length > 0) || + (filter.authors && filter.authors.length > 0) || + (filter.kinds && filter.kinds.length > 0) || + (filter['#e'] && filter['#e'].length > 0) || + (filter['#p'] && filter['#p'].length > 0) || + (filter['#d'] && filter['#d'].length > 0) || + filter.since !== undefined || + filter.until !== undefined || + filter.search !== undefined; + }); + } + async fetchEvents( filters: Filter[], relays: string[], options: FetchOptions = {} ): Promise { + // Sanitize filters to remove invalid pubkeys before processing + filters = this.sanitizeFilters(filters); + + // If all filters were invalid, return empty array + if (filters.length === 0) { + return []; + } + const { cacheResults = true, onUpdate, timeout = 10000, priority = 'medium', caller: providedCaller } = options; const caller = providedCaller || this.getCallerInfo(); diff --git a/src/routes/api/gitea-proxy/[...path]/+server.ts b/src/routes/api/gitea-proxy/[...path]/+server.ts index 3b337e7..07a71d0 100644 --- a/src/routes/api/gitea-proxy/[...path]/+server.ts +++ b/src/routes/api/gitea-proxy/[...path]/+server.ts @@ -275,7 +275,8 @@ function buildTargetUrl(baseUrl: string, apiPath: string, searchParams: URLSearc export const GET: RequestHandler = async ({ params, url }) => { try { const baseUrl = url.searchParams.get('baseUrl'); - const apiPath = params.path; + // params.path might be a string or array depending on SvelteKit version + const apiPath = Array.isArray(params.path) ? params.path.join('/') : params.path; if (!baseUrl) { return createErrorResponse('Missing baseUrl query parameter', 400); @@ -303,8 +304,26 @@ export const GET: RequestHandler = async ({ params, url }) => { // Log error responses for debugging if (!response.ok) { - console.error('[Gitea Proxy] Error response:', response.status, response.statusText); - console.error('[Gitea Proxy] Response body:', body.substring(0, 500)); + // Skip logging 404s for README file requests - these are expected when trying multiple file extensions + const isReadmeRequest = apiPath.includes('contents') && + (apiPath.toLowerCase().includes('readme') || apiPath.toLowerCase().includes('readme')); + + if (response.status === 404 && isReadmeRequest) { + // Silently skip - expected when trying README.adoc, README.md, etc. + } else if (response.status === 404) { + // Log other 404s with context + console.warn('[Gitea Proxy] 404 Not Found:', { + apiPath, + targetUrl, + baseUrl, + body: body.substring(0, 200) + }); + } else { + // Log non-404 errors + console.error('[Gitea Proxy] Error response:', response.status, response.statusText); + console.error('[Gitea Proxy] Request URL:', targetUrl); + console.error('[Gitea Proxy] Response body:', body.substring(0, 500)); + } } return new Response(body, {