mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : 자료실 로컬 파일 업로드 (진행률 표시), nginx 업로드 용량 5GB
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5ccf1a9e4
commit
de5ea95de1
4 files changed
+69
-14
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { createMediaPost } from "../api";
|
||||
import { createMediaPost, uploadMediaFiles } from "../api";
|
||||
import type { MediaPost, MediaQuery } from "../types";
|
||||
import DatePicker from "./DatePicker";
|
||||
import { MoreSentinel } from "./PostList";
|
||||
@@ -33,6 +33,7 @@ const EMPTY_SEARCH = { q: "", from: "", to: "" };
|
||||
export default function MediaList(props: Props) {
|
||||
const { posts, total, last, onMore, categories, query, token, onSelect, onQuery, onCreated, onError } = props;
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [uploaded, setUploaded] = useState<number | null>(null); // 업로드 중이면 보낸 비율(%)
|
||||
const tabs = [{ key: null, name: "전체" }, ...categories.map((c) => ({ key: c, name: c })), { key: "", name: "미분류" }];
|
||||
const searching = query.q || query.from || query.to;
|
||||
|
||||
@@ -41,20 +42,27 @@ export default function MediaList(props: Props) {
|
||||
if (!token) return;
|
||||
const form = e.currentTarget;
|
||||
const data = new FormData(form);
|
||||
const url = String(data.get("url")).trim();
|
||||
const title = String(data.get("title")).trim();
|
||||
const category = String(data.get("category")).trim();
|
||||
// 빈 파일 칸도 FormData에는 이름 없는 File로 들어옴 → 이름 있는 것만
|
||||
const files = data.getAll("files").filter((f): f is File => f instanceof File && f.name !== "");
|
||||
if (!url && files.length === 0) {
|
||||
onError(new Error("※ 링크를 넣거나 파일을 고르세요."));
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
await createMediaPost(
|
||||
token,
|
||||
String(data.get("url")).trim(),
|
||||
String(data.get("title")).trim(),
|
||||
String(data.get("category")).trim(),
|
||||
);
|
||||
// 파일을 골랐으면 업로드, 아니면 링크 다운로드
|
||||
if (files.length > 0) await uploadMediaFiles(token, files, title, category, setUploaded);
|
||||
else await createMediaPost(token, url, title, category);
|
||||
form.reset();
|
||||
onCreated();
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
setUploaded(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -85,7 +93,12 @@ export default function MediaList(props: Props) {
|
||||
<form key={query.category ?? "all"} className={styles.loginForm} onSubmit={submit}>
|
||||
<label>
|
||||
<span className={styles.num}>링크</span>
|
||||
<input name="url" type="url" className={styles.wide} placeholder="유튜브·인스타 주소" required />
|
||||
<input name="url" type="url" className={styles.wide} placeholder="유튜브·인스타 주소" />
|
||||
</label>
|
||||
<label>
|
||||
<span className={styles.num}>파일</span>
|
||||
{/* 고르면 링크 대신 내 PC 파일을 업로드 (여러 개 가능) */}
|
||||
<input name="files" type="file" multiple />
|
||||
</label>
|
||||
<label>
|
||||
<span className={styles.num}>분류</span>
|
||||
@@ -99,10 +112,10 @@ export default function MediaList(props: Props) {
|
||||
</label>
|
||||
<label>
|
||||
<span className={styles.num}>제목</span>
|
||||
<input name="title" className={styles.wide} placeholder="비우면 영상 제목으로" maxLength={500} />
|
||||
<input name="title" className={styles.wide} placeholder="비우면 영상·파일 제목으로" maxLength={500} />
|
||||
</label>
|
||||
<button type="submit" disabled={busy}>
|
||||
{busy ? "요청중..." : "다운로드 등록"}
|
||||
{uploaded !== null ? `업로드 ${bar(uploaded, 10)}` : busy ? "요청중..." : "등록"}
|
||||
</button>
|
||||
</form>
|
||||
<hr className={styles.rule} />
|
||||
|
||||
Reference in new issue
Block a user