diff --git a/src/APIClient/APIClient10.js b/src/APIClient/APIClient10.js index ad96a84..cb8e714 100644 --- a/src/APIClient/APIClient10.js +++ b/src/APIClient/APIClient10.js @@ -444,6 +444,14 @@ class APIClient10 { return this.request(`/api/v1/dashboard/logout`); } + getFileBlackList(){ + return this.request(`/api/v1/cidstore/list`); + } + + addFileBlackList(arg,batch){ + return this.request(`/api/v1/cidstore/add?arg=${arg}&batch=${batch}`); + } + } const Client10 = new APIClient10(); diff --git a/src/components/Modals/FileBlackListModal.js b/src/components/Modals/FileBlackListModal.js new file mode 100644 index 0000000..27e233a --- /dev/null +++ b/src/components/Modals/FileBlackListModal.js @@ -0,0 +1,197 @@ +import React, { useEffect, useState } from 'react'; +import { useIntl } from 'react-intl'; +import { getFileBlackList, addFileBlackList } from 'services/filesService.js'; +import { LoadingOutlined } from '@ant-design/icons'; +import { Spin, Input } from 'antd'; +import Emitter from 'utils/eventBus'; +import { t } from 'utils/text.js'; +import CommonModal from './CommonModal'; +import isIPFS from 'is-ipfs'; + +const { TextArea } = Input; + +export default function EncryptFileModal({ color, closeModal, showModal = false }) { + + const intl = useIntl(); + const [loading, setLoading] = useState(false); + const [isEdit, setIsEdit] = useState(false); + const [listVal, setListVal] = useState(''); + const [initListVal, setInitListVal] = useState(''); + const [validateMsg, setValidateMsg] = useState(''); + + const getFileBlackListData = async () => { + let listData = await getFileBlackList() || []; + let listStr = listData.join('\n') || '' + setListVal(listStr); + setInitListVal(listStr); + }; + + useEffect(() => { + if (showModal) { + setValidateMsg(''); + getFileBlackListData(); + } + // Emitter.on('openDecryptFileModal', set); + return () => { + // Emitter.removeListener('openDecryptFileModal'); + window.body.style.overflow = ''; + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [showModal]); + + useEffect(() => { + setIsEdit(false); + }, [showModal]); + + const validateCid = val => { + + let res = isIPFS.cid(val); + if (res) { + setValidateMsg(''); + return true; + } + return false; + }; + + // const validateListVal = val => { + // console.log(val,'11') + // let reg = /^[A-Za-z0-9]+$/; + // if (!val || reg.test(val)) { + // setValidateMsg(''); + // return true; + // } + // if (!reg.test(val)) { + // setValidateMsg(t('validate_file_blacklist_cid1')); + // return false; + // } + // return true; + // }; + + const changeListVal = e => { + setListVal(e.target.value); + }; + + const editFileList = () => { + setIsEdit(!isEdit); + }; + + const cancelEdit = () => { + setValidateMsg(''); + setListVal(initListVal); + setIsEdit(false); + }; + + const saveFileList = async () => { + // if (listVal && !validateListVal(listVal)) { + // return; + // } + let listArr = listVal.split('\n'); + let validateCids = true; + for (var v in listArr){ + if(listArr[v] && !validateCid(listArr[v])){ + validateCids = false + break; + } + + } + if(!validateCids){ + setValidateMsg(t('validate_file_blacklist_cid2')); + return + } + + try { + await addFileBlackList(listArr,true); + setLoading(false); + setInitListVal(listVal); + setIsEdit(false) + Emitter.emit('showMessageAlert', { + message: 'add_file_blacklist_success', + status: 'success', + type: 'frontEnd', + }); + } catch (e) { + Emitter.emit('showMessageAlert', { message: e.Message, status: 'error' }); + } + + }; + + + return ( + +
+
+ +
{t('file_blacklist_title')}
+
+ {t('file_blacklist_desc')} +
+
+ {t('file_blacklist_desc2')} +
+ + + +