- Fix .gitignore to exclude only backend/lib/, not frontend/lib/ - Add frontend/lib/ files (api.ts, types.ts, utils.ts) to git - Add .dockerignore to frontend to exclude build artifacts - Update backend Dockerfile to Python 3.9 with ARM64 support - Add debug to frontend Dockerfile - Update claude-todo with current project state This fixes "Module not found: Can't resolve '@/lib/api'" error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
104 lines
2.7 KiB
TypeScript
104 lines
2.7 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'
|
|
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
|
|
|
|
const apiClient = axios.create({
|
|
baseURL: API_BASE_URL,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
|
|
// Tracks
|
|
export async function getTracks(params: FilterParams & { skip?: number; limit?: number }): Promise<TracksResponse> {
|
|
const response = await apiClient.get('/api/tracks', { params })
|
|
return response.data
|
|
}
|
|
|
|
export async function getTrack(id: string): Promise<Track> {
|
|
const response = await apiClient.get(`/api/tracks/${id}`)
|
|
return response.data
|
|
}
|
|
|
|
export async function deleteTrack(id: string): Promise<void> {
|
|
await apiClient.delete(`/api/tracks/${id}`)
|
|
}
|
|
|
|
// Search
|
|
export async function searchTracks(
|
|
query: string,
|
|
filters?: { genre?: string; mood?: string; limit?: number }
|
|
): Promise<SearchResponse> {
|
|
const response = await apiClient.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 apiClient.get(`/api/tracks/${id}/similar`, {
|
|
params: { limit },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Analysis
|
|
export async function analyzeFolder(request: AnalyzeFolderRequest): Promise<{ job_id: string }> {
|
|
const response = await apiClient.post('/api/analyze/folder', request)
|
|
return response.data
|
|
}
|
|
|
|
export async function getAnalyzeStatus(jobId: string): Promise<JobStatus> {
|
|
const response = await apiClient.get(`/api/analyze/status/${jobId}`)
|
|
return response.data
|
|
}
|
|
|
|
export async function deleteJob(jobId: string): Promise<void> {
|
|
await apiClient.delete(`/api/analyze/job/${jobId}`)
|
|
}
|
|
|
|
// Audio
|
|
export function getStreamUrl(trackId: string): string {
|
|
return `${API_BASE_URL}/api/audio/stream/${trackId}`
|
|
}
|
|
|
|
export function getDownloadUrl(trackId: string): string {
|
|
return `${API_BASE_URL}/api/audio/download/${trackId}`
|
|
}
|
|
|
|
export async function getWaveform(trackId: string, numPeaks: number = 800): Promise<WaveformData> {
|
|
const response = await apiClient.get(`/api/audio/waveform/${trackId}`, {
|
|
params: { num_peaks: numPeaks },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Stats
|
|
export async function getStats(): Promise<Stats> {
|
|
const response = await apiClient.get('/api/stats')
|
|
return response.data
|
|
}
|
|
|
|
// Health
|
|
export async function healthCheck(): Promise<{ status: string }> {
|
|
const response = await apiClient.get('/health')
|
|
return response.data
|
|
}
|
|
|
|
export default apiClient
|