feat : 자료실(4번 메뉴) 추가 — 링크 등록 시 영상/이미지 다운로드 후 게시
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s

- 목록: 링크·제목 등록 칸, 받는 중인 글이 있으면 5초마다 자동 새로고침
- 상세: 파일별 <video>/<img> (백엔드가 준 1시간짜리 토큰 주소)
- API 오류 시 서버가 준 이유({"error"})를 팝업에 표시

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-27 17:04:44 +09:00
1 parent ca4df3e9a3
commit eac57c04e7
8 files changed
+273 -10

No files matched your search

@@ -0,0 +1,77 @@
import { useEffect, useState } from "react";
import { API_URL, fetchMediaPost } from "../api";
import type { MediaPost } from "../types";
import { STATUS } from "./MediaList";
import styles from "./bbs.module.css";
/** 자료실 글 보기: 파일마다 <video>/<img>. 파일 주소의 토큰은 1시간 유효 → 오래 열어 두었으면 "L" 후 다시 열기 */
export default function MediaDetail({ id, token, onError }: { id: number; token: string; onError: (e: unknown) => void }) {
const [post, setPost] = useState<MediaPost | null>(null);
// 받는 중이면 5초마다 다시 조회 → 끝나면 파일이 나타남
useEffect(() => {
let stale = false;
let timer: ReturnType<typeof setTimeout>;
const load = () =>
fetchMediaPost(token, id)
.then((p) => {
if (stale) return;
setPost(p);
if (p.status === "DOWNLOADING") timer = setTimeout(load, 5000);
})
.catch((e) => !stale && onError(e));
load();
return () => {
stale = true;
clearTimeout(timer);
};
}, [id, token, onError]);
if (!post) {
return (
<section className={`${styles.win} ${styles.full}`}>
<div className={styles.dim}>불러오는 중...</div>
</section>
);
}
return (
<section className={`${styles.win} ${styles.full}`}>
<span className={styles.cap}>═ [4] 자료실 ═</span>
<div className={styles.postHead}>
<span>제목 :</span> {post.title}
</div>
<div className={styles.postHead}>
<span>등록:</span> {post.author} <span>날짜:</span> {post.createdAt.slice(0, 16).replace("T", " ")}{" "}
<span>상태:</span> {STATUS[post.status]}
</div>
<hr className={styles.rule} />
{post.status === "DOWNLOADING" ? (
<div className={styles.dim}>다운로드 중입니다... 끝나면 자동으로 표시됩니다.</div>
) : post.files.length === 0 ? (
<div className={styles.error}>※ 다운로드에 실패했습니다. (쿠키 만료·삭제된 게시물·지원하지 않는 링크)</div>
) : (
<div className={styles.html}>
{post.files.map((f) => {
const src = API_URL + f.url;
if (f.type === "video") return <video key={f.url} src={src} controls preload="metadata" playsInline />;
// eslint-disable-next-line @next/next/no-img-element -- 정적 export라 next/image 최적화 불가
if (f.type === "image") return <img key={f.url} src={src} alt={f.name} loading="lazy" />;
return (
<p key={f.url}>
<a href={src}>{f.name}</a>
</p>
);
})}
</div>
)}
<hr className={styles.rule} />
<div className={styles.footer}>
<a className={styles.accent} href={post.sourceUrl} target="_blank" rel="noreferrer">
원본 보기 ↗
</a>{" "}
· <b>L</b>=목록 · <b>M</b>=메인
</div>
</section>
);
}