Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
95558ab
chore: 자막 추출용 youtubei.js 의존성 추가
Dino0204 Jun 29, 2026
a2e2977
feat: 자막 데이터 검증용 web-llm 의존성 추가
Dino0204 Jun 29, 2026
7052355
feat: AI 분석 권한 설정 및 쿼리 추가
Dino0204 Jun 29, 2026
61f839b
feat: 유튜브 자막 가져오기
Dino0204 Jun 29, 2026
38ddc15
feat: 메인 스레드 중단 방지용 llm worker
Dino0204 Jun 29, 2026
4c059e9
change: 한국어를 우선순위로 변경
Dino0204 Jun 29, 2026
633d655
feat: 기상음악 훅에 권한 설정
Dino0204 Jun 29, 2026
a83edd9
refactor: 기상음악 추천 기능을 wake-up-music-recommend로 분리
Dino0204 Jun 29, 2026
41a6163
refactor: 기상음악 AI 분석 모듈을 wake-up-music-analysis로 구성
Dino0204 Jun 29, 2026
3c1e5c9
refactor: 기상음악 AI 분석 표시 컴포넌트 분리
Dino0204 Jun 29, 2026
af2da85
refactor: 음악 리스트 아이템에 선택·AI 상태 슬롯 추가
Dino0204 Jun 29, 2026
d77dfca
feat: 기상음악 크게 보기에 AI 분석·인앱 플레이어 추가
Dino0204 Jun 29, 2026
ee884a7
change: 기상음악 권한·훅 정리 (사감 AI 분석 제한, 미사용 날짜 헬퍼 제거)
Dino0204 Jun 29, 2026
a09f3de
fix: 기상음악 자막·캐시·선택표시 리뷰 반영
Dino0204 Jun 29, 2026
ea58171
fix: 플레이어 너비 제한
Dino0204 Jun 29, 2026
f76ed7f
fear: AI 면책 문구 추가
Dino0204 Jun 29, 2026
822e22c
feat: 자동 생성 자막 감지 및 배지 표시
Dino0204 Jun 30, 2026
cb2fa23
change: NoteText 다중 줄 옵션 추가
Dino0204 Jun 30, 2026
e02fdcd
refactor: AI 분석 결과 패널을 상태별 컴포넌트로 분리
Dino0204 Jun 30, 2026
38f8ed0
refactor: AI 모델 로드 상태를 단일 출처로 분리
Dino0204 Jun 30, 2026
55b379e
change: 크게 보기 플레이어 UI 개선
Dino0204 Jun 30, 2026
7dc1f7f
chore: 포맷
Dino0204 Jun 30, 2026
3a27c74
feat: yt-dlp docker image
Dino0204 Jun 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ ENV NODE_ENV=production \
PORT=3000 \
HOSTNAME=0.0.0.0

# yt-dlp
ADD https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux /usr/local/bin/yt-dlp
RUN chmod a+rx /usr/local/bin/yt-dlp

RUN groupadd -r nodejs && useradd -r -g nodejs nextjs

# public assets + standalone server + static chunks
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Header } from "@/widgets/header/ui/header";
import { AiChatButton } from "@/features/ai-chat/ui/AiChatButton";
import { AiChatModal } from "@/features/ai-chat/ui/AiChatModal";
import { useAiChatPanel } from "@/features/ai-chat/model/useAiChatPanel";
import { WakeUpMusicRecommend } from "@/features/wake-up-music/ui/WakeUpMusicRecommend";
import { WakeUpMusicRecommend } from "@/features/wake-up-music-recommend/ui/WakeUpMusicRecommend";
import { RealtimeSubscriptions } from "@/widgets/realtime-subscription/ui/RealtimeSubscriptions";

export default function MainLayout({
Expand Down
42 changes: 42 additions & 0 deletions app/api/youtube/transcript/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { HttpStatusCode } from "axios";
import { NextRequest, NextResponse } from "next/server";
import { extractYoutubeVideoId } from "@/entities/music/lib/youtube";
import { getYoutubeTranscript } from "@/entities/music/lib/transcript";

export const runtime = "nodejs";

export async function GET(request: NextRequest) {
const authorization = request.headers.get("authorization");
const accessToken = authorization?.startsWith("Bearer ")
? authorization.slice("Bearer ".length)
: null;

if (!accessToken) {
return NextResponse.json(
{ error: "access token 없음" },
{ status: HttpStatusCode.Unauthorized },
);
}
Comment thread
Dino0204 marked this conversation as resolved.

const params = request.nextUrl.searchParams;
const urlParam = params.get("url");
const idParam = params.get("id");
const videoId =
idParam ?? (urlParam ? extractYoutubeVideoId(urlParam) : null);

const youtubeIdRegex = /^[a-zA-Z0-9_-]{11}$/;
if (!videoId || !youtubeIdRegex.test(videoId)) {
return NextResponse.json(
{ error: "올바른 형식의 videoId(id) 또는 url이 필요합니다." },
{ status: HttpStatusCode.BadRequest },
);
}
Comment thread
Dino0204 marked this conversation as resolved.

const result = await getYoutubeTranscript(videoId);

if ("error" in result) {
return NextResponse.json(result, { status: HttpStatusCode.NotFound });
}

return NextResponse.json(result);
}
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"format:check": "prettier --check --ignore-unknown ."
},
"dependencies": {
"@mlc-ai/web-llm": "^0.2.84",
"@sentry/nextjs": "^10.53.1",
"@sun-typeface/suit": "^2.0.5",
"@tanstack/react-query": "^5.90.20",
Expand Down
7 changes: 7 additions & 0 deletions src/entities/ai/lib/webllm.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { WebWorkerMLCEngineHandler } from "@mlc-ai/web-llm";

const handler = new WebWorkerMLCEngineHandler();

self.onmessage = (event: MessageEvent) => {
handler.onmessage(event);
};
94 changes: 94 additions & 0 deletions src/entities/ai/lib/webllmEngine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { WebWorkerMLCEngine } from "@mlc-ai/web-llm";

export const MUSIC_LLM_MODEL_ID = "gemma-2-2b-it-q4f16_1-MLC";

export type ModelState =
| { status: "idle" }
| { status: "loading"; progress: number }
| { status: "ready" }
| { status: "error"; message: string };

const WEBGPU_UNSUPPORTED_MESSAGE =
"이 브라우저/기기에서 WebGPU를 사용할 수 없습니다.";

let enginePromise: Promise<WebWorkerMLCEngine> | null = null;
let modelState: ModelState = { status: "idle" };
const listeners = new Set<() => void>();

function setModelState(next: ModelState) {
modelState = next;
listeners.forEach((listener) => listener());
}

export function subscribeModelState(listener: () => void): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}

export function getModelStateSnapshot(): ModelState {
return modelState;
}

export async function ensureWebGpuSupport(): Promise<void> {
if (modelState.status !== "idle") return;

const gpu = (
navigator as Navigator & {
gpu?: { requestAdapter: () => Promise<unknown> };
}
).gpu;

if (!gpu) {
setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE });
return;
}

