응원가 영구 보존·종료 경기 노출 — 음원 DB 저장 + 경기별 조회 API
- Suno CDN 임시 URL 만료 대비: 완성 곡 첫 트랙을 워커가 다운로드해
song_audio(bytea)로 보존하고 audioUrl을 /api/songs/audio/{id}/{idx}로 재작성
(틱당 5곡, 실패 3회 상한 — 기존 곡도 자동 백필)
- GET /api/songs/match/{match_id} 추가 — 날짜 무관 조회로 종료된 경기
상세에서도 '응원가 듣기' 버튼 노출
- 프론트 getTeamSongTracks를 오늘 전체 캐시 → 경기별 조회·캐시로 전환
- 음원 서빙은 Range(206) 지원, immutable 캐시 + task_id 캐시버스터
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc333d64f4
commit
fdb04a2ccc
5 files changed
+186
-26
No files matched your search
@@ -64,6 +64,11 @@ export function getTodaySongs(league = ""): Promise<SongOut[]> {
|
||||
return http<SongOut[]>(`/songs/today${league ? `?league=${league}` : ""}`);
|
||||
}
|
||||
|
||||
// 경기별 응원가 — 날짜 무관이라 종료된 경기 상세에서도 곡이 나온다
|
||||
export function getMatchSongs(matchId: string): Promise<SongOut[]> {
|
||||
return http<SongOut[]>(`/songs/match/${matchId}`);
|
||||
}
|
||||
|
||||
export function listMatches(lang: Lang, league = ""): Promise<Match[]> {
|
||||
return http<Match[]>(`/matches?lang=${lang}${league ? `&league=${league}` : ""}`);
|
||||
}
|
||||
|
||||
@@ -25,27 +25,19 @@ export function getTracksForPath(pathname: string): Track[] {
|
||||
}
|
||||
|
||||
// ── 오늘의 응원가 (백엔드 Suno 자동 생성) ─────────────────────
|
||||
// 하루 단위 캐시 — 같은 세션에서 경로 이동마다 재요청하지 않는다.
|
||||
import { getTodaySongs, type SongOut } from "./api";
|
||||
// 경기 단위 조회·캐시 — 날짜 무관이라 종료된 경기 상세에서도 곡이 나온다.
|
||||
import { getMatchSongs, type SongOut } from "./api";
|
||||
|
||||
let songsPromise: Promise<SongOut[]> | null = null;
|
||||
let songsDay = "";
|
||||
let songsAt = 0;
|
||||
// 곡은 라인업 반영 재생성으로 당일 중에도 교체되므로 짧은 TTL 로 재조회
|
||||
const SONGS_TTL_MS = 5 * 60_000;
|
||||
const matchSongsCache = new Map<string, { at: number; p: Promise<SongOut[]> }>();
|
||||
|
||||
function todayKstKey(): string {
|
||||
return new Date(Date.now() + 9 * 3600_000).toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function fetchSongsCached(): Promise<SongOut[]> {
|
||||
const day = todayKstKey();
|
||||
if (!songsPromise || songsDay !== day || Date.now() - songsAt > SONGS_TTL_MS) {
|
||||
songsDay = day;
|
||||
songsAt = Date.now();
|
||||
songsPromise = getTodaySongs().catch(() => []); // 전 리그
|
||||
}
|
||||
return songsPromise;
|
||||
function fetchMatchSongsCached(matchId: string): Promise<SongOut[]> {
|
||||
const hit = matchSongsCache.get(matchId);
|
||||
if (hit && Date.now() - hit.at <= SONGS_TTL_MS) return hit.p;
|
||||
const p = getMatchSongs(matchId).catch(() => []);
|
||||
matchSongsCache.set(matchId, { at: Date.now(), p });
|
||||
return p;
|
||||
}
|
||||
|
||||
function songToTracks(s: SongOut): Track[] {
|
||||
@@ -66,13 +58,13 @@ function songToTracks(s: SongOut): Track[] {
|
||||
}));
|
||||
}
|
||||
|
||||
// 특정 경기·팀의 오늘의 응원가 트랙 — 상세 페이지 '응원가 듣기' 버튼용.
|
||||
// 전 팀 동일 로직(그날 생성곡만). 곡이 없으면 빈 배열.
|
||||
// 특정 경기·팀의 응원가 트랙 — 상세 페이지 '응원가 듣기' 버튼용.
|
||||
// 종료된 경기도 그날 생성곡을 그대로 노출한다. 곡이 없으면 빈 배열.
|
||||
export async function getTeamSongTracks(
|
||||
matchId: string,
|
||||
teamCode: string,
|
||||
): Promise<Track[]> {
|
||||
const songs = await fetchSongsCached();
|
||||
const songs = await fetchMatchSongsCached(matchId);
|
||||
return songs
|
||||
.filter((s) => s.matchId === matchId && s.teamCode === teamCode)
|
||||
.flatMap(songToTracks);
|
||||
|
||||
Reference in new issue
Block a user