| import type { UvifyResult } from '../types/uvify'; | |
| const API_BASE_URL = import.meta.env.VITE_API_URL || (import.meta.env.PROD ? '' : 'http://localhost:8000'); | |
| export const analyzeRepository = async (source: string): Promise<UvifyResult[]> => { | |
| try { | |
| // Clean up the source input | |
| let cleanSource = source.trim(); | |
| // Remove https://github.com/ prefix if present | |
| if (cleanSource.startsWith('https://github.com/')) { | |
| cleanSource = cleanSource.replace('https://github.com/', ''); | |
| } | |
| // Remove trailing .git if present | |
| if (cleanSource.endsWith('.git')) { | |
| cleanSource = cleanSource.slice(0, -4); | |
| } | |
| // Make the API call to the mounted API endpoint | |
| const response = await fetch(`${API_BASE_URL}/api/${cleanSource}`); | |
| if (!response.ok) { | |
| const errorText = await response.text(); | |
| throw new Error(errorText || `HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| return data; | |
| } catch (error) { | |
| if (error instanceof Error) { | |
| throw error; | |
| } | |
| throw new Error('An unexpected error occurred'); | |
| } | |
| }; |