Compare commits

...

6 Commits

Author SHA1 Message Date
6ae861ff54 Actualiser .gitea/workflows/docker.yml
All checks were successful
Build and Push Docker Images / Build Backend Image (push) Successful in 12m28s
Build and Push Docker Images / Build Frontend Image (push) Successful in 58s
Remise en état build backend
2025-12-26 00:15:54 +01:00
b74c6b0b40 Fix scan infini: exclure dossiers transcoded et waveforms
All checks were successful
Build and Push Docker Images / Build Frontend Image (push) Successful in 57s
Problème: Le scanner scannait TOUS les dossiers, y compris les dossiers
générés (transcoded/ et waveforms/), créant:
1. Boucle infinie: scan original → crée transcoded → re-scan transcoded
2. Segfaults: tentative de transcoder des fichiers déjà transcodés
3. Doublons en base de données

Solution:
- library.py: Exclut transcoded, waveforms, .transcoded, .waveforms
- scanner.py: Même exclusion dans le CLI

Technique: Modifie dirs[:] dans os.walk() pour skip ces dossiers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 00:08:13 +01:00
4d8fa57ab2 Fix tous les appels API pour utiliser getApiUrl() au lieu de process.env
All checks were successful
Build and Push Docker Images / Build Frontend Image (push) Successful in 3m31s
Problème: Le commit précédent n'avait corrigé que api.ts, mais AudioPlayer
et page.tsx utilisaient encore directement process.env.NEXT_PUBLIC_API_URL,
ce qui ignorait la config runtime.

Fichiers corrigés:
1. lib/api.ts:
   - Export getApiUrl() pour usage externe

2. app/page.tsx:
   - Import getApiUrl
   - /api/library/scan: process.env → getApiUrl()
   - /api/library/scan/status: process.env → getApiUrl()

3. components/AudioPlayer.tsx:
   - Import getApiUrl
   - /api/audio/waveform: process.env → getApiUrl()
   - /api/audio/stream: process.env → getApiUrl()
   - /api/audio/download: process.env → getApiUrl()

