|
|
@ -4,10 +4,11 @@ import { useDropzone } from 'react-dropzone';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { ActiveState } from '../models/misc';
|
|
|
|
import { ActiveState } from '../models/misc';
|
|
|
|
import { getDocs } from '../preferences/preferenceApi';
|
|
|
|
import { getDocs } from '../preferences/preferenceApi';
|
|
|
|
import { setSourceDocs } from '../preferences/preferenceSlice';
|
|
|
|
import { setSelectedDocs, setSourceDocs } from '../preferences/preferenceSlice';
|
|
|
|
import Dropdown from '../components/Dropdown';
|
|
|
|
import Dropdown from '../components/Dropdown';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
export default function Upload({
|
|
|
|
|
|
|
|
|
|
|
|
function Upload({
|
|
|
|
modalState,
|
|
|
|
modalState,
|
|
|
|
setModalState,
|
|
|
|
setModalState,
|
|
|
|
}: {
|
|
|
|
}: {
|
|
|
@ -24,25 +25,28 @@ export default function Upload({
|
|
|
|
search_queries: [''],
|
|
|
|
search_queries: [''],
|
|
|
|
number_posts: 10,
|
|
|
|
number_posts: 10,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const [activeTab, setActiveTab] = useState<string>('file');
|
|
|
|
|
|
|
|
const [files, setfiles] = useState<File[]>([]);
|
|
|
|
|
|
|
|
const [progress, setProgress] = useState<{
|
|
|
|
|
|
|
|
type: 'UPLOAD' | 'TRAINIING';
|
|
|
|
|
|
|
|
percentage: number;
|
|
|
|
|
|
|
|
taskId?: string;
|
|
|
|
|
|
|
|
failed?: boolean;
|
|
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
|
|
const urlOptions: { label: string; value: string }[] = [
|
|
|
|
const urlOptions: { label: string; value: string }[] = [
|
|
|
|
{ label: 'Crawler', value: 'crawler' },
|
|
|
|
{ label: 'Crawler', value: 'crawler' },
|
|
|
|
// { label: 'Sitemap', value: 'sitemap' },
|
|
|
|
// { label: 'Sitemap', value: 'sitemap' },
|
|
|
|
{ label: 'Link', value: 'url' },
|
|
|
|
{ label: 'Link', value: 'url' },
|
|
|
|
{ label: 'Reddit', value: 'reddit' },
|
|
|
|
{ label: 'Reddit', value: 'reddit' },
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const [urlType, setUrlType] = useState<{ label: string; value: string }>({
|
|
|
|
const [urlType, setUrlType] = useState<{ label: string; value: string }>({
|
|
|
|
label: 'Link',
|
|
|
|
label: 'Link',
|
|
|
|
value: 'url',
|
|
|
|
value: 'url',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const [activeTab, setActiveTab] = useState<string>('file');
|
|
|
|
|
|
|
|
const [files, setfiles] = useState<File[]>([]);
|
|
|
|
|
|
|
|
const [progress, setProgress] = useState<{
|
|
|
|
|
|
|
|
type: 'UPLOAD' | 'TRAINIING';
|
|
|
|
|
|
|
|
percentage: number;
|
|
|
|
|
|
|
|
taskId?: string;
|
|
|
|
|
|
|
|
failed?: boolean;
|
|
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Progress({
|
|
|
|
function Progress({
|
|
|
|
title,
|
|
|
|
title,
|
|
|
@ -93,16 +97,26 @@ export default function Upload({
|
|
|
|
|
|
|
|
|
|
|
|
function TrainingProgress() {
|
|
|
|
function TrainingProgress() {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
(progress?.percentage ?? 0) < 100 &&
|
|
|
|
let timeoutID: number | undefined;
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
|
|
if ((progress?.percentage ?? 0) < 100) {
|
|
|
|
|
|
|
|
timeoutID = setTimeout(() => {
|
|
|
|
const apiHost = import.meta.env.VITE_API_HOST;
|
|
|
|
const apiHost = import.meta.env.VITE_API_HOST;
|
|
|
|
fetch(`${apiHost}/api/task_status?task_id=${progress?.taskId}`)
|
|
|
|
fetch(`${apiHost}/api/task_status?task_id=${progress?.taskId}`)
|
|
|
|
.then((data) => data.json())
|
|
|
|
.then((data) => data.json())
|
|
|
|
.then((data) => {
|
|
|
|
.then((data) => {
|
|
|
|
if (data.status == 'SUCCESS') {
|
|
|
|
if (data.status == 'SUCCESS') {
|
|
|
|
if (data.result.limited === true) {
|
|
|
|
if (data.result.limited === true) {
|
|
|
|
getDocs().then((data) => dispatch(setSourceDocs(data)));
|
|
|
|
getDocs().then((data) => {
|
|
|
|
|
|
|
|
dispatch(setSourceDocs(data));
|
|
|
|
|
|
|
|
dispatch(
|
|
|
|
|
|
|
|
setSelectedDocs(
|
|
|
|
|
|
|
|
data?.find((d) => d.location.toLowerCase() === 'local'),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
setProgress(
|
|
|
|
setProgress(
|
|
|
|
(progress) =>
|
|
|
|
(progress) =>
|
|
|
|
progress && {
|
|
|
|
progress && {
|
|
|
@ -112,7 +126,14 @@ export default function Upload({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
getDocs().then((data) => dispatch(setSourceDocs(data)));
|
|
|
|
getDocs().then((data) => {
|
|
|
|
|
|
|
|
dispatch(setSourceDocs(data));
|
|
|
|
|
|
|
|
dispatch(
|
|
|
|
|
|
|
|
setSelectedDocs(
|
|
|
|
|
|
|
|
data?.find((d) => d.location.toLowerCase() === 'local'),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
setProgress(
|
|
|
|
setProgress(
|
|
|
|
(progress) =>
|
|
|
|
(progress) =>
|
|
|
|
progress && {
|
|
|
|
progress && {
|
|
|
@ -133,6 +154,14 @@ export default function Upload({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}, 5000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
if (timeoutID !== undefined) {
|
|
|
|
|
|
|
|
clearTimeout(timeoutID);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}, [progress, dispatch]);
|
|
|
|
}, [progress, dispatch]);
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Progress
|
|
|
|
<Progress
|
|
|
@ -217,6 +246,7 @@ export default function Upload({
|
|
|
|
['.docx'],
|
|
|
|
['.docx'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
const { name, value } = e.target;
|
|
|
|
const { name, value } = e.target;
|
|
|
|
if (name === 'search_queries' && value.length > 0) {
|
|
|
|
if (name === 'search_queries' && value.length > 0) {
|
|
|
@ -230,7 +260,9 @@ export default function Upload({
|
|
|
|
[name]: value,
|
|
|
|
[name]: value,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let view;
|
|
|
|
let view;
|
|
|
|
|
|
|
|
|
|
|
|
if (progress?.type === 'UPLOAD') {
|
|
|
|
if (progress?.type === 'UPLOAD') {
|
|
|
|
view = <UploadProgress></UploadProgress>;
|
|
|
|
view = <UploadProgress></UploadProgress>;
|
|
|
|
} else if (progress?.type === 'TRAINIING') {
|
|
|
|
} else if (progress?.type === 'TRAINIING') {
|
|
|
@ -263,6 +295,7 @@ export default function Upload({
|
|
|
|
{t('modals.uploadDoc.remote')}
|
|
|
|
{t('modals.uploadDoc.remote')}
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{activeTab === 'file' && (
|
|
|
|
{activeTab === 'file' && (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<input
|
|
|
|
<input
|
|
|
@ -411,6 +444,7 @@ export default function Upload({
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-row-reverse">
|
|
|
|
<div className="flex flex-row-reverse">
|
|
|
|
{activeTab === 'file' ? (
|
|
|
|
{activeTab === 'file' ? (
|
|
|
|
<button
|
|
|
|
<button
|
|
|
@ -462,3 +496,5 @@ export default function Upload({
|
|
|
|
</article>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default Upload;
|
|
|
|