@restnfeel/agentc-starter-kit
Version:
한국어 기업용 CMS 모듈 - Task Master AI와 함께 빠르게 웹사이트를 구현할 수 있는 재사용 가능한 컴포넌트 시스템
86 lines (83 loc) • 5.67 kB
JavaScript
"use client";
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { Card, CardHeader, CardContent } from '../ui/Card.js';
import { Button } from '../ui/Button.js';
function DocumentUploader({ ragEngine, onDocumentUploaded, onDocumentDeleted, } = {}) {
const [dragActive, setDragActive] = useState(false);
const [uploading, setUploading] = useState(false);
const [uploadResults, setUploadResults] = useState([]);
const handleFileUpload = async (files) => {
setUploading(true);
setUploadResults([]);
try {
const formData = new FormData();
Array.from(files).forEach((file) => {
formData.append("files", file);
});
const response = await fetch("/api/rag/upload", {
method: "POST",
body: formData,
});
const result = await response.json();
if (result.success) {
setUploadResults(result.results || []);
onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded();
}
else {
setUploadResults([
{
filename: "업로드 실패",
success: false,
error: result.error || "알 수 없는 오류",
},
]);
}
}
catch (error) {
console.error("파일 업로드 오류:", error);
setUploadResults([
{
filename: "네트워크 오류",
success: false,
error: "서버와 연결할 수 없습니다.",
},
]);
}
finally {
setUploading(false);
}
};
const handleFileSelect = (e) => {
const files = e.target.files;
if (files && files.length > 0) {
handleFileUpload(files);
}
};
const handleDrag = (e) => {
e.preventDefault();
e.stopPropagation();
if (e.type === "dragenter" || e.type === "dragover") {
setDragActive(true);
}
else if (e.type === "dragleave") {
setDragActive(false);
}
};
const handleDrop = (e) => {
e.preventDefault();
e.stopPropagation();
setDragActive(false);
const files = e.dataTransfer.files;
if (files && files.length > 0) {
handleFileUpload(files);
}
};
return (jsxs(Card, { children: [jsxs(CardHeader, { children: [jsx("h3", { className: "text-lg font-semibold", children: "\uD83D\uDCC1 \uBB38\uC11C \uC5C5\uB85C\uB4DC" }), jsx("p", { className: "text-sm text-gray-600", children: "PDF, TXT, DOCX \uD30C\uC77C\uC744 \uC5C5\uB85C\uB4DC\uD558\uC5EC RAG \uC2DC\uC2A4\uD15C\uC5D0 \uCD94\uAC00\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4." })] }), jsxs(CardContent, { className: "space-y-4", children: [jsx("div", { className: `border-2 border-dashed rounded-lg p-8 text-center transition-colors ${dragActive
? "border-blue-500 bg-blue-50"
: "border-gray-300 bg-gray-50"}`, onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop, children: jsxs("div", { className: "flex flex-col items-center space-y-2", children: [jsx("svg", { className: "w-12 h-12 text-gray-400", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" }) }), jsxs("div", { className: "space-y-1", children: [jsx("p", { className: "text-lg font-medium text-gray-700", children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uC5D0 \uB4DC\uB798\uADF8\uD558\uAC70\uB098 \uD074\uB9AD\uD558\uC5EC \uC5C5\uB85C\uB4DC" }), jsx("p", { className: "text-sm text-gray-500", children: "PDF, TXT, DOCX \uD30C\uC77C \uC9C0\uC6D0 (\uCD5C\uB300 10MB)" })] }), jsxs("label", { className: "cursor-pointer", children: [jsx("input", { type: "file", multiple: true, accept: ".pdf,.txt,.docx", onChange: handleFileSelect, className: "hidden", disabled: uploading }), jsx(Button, { type: "button", variant: "outline", disabled: uploading, className: "mt-2", children: uploading ? "업로드 중..." : "파일 선택" })] })] }) }), uploadResults.length > 0 && (jsxs("div", { className: "space-y-2", children: [jsx("h4", { className: "font-medium text-gray-700", children: "\uC5C5\uB85C\uB4DC \uACB0\uACFC:" }), jsx("div", { className: "space-y-2", children: uploadResults.map((result, index) => (jsxs("div", { className: `p-3 rounded-md border ${result.success
? "bg-green-50 border-green-200"
: "bg-red-50 border-red-200"}`, children: [jsxs("div", { className: "flex items-center justify-between", children: [jsxs("div", { className: "flex items-center space-x-2", children: [jsx("span", { className: `text-sm ${result.success ? "text-green-700" : "text-red-700"}`, children: result.success ? "✅" : "❌" }), jsx("span", { className: "font-medium text-sm", children: result.filename })] }), result.success && result.chunks && (jsxs("span", { className: "text-xs text-gray-600", children: [result.chunks, "\uAC1C \uCCAD\uD06C \uC0DD\uC131"] }))] }), result.error && (jsx("p", { className: "text-xs text-red-600 mt-1", children: result.error }))] }, index))) })] }))] })] }));
}
export { DocumentUploader };
//# sourceMappingURL=document-uploader.js.map