Maintenant TOUS les appels API utilisent la config runtime
(window.__RUNTIME_CONFIG__) côté client.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-24 10:54:38 +01:00
36652ea2cc Fix API URL configuration pour production
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>
2025-12-24 10:12:38 +01:00
3b236d6af4 Merge pull request 'Fix localhost en prod' (#4) from prochains-changements into main
All checks were successful
Build and Push Docker Images / Build Frontend Image (push) Successful in 5m45s
Reviewed-on: #4
2025-12-23 15:34:34 +01:00
64ba7f9006 Merge pull request 'Fix CORS' (#3) from prochains-changements into main
All checks were successful
Build and Push Docker Images / Build Backend Image (push) Successful in 12m50s
Build and Push Docker Images / Build Frontend Image (push) Successful in 7m10s
Reviewed-on: #3
2025-12-23 14:34:05 +01:00
7 changed files with 126 additions and 33 deletions

View File

@@ -13,6 +13,95 @@ env:
IMAGE_FRONTEND: audio-classifier-frontend
jobs:
build-backend:
name: Build Backend Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Essentia models
run: |
mkdir -p backend/models
cd backend/models
# Download models from Essentia
echo "Downloading Essentia models..."
# Embedding model (18 MB)
curl -L -o discogs-effnet-bs64-1.pb \
https://essentia.upf.edu/models/feature-extractors/discogs-effnet/discogs-effnet-bs64-1.pb
# Genre classifier (2 MB)
curl -L -o genre_discogs400-discogs-effnet-1.pb \
https://essentia.upf.edu/models/classification-heads/genre_discogs400/genre_discogs400-discogs-effnet-1.pb
# Genre metadata
curl -L -o genre_discogs400-discogs-effnet-1.json \
https://essentia.upf.edu/models/classification-heads/genre_discogs400/genre_discogs400-discogs-effnet-1.json
# Mood classifier (2.7 MB)
curl -L -o mtg_jamendo_moodtheme-discogs-effnet-1.pb \
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_moodtheme/mtg_jamendo_moodtheme-discogs-effnet-1.pb
# Instrument classifier (2.6 MB)
curl -L -o mtg_jamendo_instrument-discogs-effnet-1.pb \
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_instrument/mtg_jamendo_instrument-discogs-effnet-1.pb
# Genre classifier alternative (2.7 MB)
curl -L -o mtg_jamendo_genre-discogs-effnet-1.pb \
https://essentia.upf.edu/models/classification-heads/mtg_jamendo_genre/mtg_jamendo_genre-discogs-effnet-1.pb
ls -lh
echo "Models downloaded successfully!"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Determine version
id: version
run: |
if [[ "${{ gitea.ref }}" == refs/tags/v* ]]; then
echo "VERSION=${GITEA_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ startsWith(gitea.ref, 'refs/tags/v') }}
type=raw,value=dev,enable=${{ gitea.ref == 'refs/heads/main' }}
type=sha,prefix=dev-,format=short,enable=${{ gitea.ref == 'refs/heads/main' }}
- name: Build and push backend
uses: docker/build-push-action@v5
with:
context: .
file: ./backend/Dockerfile
push: true
build-args: |
VERSION=${{ steps.version.outputs.VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_BACKEND }}:buildcache,mode=max
build-frontend:
name: Build Frontend Image
runs-on: ubuntu-latest

View File

@@ -41,6 +41,9 @@ def find_audio_files(directory: str) -> list[Path]:
return []
for root, dirs, files in os.walk(directory_path):
# Skip transcoded and waveforms directories
dirs[:] = [d for d in dirs if d not in ['transcoded', 'waveforms', '.transcoded', '.waveforms']]
for file in files:
file_path = Path(root) / file
if file_path.suffix.lower() in AUDIO_EXTENSIONS:

View File

@@ -46,6 +46,9 @@ def find_audio_files(directory: str) -> List[Path]:
logger.info(f"Scanning directory: {directory}")
for root, dirs, files in os.walk(directory_path):
# Skip transcoded and waveforms directories
dirs[:] = [d for d in dirs if d not in ['transcoded', 'waveforms', '.transcoded', '.waveforms']]
for file in files:
file_path = Path(root) / file
if file_path.suffix.lower() in AUDIO_EXTENSIONS:

View File

@@ -41,9 +41,7 @@ services:
image: git.benoitsz.com/benoit/audio-classifier-frontend:dev
container_name: audio_classifier_ui
environment:
# In production, set NEXT_PUBLIC_API_URL to your server's public URL
# Example: NEXT_PUBLIC_API_URL=https://yourserver.com:8001
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:8001}
NEXT_PUBLIC_API_URL: https://api.audioclassifier.benoitsz.com
ports:
- "3000:3000"
depends_on:

View File

@@ -2,7 +2,7 @@
import { useState, useMemo } from "react"
import { useQuery } from "@tanstack/react-query"
import { getTracks } from "@/lib/api"
import { getTracks, getApiUrl } from "@/lib/api"
import type { FilterParams, Track } from "@/lib/types"
import FilterPanel from "@/components/FilterPanel"
import AudioPlayer from "@/components/AudioPlayer"
@@ -90,7 +90,7 @@ export default function Home() {
setIsScanning(true)
setScanStatus("Démarrage du scan...")
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/library/scan`, {
const response = await fetch(`${getApiUrl()}/api/library/scan`, {
method: 'POST',
})
@@ -103,7 +103,7 @@ export default function Home() {
// Poll scan status
const pollInterval = setInterval(async () => {
try {
const statusResponse = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/library/scan/status`)
const statusResponse = await fetch(`${getApiUrl()}/api/library/scan/status`)
const status = await statusResponse.json()
if (!status.is_scanning) {

View File

@@ -2,6 +2,7 @@
import { useState, useRef, useEffect } from "react"
import type { Track } from "@/lib/types"
import { getApiUrl } from "@/lib/api"
interface AudioPlayerProps {
track: Track | null
@@ -79,7 +80,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
setIsLoadingWaveform(true)
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/audio/waveform/${trackId}`
`${getApiUrl()}/api/audio/waveform/${trackId}`
)
if (response.ok) {
const data = await response.json()
@@ -161,7 +162,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
return (
<div className="bg-gray-50 border-t border-gray-300 shadow-lg" style={{ height: '80px' }}>
{/* Hidden audio element */}
{track && <audio ref={audioRef} src={`${process.env.NEXT_PUBLIC_API_URL}/api/audio/stream/${track.id}`} />}
{track && <audio ref={audioRef} src={`${getApiUrl()}/api/audio/stream/${track.id}`} />}
<div className="h-full flex items-center gap-3 px-4">
{/* Play/Pause button */}
@@ -300,7 +301,7 @@ export default function AudioPlayer({ track, isPlaying, onPlayingChange }: Audio
{/* Download button */}
{track && (
<a
href={`${process.env.NEXT_PUBLIC_API_URL}/api/audio/download/${track.id}`}
href={`${getApiUrl()}/api/audio/download/${track.id}`}
download
className="w-8 h-8 flex items-center justify-center text-gray-600 hover:text-gray-900 transition-colors rounded hover:bg-gray-200 flex-shrink-0"
aria-label="Download"

View File

@@ -15,35 +15,36 @@ import type {
} from './types'
// Get API URL from runtime config (injected at container startup) or fallback to env var
function getApiUrl(): string {
export 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'
}
const API_BASE_URL = getApiUrl()
const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
})
// 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 apiClient.get('/api/tracks', { params })
const response = await getApiClient().get('/api/tracks', { params })
return response.data
}
export async function getTrack(id: string): Promise<Track> {
const response = await apiClient.get(`/api/tracks/${id}`)
const response = await getApiClient().get(`/api/tracks/${id}`)
return response.data
}
export async function deleteTrack(id: string): Promise<void> {
await apiClient.delete(`/api/tracks/${id}`)
await getApiClient().delete(`/api/tracks/${id}`)
}
// Search
@@ -51,7 +52,7 @@ export async function searchTracks(
query: string,
filters?: { genre?: string; mood?: string; limit?: number }
): Promise<SearchResponse> {
const response = await apiClient.get('/api/search', {
const response = await getApiClient().get('/api/search', {
params: { q: query, ...filters },
})
return response.data
@@ -59,7 +60,7 @@ export async function searchTracks(
// Similar
export async function getSimilarTracks(id: string, limit: number = 10): Promise<SimilarTracksResponse> {
const response = await apiClient.get(`/api/tracks/${id}/similar`, {
const response = await getApiClient().get(`/api/tracks/${id}/similar`, {
params: { limit },
})
return response.data
@@ -67,30 +68,30 @@ export async function getSimilarTracks(id: string, limit: number = 10): Promise<
// Analysis
export async function analyzeFolder(request: AnalyzeFolderRequest): Promise<{ job_id: string }> {
const response = await apiClient.post('/api/analyze/folder', request)
const response = await getApiClient().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}`)
const response = await getApiClient().get(`/api/analyze/status/${jobId}`)
return response.data
}
export async function deleteJob(jobId: string): Promise<void> {
await apiClient.delete(`/api/analyze/job/${jobId}`)
await getApiClient().delete(`/api/analyze/job/${jobId}`)
}
// Audio
export function getStreamUrl(trackId: string): string {
return `${API_BASE_URL}/api/audio/stream/${trackId}`
return `${getApiUrl()}/api/audio/stream/${trackId}`
}
export function getDownloadUrl(trackId: string): string {
return `${API_BASE_URL}/api/audio/download/${trackId}`
return `${getApiUrl()}/api/audio/download/${trackId}`
}
export async function getWaveform(trackId: string, numPeaks: number = 800): Promise<WaveformData> {
const response = await apiClient.get(`/api/audio/waveform/${trackId}`, {
const response = await getApiClient().get(`/api/audio/waveform/${trackId}`, {
params: { num_peaks: numPeaks },
})
return response.data
@@ -98,14 +99,12 @@ export async function getWaveform(trackId: string, numPeaks: number = 800): Prom
// Stats
export async function getStats(): Promise<Stats> {
const response = await apiClient.get('/api/stats')
const response = await getApiClient().get('/api/stats')
return response.data
}
// Health
export async function healthCheck(): Promise<{ status: string }> {
const response = await apiClient.get('/health')
const response = await getApiClient().get('/health')
return response.data
}
export default apiClient