fix frontend bug
This commit is contained in:
1 parent
a18f7a5c8b
commit
9bb46f7004
10 files changed
+83
-21
No files matched your search
@@ -14,8 +14,12 @@ def artifact_path(pipeline: str, task_id: str, name: str) -> str:
|
|||||||
return f"{pipeline}/{task_id}/{name}"
|
return f"{pipeline}/{task_id}/{name}"
|
||||||
|
|
||||||
|
|
||||||
async def store_bytes(pipeline: str, task_id: str, name: str, data: bytes) -> str:
|
async def store_bytes(pipeline: str, task_id: str, name: str, data: bytes, *,
|
||||||
return await blob.upload_bytes(data, artifact_path(pipeline, task_id, name))
|
download_as: str | None = None) -> str:
|
||||||
|
"""download_as를 주면 브라우저가 그 주소를 열 때 그 이름으로 내려받는다"""
|
||||||
|
return await blob.upload_bytes(
|
||||||
|
data, artifact_path(pipeline, task_id, name),
|
||||||
|
disposition=blob.as_attachment(download_as) if download_as else None)
|
||||||
|
|
||||||
|
|
||||||
async def store_image(pipeline: str, task_id: str, name: str, image: Image.Image) -> str:
|
async def store_image(pipeline: str, task_id: str, name: str, image: Image.Image) -> str:
|
||||||
|
|||||||
@@ -242,8 +242,9 @@ async def run_compose(session: AsyncSession, task: PlayreelTask) -> None:
|
|||||||
compose_longcut, poster, clip, timeline, narration, sections, band_info(meta),
|
compose_longcut, poster, clip, timeline, narration, sections, band_info(meta),
|
||||||
bgm_mp3=bgm, qr=Image.open(qr_path) if qr_path.exists() else None)
|
bgm_mp3=bgm, qr=Image.open(qr_path) if qr_path.exists() else None)
|
||||||
|
|
||||||
task.video_url = await store_bytes(PIPELINE, task.id,
|
filename = f"{task.slug}_30_v{task.version + 1}.mp4"
|
||||||
f"longcut_v{task.version + 1}.mp4", result.video)
|
task.video_url = await store_bytes(PIPELINE, task.id, filename, result.video,
|
||||||
|
download_as=filename)
|
||||||
task.scene_plan = result.plan.model_dump()
|
task.scene_plan = result.plan.model_dump()
|
||||||
task.video_duration = result.duration
|
task.video_duration = result.duration
|
||||||
task.video_frames = result.frames
|
task.video_frames = result.frames
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ async def run_narration_text(session: AsyncSession, task: PosterAliveTask) -> No
|
|||||||
task.narration_voice = answer.voice
|
task.narration_voice = answer.voice
|
||||||
task.bgm_style = answer.bgm_style.model_dump()
|
task.bgm_style = answer.bgm_style.model_dump()
|
||||||
task.poster_metadata = answer.metadata.model_dump()
|
task.poster_metadata = answer.metadata.model_dump()
|
||||||
|
# 올릴 때 이름을 안 줬으면 포스터에서 읽은 행사명이 이름이 된다
|
||||||
|
if not task.name:
|
||||||
|
task.name = answer.metadata.event_name
|
||||||
task.state = PosterAliveState.MOTION
|
task.state = PosterAliveState.MOTION
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
@@ -131,9 +134,11 @@ async def run_render(session: AsyncSession, task: PosterAliveTask) -> None:
|
|||||||
result = await asyncio.to_thread(render, clip, poster, narration=narration, bgm=bgm,
|
result = await asyncio.to_thread(render, clip, poster, narration=narration, bgm=bgm,
|
||||||
timeline=timeline)
|
timeline=timeline)
|
||||||
|
|
||||||
task.video_url = await store_bytes(PIPELINE, task.id, "final.mp4", result.video)
|
task.video_url = await store_bytes(PIPELINE, task.id, "final.mp4", result.video,
|
||||||
|
download_as=f"{task.name}.mp4")
|
||||||
task.thumbnail_url = await store_bytes(PIPELINE, task.id, "thumbnail.jpg",
|
task.thumbnail_url = await store_bytes(PIPELINE, task.id, "thumbnail.jpg",
|
||||||
result.thumbnail)
|
result.thumbnail,
|
||||||
|
download_as=f"{task.name}.jpg")
|
||||||
task.video_duration = result.duration
|
task.video_duration = result.duration
|
||||||
task.video_frames = result.frames
|
task.video_frames = result.frames
|
||||||
task.video_width = result.width
|
task.video_width = result.width
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ async def create(poster: UploadFile = File(...), name: str = Form(""),
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(422, "이미지 파일을 열 수 없습니다")
|
raise HTTPException(422, "이미지 파일을 열 수 없습니다")
|
||||||
|
|
||||||
task = await poster_alive.create_task(session, name.strip() or "이름 없는 행사", raw,
|
# 이름을 비워 두면 narration_text 가 포스터에서 읽은 행사명으로 채운다
|
||||||
skip_review=auto)
|
task = await poster_alive.create_task(session, name.strip(), raw, skip_review=auto)
|
||||||
return {"id": task.id, "ahead": 0}
|
return {"id": task.id, "ahead": 0}
|
||||||
|
|
||||||
|
|
||||||
@@ -120,6 +120,8 @@ async def edit_metadata(task_id: str, body: MetadataBody,
|
|||||||
if body.keywords is not None:
|
if body.keywords is not None:
|
||||||
metadata["keywords"] = [word.strip() for word in body.keywords if word.strip()]
|
metadata["keywords"] = [word.strip() for word in body.keywords if word.strip()]
|
||||||
task.poster_metadata = metadata
|
task.poster_metadata = metadata
|
||||||
|
# 잡 이름이 곧 내려받는 파일명이라 고친 행사명을 따라간다
|
||||||
|
task.name = metadata["event_name"]
|
||||||
await session.commit()
|
await session.commit()
|
||||||
return poster_alive_view(task)
|
return poster_alive_view(task)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from models.pipeline_state import PlayreelState
|
|||||||
from pipelines import playreel
|
from pipelines import playreel
|
||||||
from pipelines.gate import (REVERSIBLE_GATES, PlayreelGate, apply_playreel_edits,
|
from pipelines.gate import (REVERSIBLE_GATES, PlayreelGate, apply_playreel_edits,
|
||||||
previous_gate, resume_stage)
|
previous_gate, resume_stage)
|
||||||
from pipelines.runner import AWAITING_REVIEW, FAILED, QUEUED, RUNNING, reset_from
|
from pipelines.runner import AWAITING_REVIEW, DONE, FAILED, QUEUED, RUNNING, reset_from
|
||||||
from routers.view import playreel_view
|
from routers.view import playreel_view
|
||||||
from tables.task import PlayreelTask
|
from tables.task import PlayreelTask
|
||||||
from utils.database import get_session
|
from utils.database import get_session
|
||||||
@@ -119,6 +119,9 @@ async def back(task_id: str, session: AsyncSession = Depends(get_session)):
|
|||||||
async def retry(task_id: str, session: AsyncSession = Depends(get_session)):
|
async def retry(task_id: str, session: AsyncSession = Depends(get_session)):
|
||||||
"""실패 재시도와 클립 재생성. i2v를 다시 돌리면 크레딧이 다시 든다"""
|
"""실패 재시도와 클립 재생성. i2v를 다시 돌리면 크레딧이 다시 든다"""
|
||||||
task = await find_task(session, task_id)
|
task = await find_task(session, task_id)
|
||||||
|
# 끝난 것을 다시 돌리면 크레딧만 나간다. 새로 만들 거면 새 잡이다
|
||||||
|
if task.status == DONE:
|
||||||
|
raise HTTPException(409, "이미 끝난 작업입니다")
|
||||||
restart = (PlayreelState.I2V.value if task.gate == PlayreelGate.CLIP_CONFIRM
|
restart = (PlayreelState.I2V.value if task.gate == PlayreelGate.CLIP_CONFIRM
|
||||||
else task.error_stage or PlayreelState.FETCH.value)
|
else task.error_stage or PlayreelState.FETCH.value)
|
||||||
reset_from(task, restart)
|
reset_from(task, restart)
|
||||||
|
|||||||
+16
-3
@@ -2,7 +2,7 @@
|
|||||||
필드는 web/lib/api.ts 의 Job, web/lib/playreel.ts 의 PlayreelJob 과 맞춤
|
필드는 web/lib/api.ts 의 Job, web/lib/playreel.ts 의 PlayreelJob 과 맞춤
|
||||||
"""
|
"""
|
||||||
from models.motion import MotionPlan
|
from models.motion import MotionPlan
|
||||||
from models.pipeline_state import PlayreelState, PosterAliveState, initial_timings
|
from models.pipeline_state import PlayreelState, PosterAliveState, stage_keys
|
||||||
from pipelines.gate import build_review
|
from pipelines.gate import build_review
|
||||||
from tables.task import PlayreelTask, PosterAliveTask
|
from tables.task import PlayreelTask, PosterAliveTask
|
||||||
|
|
||||||
@@ -24,13 +24,26 @@ def motion_elements(motion_plan: dict | None) -> list[str] | None:
|
|||||||
return [item.motion for item in MotionPlan.model_validate(motion_plan).kept]
|
return [item.motion for item in MotionPlan.model_validate(motion_plan).kept]
|
||||||
|
|
||||||
|
|
||||||
|
IDLE = {"status": "idle", "started": None, "ended": None}
|
||||||
|
# 이름은 narration_text 가 포스터에서 읽어 채운다. 그 전까지 화면에 쓸 말
|
||||||
|
UNNAMED = "이름 없는 행사"
|
||||||
|
|
||||||
|
|
||||||
|
def ordered_stages(task, state_type) -> dict:
|
||||||
|
"""스테퍼가 키 순서대로 그리므로 실행 순서로 다시 세운다.
|
||||||
|
JSON 객체는 순서를 담는 자리가 아니고, 순서의 정본은 state enum이다.
|
||||||
|
"""
|
||||||
|
stored = task.stage_timings or {}
|
||||||
|
return {key: stored.get(key, IDLE) for key in stage_keys(state_type)}
|
||||||
|
|
||||||
|
|
||||||
def base_view(task, state_type) -> dict:
|
def base_view(task, state_type) -> dict:
|
||||||
return {
|
return {
|
||||||
"id": task.id,
|
"id": task.id,
|
||||||
"name": task.name,
|
"name": task.name or UNNAMED,
|
||||||
"status": task.status,
|
"status": task.status,
|
||||||
"stage": current_stage(task),
|
"stage": current_stage(task),
|
||||||
"stages": task.stage_timings or initial_timings(state_type),
|
"stages": ordered_stages(task, state_type),
|
||||||
"error": error_view(task),
|
"error": error_view(task),
|
||||||
"created_at": task.created_at.timestamp(),
|
"created_at": task.created_at.timestamp(),
|
||||||
"credits_used": task.credits_used,
|
"credits_used": task.credits_used,
|
||||||
|
|||||||
+16
-1
@@ -5,6 +5,7 @@ SAS 토큰을 붙인 URL로 PUT 한 번. 경로 규칙은 부르는 쪽이 정
|
|||||||
"""
|
"""
|
||||||
import mimetypes
|
import mimetypes
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
@@ -60,12 +61,26 @@ def with_sas(url: str) -> str:
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
async def upload_bytes(data: bytes, path: str, content_type: str | None = None) -> str:
|
def as_attachment(filename: str) -> str:
|
||||||
|
"""이 값이 붙은 blob은 브라우저가 열면 내려받기가 된다.
|
||||||
|
|
||||||
|
<a download>은 다른 출처에 안 먹어 완성본은 이 길로 간다.
|
||||||
|
한글 파일명은 RFC 5987 형식이라야 온전히 건너간다.
|
||||||
|
"""
|
||||||
|
return f"attachment; filename*=UTF-8''{quote(filename)}"
|
||||||
|
|
||||||
|
|
||||||
|
async def upload_bytes(data: bytes, path: str, content_type: str | None = None,
|
||||||
|
disposition: str | None = None) -> str:
|
||||||
"""path 예: playreel/nol_26007416/clip.mp4. 공개 URL을 돌려준다."""
|
"""path 예: playreel/nol_26007416/clip.mp4. 공개 URL을 돌려준다."""
|
||||||
if not settings.azure_blob_base_url or not settings.azure_blob_sas_token:
|
if not settings.azure_blob_base_url or not settings.azure_blob_sas_token:
|
||||||
raise RuntimeError("AZURE_BLOB_BASE_URL / AZURE_BLOB_SAS_TOKEN 없음")
|
raise RuntimeError("AZURE_BLOB_BASE_URL / AZURE_BLOB_SAS_TOKEN 없음")
|
||||||
|
|
||||||
headers = {"Content-Type": content_type or guess_content_type(path), **BLOB_TYPE_HEADER}
|
headers = {"Content-Type": content_type or guess_content_type(path), **BLOB_TYPE_HEADER}
|
||||||
|
if disposition:
|
||||||
|
# 헤더 이름이 Content-Disposition이면 이 요청 본문의 성격으로 읽힌다.
|
||||||
|
# blob 속성으로 저장되는 것은 x-ms- 쪽이다
|
||||||
|
headers["x-ms-blob-content-disposition"] = disposition
|
||||||
response = await get_client().put(upload_url(path), content=data, headers=headers)
|
response = await get_client().put(upload_url(path), content=data, headers=headers)
|
||||||
if response.status_code not in (200, 201):
|
if response.status_code not in (200, 201):
|
||||||
print(f"[blob] 업로드 실패 {response.status_code} {path}: {response.text[:300]}",
|
print(f"[blob] 업로드 실패 {response.status_code} {path}: {response.text[:300]}",
|
||||||
|
|||||||
+6
-3
@@ -1,8 +1,10 @@
|
|||||||
|
# 앞에 아파치가 선다 (playreel.o2o.kr → / 는 30100, /api 는 30101).
|
||||||
|
# 포트를 루프백에만 붙여 서버 IP로 직접 들어오는 길을 막는다.
|
||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
build: ./backend
|
build: ./backend
|
||||||
ports:
|
ports:
|
||||||
- "30101:30101"
|
- "127.0.0.1:30101:30101"
|
||||||
env_file:
|
env_file:
|
||||||
- backend/.env
|
- backend/.env
|
||||||
volumes:
|
volumes:
|
||||||
@@ -16,9 +18,10 @@ services:
|
|||||||
frontend:
|
frontend:
|
||||||
build: ./frontend
|
build: ./frontend
|
||||||
ports:
|
ports:
|
||||||
- "30100:30100"
|
- "127.0.0.1:30100:30100"
|
||||||
environment:
|
environment:
|
||||||
# Next 리라이트가 /api/* 를 여기로 넘긴다
|
# 아파치가 /api 를 백엔드로 바로 보내므로 운영에서는 안 쓰인다.
|
||||||
|
# 아파치 없이 띄울 때 proxy.ts 가 이 값으로 넘긴다.
|
||||||
API_ORIGIN: http://backend:30101
|
API_ORIGIN: http://backend:30101
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Link from "next/link";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import StageStepper, { stageProgress } from "@/components/stage-stepper";
|
import StageStepper, { stageProgress } from "@/components/stage-stepper";
|
||||||
import MetadataCard from "@/components/metadata-card";
|
import MetadataCard from "@/components/metadata-card";
|
||||||
import { apiFetch, useJob } from "@/lib/api";
|
import { apiFetch, useJob, type Job } from "@/lib/api";
|
||||||
|
|
||||||
const SUBTITLES: Record<string, string> = {
|
const SUBTITLES: Record<string, string> = {
|
||||||
queued: "대기 중입니다. 앞선 작업이 끝나면 자동으로 시작됩니다",
|
queued: "대기 중입니다. 앞선 작업이 끝나면 자동으로 시작됩니다",
|
||||||
@@ -115,6 +115,12 @@ export default function JobPage({ params }: { params: Promise<{ id: string }> })
|
|||||||
});
|
});
|
||||||
refresh();
|
refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// 실패 화면을 띄워둔 사이에 끝났을 수 있다. 그때는 에러 대신 결과를 보여준다
|
||||||
|
const latest = await apiFetch<Job>(`/api/f1/jobs/${id}`).catch(() => null);
|
||||||
|
if (latest?.status === "done") {
|
||||||
|
refresh();
|
||||||
|
return;
|
||||||
|
}
|
||||||
setActionError((e as Error).message);
|
setActionError((e as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
@@ -316,10 +322,12 @@ export default function JobPage({ params }: { params: Promise<{ id: string }> })
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div style={{ marginTop: "auto", paddingTop: "1.5rem", display: "grid", gridTemplateColumns: "1fr 1fr", gap: "0.75rem" }}>
|
<div style={{ marginTop: "auto", paddingTop: "1.5rem", display: "grid", gridTemplateColumns: "1fr 1fr", gap: "0.75rem" }}>
|
||||||
|
{/* blob에 Content-Disposition이 박혀 있어 주소만 열면 내려받기가 된다.
|
||||||
|
<a download>은 다른 출처에 안 먹으므로 이 속성에 기대지 않는다 */}
|
||||||
{job.artifacts.thumbnail ? (
|
{job.artifacts.thumbnail ? (
|
||||||
<a href={job.artifacts.thumbnail} download className="btn-tonal-mint">정지 컷 JPG</a>
|
<a href={job.artifacts.thumbnail} className="btn-tonal-mint">정지 컷 JPG</a>
|
||||||
) : <span />}
|
) : <span />}
|
||||||
<a href={job.artifacts.video} download className="btn-cta"
|
<a href={job.artifacts.video} className="btn-cta"
|
||||||
style={{ padding: "0.75rem 1rem", fontSize: "var(--text-base)", borderRadius: "var(--radius-xl)", textDecoration: "none" }}>
|
style={{ padding: "0.75rem 1rem", fontSize: "var(--text-base)", borderRadius: "var(--radius-xl)", textDecoration: "none" }}>
|
||||||
MP4 다운로드
|
MP4 다운로드
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useRouter, useSearchParams } from "next/navigation";
|
|||||||
import StageStepper, { stageProgress } from "@/components/stage-stepper";
|
import StageStepper, { stageProgress } from "@/components/stage-stepper";
|
||||||
import { GateBody, GateShell } from "@/components/gate-card";
|
import { GateBody, GateShell } from "@/components/gate-card";
|
||||||
import { apiFetch } from "@/lib/api";
|
import { apiFetch } from "@/lib/api";
|
||||||
import { GATE_META, PLAYREEL_STAGE_LABELS, usePlayreelJob } from "@/lib/playreel";
|
import { GATE_META, PLAYREEL_STAGE_LABELS, usePlayreelJob, type PlayreelJob } from "@/lib/playreel";
|
||||||
import { useAutoApprove } from "@/lib/prefs";
|
import { useAutoApprove } from "@/lib/prefs";
|
||||||
import { isAutoApprovable } from "@/components/auto-approve";
|
import { isAutoApprovable } from "@/components/auto-approve";
|
||||||
|
|
||||||
@@ -70,6 +70,12 @@ export default function PlayreelJobPage({ params }: { params: Promise<{ id: stri
|
|||||||
edits.current = null;
|
edits.current = null;
|
||||||
refresh();
|
refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// 실패 화면을 띄워둔 사이에 끝났을 수 있다. 그때는 에러 대신 결과를 보여준다
|
||||||
|
const latest = await apiFetch<PlayreelJob>(`/api/playreel/jobs/${id}`).catch(() => null);
|
||||||
|
if (latest?.status === "done") {
|
||||||
|
refresh();
|
||||||
|
return;
|
||||||
|
}
|
||||||
setActionError((e as Error).message);
|
setActionError((e as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
@@ -170,7 +176,9 @@ export default function PlayreelJobPage({ params }: { params: Promise<{ id: stri
|
|||||||
<p style={{ margin: 0, fontSize: "var(--text-sm)", color: "var(--color-text-gray-400)" }}>출처 · <a href={job.source.url} target="_blank" rel="noreferrer" style={{ color: "var(--color-mint)" }}>공연 상품페이지 열기 →</a></p>
|
<p style={{ margin: 0, fontSize: "var(--text-sm)", color: "var(--color-text-gray-400)" }}>출처 · <a href={job.source.url} target="_blank" rel="noreferrer" style={{ color: "var(--color-mint)" }}>공연 상품페이지 열기 →</a></p>
|
||||||
<div className="result-actions">
|
<div className="result-actions">
|
||||||
<Link href="/" className="btn-tonal-mint" style={{ textDecoration: "none", textAlign: "center" }}>새 버전 만들기</Link>
|
<Link href="/" className="btn-tonal-mint" style={{ textDecoration: "none", textAlign: "center" }}>새 버전 만들기</Link>
|
||||||
<a href={job.artifacts.video} download className="btn-cta" style={{ padding: "0.75rem 1rem", fontSize: "var(--text-base)", borderRadius: "var(--radius-xl)", textDecoration: "none" }}>MP4 다운로드</a>
|
{/* blob에 Content-Disposition이 박혀 있어 주소만 열면 내려받기가 된다.
|
||||||
|
<a download>은 다른 출처에 안 먹으므로 이 속성에 기대지 않는다 */}
|
||||||
|
<a href={job.artifacts.video} className="btn-cta" style={{ padding: "0.75rem 1rem", fontSize: "var(--text-base)", borderRadius: "var(--radius-xl)", textDecoration: "none" }}>MP4 다운로드</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user