try {
const adapter = await gpu.requestAdapter();
if (!adapter) {
setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE });
}
} catch {
setModelState({ status: "error", message: WEBGPU_UNSUPPORTED_MESSAGE });
}
}

export function getMusicLlmEngine(): Promise<WebWorkerMLCEngine> {
if (!enginePromise) {
setModelState({ status: "loading", progress: 0 });
enginePromise = (async () => {
const { CreateWebWorkerMLCEngine } = await import("@mlc-ai/web-llm");
const worker = new Worker(
new URL("./webllm.worker.ts", import.meta.url),
{
type: "module",
},
);

const engine = await CreateWebWorkerMLCEngine(
worker,
MUSIC_LLM_MODEL_ID,
{
initProgressCallback: (report) =>
setModelState({ status: "loading", progress: report.progress }),
},
);
setModelState({ status: "ready" });
return engine;
})().catch((error) => {
enginePromise = null;
const reason = error instanceof Error ? error.message : String(error);
setModelState({
status: "error",
message: reason.includes("WebGPU")
? WEBGPU_UNSUPPORTED_MESSAGE
: "AI 모델을 불러오지 못했습니다.",
});
throw error;
});
}

return enginePromise;
}
16 changes: 16 additions & 0 deletions src/entities/ai/model/useModelState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import { useSyncExternalStore } from "react";
import {
getModelStateSnapshot,
subscribeModelState,
type ModelState,
} from "@/entities/ai/lib/webllmEngine";

export function useModelState(): ModelState {
return useSyncExternalStore(
subscribeModelState,
getModelStateSnapshot,
getModelStateSnapshot,
);
}
16 changes: 14 additions & 2 deletions src/entities/dormitory/lib/musicPermission.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import type { UserRole } from "@/entities/user/model/user";

// 기자위(DORMITORY_MANAGER) 중 AI 분석을 쓸 수 있는 사감 계정 이름
const DORM_SUPERVISOR_NAME = "사감선생님";

interface CreateMusicPermissionParams {
role?: UserRole;
name?: string;
}

export function createMusicPermission({ role }: CreateMusicPermissionParams) {
export function createMusicPermission({
role,
name,
}: CreateMusicPermissionParams) {
const isDormManager = role === "DORMITORY_MANAGER";

return {
canDeleteAnyMusic: role === "ADMIN" || role === "DORMITORY_MANAGER",
canDeleteAnyMusic: role === "ADMIN" || isDormManager,
// 어드민은 모두 가능, 기자위는 사감선생님만 가능
canUseAiAnalysis:
role === "ADMIN" || (isDormManager && name === DORM_SUPERVISOR_NAME),
Comment thread
Dino0204 marked this conversation as resolved.
};
}
32 changes: 32 additions & 0 deletions src/entities/music/api/youtubeQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface YoutubeVideosResponse {
videos: YoutubeVideoMetadata[];
}

export interface YoutubeTranscript {
text: string;
}

export async function getYoutubeVideos(
videoIds: string[],
signal?: AbortSignal,
Expand All @@ -35,6 +39,25 @@ export async function getYoutubeVideos(
return Object.fromEntries(data.videos.map((video) => [video.id, video]));
}

const TRANSCRIPT_TIMEOUT_MS = 65_000;

export async function getYoutubeTranscript(
videoId: string,
signal?: AbortSignal,
): Promise<YoutubeTranscript> {
const { data } = await instance.get<YoutubeTranscript>(
"/api/youtube/transcript",
{
baseURL: undefined,
params: { id: videoId },
timeout: TRANSCRIPT_TIMEOUT_MS,
signal,
},
);

return data;
}

export const youtubeQueries = {
videos: (videoIds: string[]) => {
const ids = Array.from(new Set(videoIds)).sort();
Expand All @@ -45,4 +68,13 @@ export const youtubeQueries = {
enabled: ids.length > 0,
});
},

transcript: (videoId: string) =>
queryOptions({
queryKey: ["music", "youtube-transcript", videoId],
queryFn: ({ signal }) => getYoutubeTranscript(videoId, signal),
enabled: Boolean(videoId),
staleTime: Infinity,
gcTime: Infinity,
}),
} as const;
Loading
Loading