-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: fileList routes and refactor uploader
- Loading branch information
Showing
7 changed files
with
154 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { llm_axiosInstance } from '../utils/axios'; | ||
|
||
export const useForm = (type: string, category: string, html_file: File) => { | ||
const formdata = new FormData(); | ||
formdata.append('type', type); | ||
formdata.append('category', category); | ||
formdata.append('html_file', html_file); | ||
|
||
const uploadData = async () => { | ||
console.log(formdata.get('type')); | ||
console.log(formdata.get('category')); | ||
console.log(formdata.get('html_file')); | ||
try { | ||
const response = await llm_axiosInstance.post('/upload_html/', formdata, { | ||
headers: { | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
}); | ||
console.log('Upload successful', response.data); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Upload Error', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
return uploadData; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,85 @@ | ||
import { Divider, List } from 'antd'; | ||
import { Button, Divider, Select } from 'antd'; | ||
import React, { useState } from 'react'; | ||
import { UploadFile } from 'antd/es/upload/interface'; | ||
import Uploader from '../../components/molecule/admin/uploader'; | ||
import { useForm } from '../../../hooks/useForm'; | ||
|
||
const FileList: React.FC = () => { | ||
const [open, setOpen] = useState(false); | ||
const [category, setCategory] = useState('모집요강'); | ||
const [type, setType] = useState('수시'); | ||
const [uploading, setUploading] = useState(false); | ||
const [fileList, setFileList] = useState<UploadFile<File>[]>([]); | ||
|
||
const handleTypeChange = (value: string) => { | ||
setType(value); | ||
}; | ||
|
||
const handleCategoryChange = (value: string) => { | ||
setCategory(value); | ||
}; | ||
|
||
const handleUpload = async () => { | ||
setUploading(true); | ||
try { | ||
if (fileList.length > 0) { | ||
const file = fileList[0].originFileObj as File; // 여기서 실제 File 객체를 가져옵니다. | ||
const uploadData = useForm(type, category, file); | ||
await uploadData(); | ||
console.log('success'); | ||
} | ||
} catch (error) { | ||
console.error('Upload failed', error); | ||
} | ||
setUploading(false); | ||
}; | ||
|
||
return ( | ||
<div className=" w-full"> | ||
<div className="w-full"> | ||
<Divider orientation="left">챗봇 관리 파일 리스트</Divider> | ||
<Uploader /> | ||
<div className="mx-8"> | ||
<div className="my-5"> | ||
<div className="mt-2"> | ||
전형방법: | ||
<Select | ||
defaultValue="수시" | ||
className="ml-2 w-40" | ||
onChange={handleTypeChange} | ||
options={[ | ||
{ value: '수시', label: '수시' }, | ||
{ value: '정시', label: '정시' }, | ||
{ value: '편입학', label: '편입학' }, | ||
]} | ||
/> | ||
</div> | ||
<div className="mt-2"> | ||
카테고리: | ||
<Select | ||
defaultValue="모집요강" | ||
className="ml-2 w-40" | ||
onChange={handleCategoryChange} | ||
options={[ | ||
{ value: '모집요강', label: '모집요강' }, | ||
{ value: '입시결과', label: '입시결과' }, | ||
{ value: '기출문제', label: '기출문제' }, | ||
{ value: '대학생활', label: '대학생활' }, | ||
{ value: '면접/실기', label: '면접/실기' }, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
<Uploader setFileList={setFileList} fileList={fileList} /> | ||
<Button | ||
type="primary" | ||
className="mt-4" | ||
onClick={handleUpload} | ||
disabled={fileList.length === 0} | ||
loading={uploading} | ||
> | ||
{uploading ? 'Uploading' : 'Start Upload'} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FileList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from 'axios'; | ||
|
||
export const llm_axiosInstance = axios.create({ | ||
baseURL: process.env.REACT_APP_LLM_SERVER_API_ADDRESS, | ||
timeout: 10000, | ||
withCredentials: false, | ||
}); | ||
|
||
export const server_axiosInstance = axios.create({ | ||
baseURL: process.env.REACT_APP_SPRING_SERVER_API_ADDRESS, | ||
timeout: 1000, | ||
withCredentials: false, | ||
}); |