All checks were successful
Build and Push Docker Images / Build Frontend Image (push) Successful in 3m59s
Problème: Le frontend utilisait localhost:8001 au lieu de l'URL de production car NEXT_PUBLIC_API_URL était évalué au build time et non au runtime. Changements: 1. Frontend (api.ts): - Remplace apiClient statique par getApiClient() dynamique - Chaque appel crée une instance axios avec l'URL runtime - getStreamUrl/getDownloadUrl utilisent getApiUrl() au lieu de API_BASE_URL - Supprime l'export default apiClient (non utilisé) 2. Docker Compose: - Configure NEXT_PUBLIC_API_URL=https://api.audioclassifier.benoitsz.com - Simplifie la config (retire le fallback) Le runtime config (window.__RUNTIME_CONFIG__) fonctionne maintenant correctement car il est évalué à chaque appel API côté client. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
/**
|
|
* API client for Audio Classifier backend
|
|
*/
|
|
import axios from 'axios'
|
|
import type {
|
|
Track,
|
|
TracksResponse,
|
|
SearchResponse,
|
|
SimilarTracksResponse,
|
|
JobStatus,
|
|
AnalyzeFolderRequest,
|
|
WaveformData,
|
|
Stats,
|
|
FilterParams,
|
|
} from './types'
|
|
|
|
// Get API URL from runtime config (injected at container startup) or fallback to env var
|
|
function getApiUrl(): string {
|
|
if (typeof window !== 'undefined' && (window as any).__RUNTIME_CONFIG__) {
|
|
return (window as any).__RUNTIME_CONFIG__.API_URL
|
|
}
|
|
return process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
|
|
}
|
|
|
|
// Create axios instance dynamically to use runtime config
|
|
function getApiClient() {
|
|
return axios.create({
|
|
baseURL: getApiUrl(),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
}
|
|
|
|
// Tracks
|
|
export async function getTracks(params: FilterParams & { skip?: number; limit?: number }): Promise<TracksResponse> {
|
|
const response = await getApiClient().get('/api/tracks', { params })
|
|
return response.data
|
|
}
|
|
|
|
export async function getTrack(id: string): Promise<Track> {
|
|
const response = await getApiClient().get(`/api/tracks/${id}`)
|
|
return response.data
|
|
}
|
|
|
|
export async function deleteTrack(id: string): Promise<void> {
|
|
await getApiClient().delete(`/api/tracks/${id}`)
|
|
}
|
|
|
|
// Search
|
|
export async function searchTracks(
|
|
query: string,
|
|
filters?: { genre?: string; mood?: string; limit?: number }
|
|
): Promise<SearchResponse> {
|
|
const response = await getApiClient().get('/api/search', {
|
|
params: { q: query, ...filters },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Similar
|
|
export async function getSimilarTracks(id: string, limit: number = 10): Promise<SimilarTracksResponse> {
|
|
const response = await getApiClient().get(`/api/tracks/${id}/similar`, {
|
|
params: { limit },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Analysis
|
|
export async function analyzeFolder(request: AnalyzeFolderRequest): Promise<{ job_id: string }> {
|
|
const response = await getApiClient().post('/api/analyze/folder', request)
|
|
return response.data
|
|
}
|
|
|
|
export async function getAnalyzeStatus(jobId: string): Promise<JobStatus> {
|
|
const response = await getApiClient().get(`/api/analyze/status/${jobId}`)
|
|
return response.data
|
|
}
|
|
|
|
export async function deleteJob(jobId: string): Promise<void> {
|
|
await getApiClient().delete(`/api/analyze/job/${jobId}`)
|
|
}
|
|
|
|
// Audio
|
|
export function getStreamUrl(trackId: string): string {
|
|
return `${getApiUrl()}/api/audio/stream/${trackId}`
|
|
}
|
|
|
|
export function getDownloadUrl(trackId: string): string {
|
|
return `${getApiUrl()}/api/audio/download/${trackId}`
|
|
}
|
|
|
|
export async function getWaveform(trackId: string, numPeaks: number = 800): Promise<WaveformData> {
|
|
const response = await getApiClient().get(`/api/audio/waveform/${trackId}`, {
|
|
params: { num_peaks: numPeaks },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Stats
|
|
export async function getStats(): Promise<Stats> {
|
|
const response = await getApiClient().get('/api/stats')
|
|
return response.data
|
|
}
|
|
|
|
// Health
|
|
export async function healthCheck(): Promise<{ status: string }> {
|
|
const response = await getApiClient().get('/health')
|
|
return response.data
|
|
}
|