diff --git a/lib/nip95.ts b/lib/nip95.ts index aa57575..27afe70 100644 --- a/lib/nip95.ts +++ b/lib/nip95.ts @@ -124,42 +124,15 @@ export async function uploadNip95Media(file: File): Promise { let lastError: Error | null = null for (const endpoint of endpoints) { try { - // Try direct upload first - const url = await tryUploadEndpoint(endpoint, formData, false) + // Always use proxy to avoid CORS, 405, and name resolution issues + // Pass endpoint as query parameter to proxy + const proxyUrl = `/api/nip95-upload?endpoint=${encodeURIComponent(endpoint)}` + const url = await tryUploadEndpoint(proxyUrl, formData, true) return { url, type: mediaType } } catch (e) { const error = e instanceof Error ? e : new Error(String(e)) const errorMessage = error.message - // If CORS error, network error, 405 error, or name resolution error, try via proxy - const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('Failed to fetch') - const isMethodNotAllowed = errorMessage.includes('405') || errorMessage.includes('Method Not Allowed') - const isNameResolutionError = errorMessage.includes('ERR_NAME_NOT_RESOLVED') || errorMessage.includes('getaddrinfo') - const shouldUseProxy = isCorsError || isMethodNotAllowed || isNameResolutionError - - if (shouldUseProxy) { - try { - console.log('Trying upload via proxy due to error:', endpoint, { - CORS: isCorsError, - 'Method Not Allowed': isMethodNotAllowed, - 'Name Resolution': isNameResolutionError, - }) - // Pass endpoint as query parameter to proxy - const proxyUrl = `/api/nip95-upload?endpoint=${encodeURIComponent(endpoint)}` - const url = await tryUploadEndpoint(proxyUrl, formData, true) - return { url, type: mediaType } - } catch (proxyError) { - console.error('NIP-95 upload proxy error:', { - endpoint, - error: proxyError instanceof Error ? proxyError.message : String(proxyError), - fileSize: file.size, - fileType: file.type, - }) - lastError = proxyError instanceof Error ? proxyError : new Error(String(proxyError)) - continue - } - } - console.error('NIP-95 upload endpoint error:', { endpoint, error: errorMessage,