From 46c2c3fb28e7e7b434f40db5750556e5d57e8438 Mon Sep 17 00:00:00 2001 From: benya Date: Thu, 2 Apr 2026 22:29:04 +0300 Subject: [PATCH] feat: import library from media root and stream tracks Add a filesystem scanner that ingests supported audio files from MEDIA_ROOT into SQLite using embedded tags with filename fallbacks. Wire startup scanning, manual rescan, and authenticated audio streaming into the backend, then connect the web player to the real stream endpoint. --- .gitignore | 1 + apps/web/src/components/player-bar.tsx | 18 +- cmd/server/main.go | 12 +- go.mod | 1 + go.sum | 2 + internal/auth/service.go | 4 + internal/db/seed.go | 23 +- internal/httpapi/router.go | 52 +++- internal/library/service.go | 31 +++ internal/scanner/service.go | 329 +++++++++++++++++++++++++ 10 files changed, 468 insertions(+), 5 deletions(-) create mode 100644 internal/scanner/service.go diff --git a/.gitignore b/.gitignore index 5505499..3a25a46 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ dist/ build/ .vite/ *.tsbuildinfo +data/ server.exe .DS_Store .env diff --git a/apps/web/src/components/player-bar.tsx b/apps/web/src/components/player-bar.tsx index 54feb62..40ac6b7 100644 --- a/apps/web/src/components/player-bar.tsx +++ b/apps/web/src/components/player-bar.tsx @@ -1,16 +1,31 @@ +import { useEffect, useRef } from 'react' import { Pause, Play, SkipBack, SkipForward, Volume2 } from 'lucide-react' import { usePlayerStore } from '@/stores/player-store' +import { useSessionStore } from '@/stores/session-store' export function PlayerBar() { const currentTrack = usePlayerStore((state) => state.currentTrack) + const token = useSessionStore((state) => state.token) + const audioRef = useRef(null) + const apiBase = import.meta.env.VITE_API_BASE ?? 'http://localhost:4040' + + useEffect(() => { + if (!audioRef.current || !currentTrack || !token) { + return + } + + audioRef.current.src = `${apiBase}/api/stream/${currentTrack.id}?token=${token}` + void audioRef.current.play().catch(() => {}) + }, [apiBase, currentTrack, token]) return (
+