feat: initial scaffold for ClickTrack monorepo
Full self-hosted click track generator for cover bands. Core technical pieces implemented: - CTP (Click Track Protocol) TypeScript schema, Zod validator, and WAV renderer (44.1 kHz, 16-bit PCM, accented downbeats, ramp sections) - MusicBrainz API client with 1 req/s rate limiting - PostgreSQL schema (songs, tempo_maps, registry_sync_log) with triggers - Git registry sync logic (clone/pull → validate CTP → upsert DB) - Next.js 14 App Router: search page, track page, API routes (/api/songs, /api/tracks, /api/generate) - UI components: SearchBar, SongResult, TempoMapEditor, ClickTrackPlayer (Web Audio API in-browser playback + WAV download) - Docker Compose stack: app + postgres + redis + nginx + registry-sync - Multi-stage Dockerfile with standalone Next.js output - .env.example documenting all configuration variables - README with setup instructions, CTP format spec, and API reference Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
49
app/api/songs/route.ts
Normal file
49
app/api/songs/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { searchSongs as searchSongsDB, upsertSong } from "@/lib/db/client";
|
||||
import { searchSongs as searchMB } from "@/lib/musicbrainz/client";
|
||||
import { z } from "zod";
|
||||
|
||||
const QuerySchema = z.object({
|
||||
q: z.string().min(1).max(200),
|
||||
limit: z.coerce.number().int().min(1).max(50).default(20),
|
||||
});
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const params = Object.fromEntries(req.nextUrl.searchParams);
|
||||
const parsed = QuerySchema.safeParse(params);
|
||||
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid query parameters", details: parsed.error.flatten() },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { q, limit } = parsed.data;
|
||||
|
||||
// Try local DB first
|
||||
let songs = await searchSongsDB(q, limit);
|
||||
|
||||
// Augment from MusicBrainz when local results are thin
|
||||
if (songs.length < 3) {
|
||||
try {
|
||||
const mbResults = await searchMB(q, limit);
|
||||
for (const s of mbResults) {
|
||||
await upsertSong({
|
||||
mbid: s.mbid,
|
||||
title: s.title,
|
||||
artist: s.artist,
|
||||
duration_seconds: s.duration_seconds,
|
||||
acousticbrainz_bpm: null,
|
||||
acousticbrainz_time_sig_num: null,
|
||||
source: "musicbrainz",
|
||||
});
|
||||
}
|
||||
songs = await searchSongsDB(q, limit);
|
||||
} catch (err) {
|
||||
console.error("[songs] MusicBrainz search failed:", err);
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ songs, total: songs.length });
|
||||
}
|
||||
Reference in New Issue
Block a user