feat : 자료실 로컬 파일 업로드 (진행률 표시), nginx 업로드 용량 5GB
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-30 11:14:05 +09:00
1 parent e5ccf1a9e4
commit de5ea95de1
4 files changed
+66 -11

No files matched your search

+6
View File
@@ -5,6 +5,12 @@ server {
# 같은 도메인의 /api 요청을 NAS 백엔드(18080)로 전달 → 브라우저는 CORS 없이 호출
location /api/ {
# 자료실 파일 업로드: nginx 기본 1MB 제한 → 백엔드(multipart 5GB)와 맞춤
# 버퍼링 끔: 큰 파일을 nginx 디스크에 다 받은 뒤 넘기지 않고 바로 백엔드로 흘려보냄
client_max_body_size 5g;
proxy_request_buffering off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_pass http://192.168.0.215:18080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
+30
View File
@@ -67,6 +67,36 @@ export const createMediaPost = (token: string, url: string, title: string, categ
body: JSON.stringify({ url, title, category }),
});
/**
* 내 PC 파일 업로드 → 바로 완료된 글로 등록. onProgress: 보낸 비율(0~100)
* fetch는 업로드 진행률을 알려주지 않아서 XMLHttpRequest 사용
*/
export const uploadMediaFiles = (token: string, files: File[], title: string, category: string, onProgress: (percent: number) => void) =>
new Promise<void>((resolve, reject) => {
const body = new FormData();
files.forEach((f) => body.append("files", f));
body.append("title", title);
body.append("category", category);
const xhr = new XMLHttpRequest();
xhr.open("POST", `${API_URL}/api/media-posts/upload`);
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(Math.floor((e.loaded / e.total) * 100));
xhr.onerror = () => reject(new Error("※ 업로드 중 연결이 끊어졌습니다."));
xhr.onload = () => {
if (xhr.status === 401 || xhr.status === 403) return reject(new AuthError("※ 로그인이 만료되었습니다. 다시 로그인하세요."));
if (xhr.status === 413) return reject(new Error("※ 파일이 너무 큽니다."));
if (xhr.status < 200 || xhr.status >= 300) {
let reason: string | undefined;
try {
reason = JSON.parse(xhr.responseText)?.error;
} catch {}
return reject(new Error(reason ? `※ ${reason}` : `※ 서버 오류 (${xhr.status})`));
}
resolve();
};
xhr.send(body);
});
const PAGE_SIZE = 30;
/**
+7 -1
View File
@@ -168,10 +168,16 @@ export default function MediaDetail({ id, token, categories, onError, onDeleted,
)}
<hr className={styles.rule} />
<div className={styles.footer}>
{/* 업로드한 글은 원본 링크가 없음 (sourceUrl = "") */}
{post.sourceUrl && (
<>
<a className={styles.accent} href={post.sourceUrl} target="_blank" rel="noreferrer">
원본 보기 ↗
</a>{" "}
· <b>L</b>=목록 · <b>M</b>=메인 ·{" "}
·{" "}
</>
)}
<b>L</b>=목록 · <b>M</b>=메인 ·{" "}
{confirming ? (
<>
<span className={styles.error}>파일까지 지워집니다. 정말 삭제할까요?</span>{" "}
+23 -10
View File
@@ -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} />