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

+93
View File
@@ -0,0 +1,93 @@
import { useState, type FormEvent } from "react";
import { createMediaPost } from "../api";
import type { MediaPost } from "../types";
import styles from "./bbs.module.css";
interface Props {
posts: MediaPost[] | null;
token: string | null;
onSelect: (cmd: string) => void;
onCreated: () => void; // 등록 성공 → 목록 다시 불러오기
onError: (e: unknown) => void;
}
export const STATUS: Record<MediaPost["status"], string> = { DOWNLOADING: "받는중", DONE: "완료", FAILED: "실패" };
/** [4] 자료실: 위에는 링크 등록 칸, 아래는 목록. 받는 중인 글이 있으면 BbsTerminal이 5초마다 새로고침 */
export default function MediaList({ posts, token, onSelect, onCreated, onError }: Props) {
const [busy, setBusy] = useState(false);
const submit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (!token) return;
const form = e.currentTarget;
const data = new FormData(form);
setBusy(true);
try {
await createMediaPost(token, String(data.get("url")).trim(), String(data.get("title")).trim());
form.reset();
onCreated();
} catch (err) {
onError(err);
} finally {
setBusy(false);
}
};
return (
<section className={`${styles.win} ${styles.full}`}>
<span className={styles.cap}>
═ [4] 자료실{posts && ` (${posts.length}건)`} ═
</span>
{!token ? (
<div className={styles.dim}>로그인이 필요합니다. (F5 또는 메인에서 7)</div>
) : (
<>
<form className={styles.loginForm} onSubmit={submit}>
<label>
<span className={styles.num}>링크</span>
<input name="url" type="url" className={styles.wide} placeholder="유튜브·인스타 주소" required />
</label>
<label>
<span className={styles.num}>제목</span>
<input name="title" className={styles.wide} placeholder="비우면 영상 제목으로" maxLength={500} />
</label>
<button type="submit" disabled={busy}>
{busy ? "요청중..." : "다운로드 등록"}
</button>
</form>
<hr className={styles.rule} />
{!posts ? (
<div className={styles.dim}>불러오는 중...</div>
) : posts.length === 0 ? (
<div className={styles.dim}>등록된 자료가 없습니다.</div>
) : (
<table className={styles.tbl}>
<thead>
<tr>
<th className={styles.idx}>번호</th>
<th>상태</th>
<th>제목</th>
<th>날짜</th>
</tr>
</thead>
<tbody>
{posts.map((p, i) => (
<tr key={p.id} onClick={() => onSelect(String(i + 1))}>
<td className={styles.idx}>{i + 1}</td>
<td className={p.status === "FAILED" ? styles.error : styles.accent}>{STATUS[p.status]}</td>
<td className={styles.title}>{p.title}</td>
<td>{p.createdAt.slice(0, 10).replaceAll("-", "")}</td>
</tr>
))}
</tbody>
</table>
)}
</>
)}
<div className={styles.footer}>
<b>번호</b>=보기 · <b>M</b>=메인 · <b>L</b>=새로고침
</div>
</section>
);
}