Skip to content

Commit

Permalink
feat: v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lulu-tro committed Dec 10, 2024
1 parent bfb99b4 commit ee077ba
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/APIClient/APIClient10.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
197 changes: 197 additions & 0 deletions src/components/Modals/FileBlackListModal.js
Original file line number Diff line number Diff line change
@@ -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 (
<CommonModal visible={showModal} onCancel={closeModal}>
<div className="common-modal-wrapper theme-bg">
<main className="flex flex-col justify-center theme-bg theme-text-main">
<img
alt=""
src={require(`../../assets/img/decrypt-cid.png`).default}
className="mb-4"
width={43}
/>
<div className="font-semibold text-xl mb-2"> {t('file_blacklist_title')} </div>
<div className="text-xs font-medium theme-text-sub-info">
{t('file_blacklist_desc')}
</div>
<div className="text-xs font-medium mb-4 theme-text-sub-info">
{t('file_blacklist_desc2')}
</div>



<TextArea
className="w-full h-3 theme-bg theme-border-color rounded-lg h-400-px"
style={{ height: 400 }}
readOnly={!isEdit}
onChange={changeListVal}
value={listVal}
placeholder={intl.formatMessage({ id: 'decrypt_input_cid_placeholder' })}
/>

<div className="flex justify-between w-full mb-4">
<span className="theme-text-error text-xs pt-1">{validateMsg}</span>
</div>
{isEdit ? (
<div className="mt-2 text-right">
<button
className="ml-2 common-btn theme-fill-gray text-gray-900 mr-4"
onClick={cancelEdit}>
{t('file_blacklist_cancel')}
</button>

<div className="ml-2 inline-block">
<Spin
spinning={loading}
indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />}>
<button
type="primary"
className="common-btn theme-common-btn"
onClick={saveFileList}>
{t('file_blacklist_save')}
</button>
</Spin>
</div>
</div>
) : (
<div className="mt-2 text-right">
<button
className="ml-2 common-btn theme-fill-gray text-gray-900 mr-4"
onClick={closeModal}>
{t('file_blacklist_close')}
</button>
<div className="ml-2 inline-block">
<Spin
spinning={loading}
indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />}>
<button
type="primary"
className="common-btn theme-common-btn"
onClick={editFileList}>
{t('file_blacklist_edit')}
</button>
</Spin>
</div>
</div>
)}
</main>
</div>
</CommonModal>
);
}
2 changes: 1 addition & 1 deletion src/components/Stats/NodeStorageStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Contracts = ({ contracts, hostPrice }) => {
{contracts}
</div>
<div className="theme-text-sub-main">
{t('price')}: {hostPrice} WBTT (GB / {t('month')})
{t('price')}: {hostPrice} WBTT (GB / {t('day')})
</div>
</div>
</div>
Expand Down
37 changes: 31 additions & 6 deletions src/components/Tables/LocalFilesTable.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React, { useEffect, useState, useCallback, useRef } from 'react';
import { useIntl } from 'react-intl';
import { Breadcrumb, Pagination, Tabs, Tooltip } from 'antd';
import { Breadcrumb, Pagination, Tabs, Tooltip, Button } from 'antd';
import PropTypes from 'prop-types';
import FileTableDropdown from 'components/Dropdowns/FileTableDropdown.js';
import ImportFilesDropdown from 'components/Dropdowns/ImportFilesDropdown.js';
import ImportFilesEncryptDropdown from 'components/Dropdowns/ImportFilesEncryptDropdown.js';
import FileBlackListModal from 'components/Modals/FileBlackListModal.js';
import FileControl from 'components/Footers/FileControl.js';
import S3ApiTable from './S3ApiTable';
import { getRootFiles, getHashByPath, getFolerSize, getFiles, searchFiles } from 'services/filesService.js';
Expand All @@ -16,7 +17,6 @@ import moment from 'moment';
import Emitter from 'utils/eventBus';
import { Truncate } from 'utils/text';


let didCancel = false;
let filesAll = [];
let nameArray = [];
Expand All @@ -31,6 +31,11 @@ export default function LocalFilesTable({ color }) {
const [total, setTotal] = useState(0);
const [current, setCurrent] = useState(1);
const [batch, setBatch] = useState([]);
const [activeKey, setActiveKey] = useState('1');
const [showFileBlackListModal, setShowFileBlackListModal] = useState(false);




const selectAll = e => {
let fileControl = document.getElementById('fileControl');
Expand Down Expand Up @@ -202,6 +207,20 @@ export default function LocalFilesTable({ color }) {
addPath(hash, hash, -1);
};

const changeActiveKey = activeKey => {
setActiveKey(activeKey);
};

const operations = () => {
if (activeKey === '2') {
return <Button className="common-btn" onClick={()=> setShowFileBlackListModal(true)} >{t('file_black_list')}</Button>;
}
return null
};




useEffect(() => {
const set = async function () {
setTimeout(() => {
Expand All @@ -223,11 +242,15 @@ export default function LocalFilesTable({ color }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

console.log('breadcrumbName', breadcrumbName);

return (
<>
<Tabs defaultActiveKey="1" className="mb-4 common-card theme-bg theme-text-main file-tab-content">
<Tabs
defaultActiveKey="1"
activeKey={activeKey}
onChange={changeActiveKey}
className="mb-4 common-card theme-bg theme-text-main file-tab-content"
tabBarExtraContent={operations()}>
<Tabs.TabPane tab={t('s3_api')} key="1" className="w-full">
<S3ApiTable color={color} />
</Tabs.TabPane>
Expand Down Expand Up @@ -363,9 +386,10 @@ export default function LocalFilesTable({ color }) {
placement="top"
title={item['Name']}>
<span className="ml-3 font-bold">
<Truncate start={5}>{item['Name']}</Truncate>
<Truncate start={5}>
{item['Name']}
</Truncate>
</span>

</Tooltip>
) : (
<span className="ml-3 font-bold">
Expand Down Expand Up @@ -454,6 +478,7 @@ export default function LocalFilesTable({ color }) {
data={batch}
/>
</div>
<FileBlackListModal color={color} showModal={showFileBlackListModal} closeModal={()=> setShowFileBlackListModal(false)} />
</Tabs.TabPane>
</Tabs>
</>
Expand Down
17 changes: 15 additions & 2 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,21 @@ const en_US = {
upload_success:'Upload Successfully',
download_success:'Download Successfully',
upload_fail:'Upload Failed',
download_fail:'Download Failed'

download_fail:'Download Failed',

//v1.9
file_black_list:'文件黑名单',
file_blacklist_cancel:'取消',
file_blacklist_close:'关闭',
file_blacklist_save:'保存',
file_blacklist_edit:'编辑',
day: 'Day',
add_file_blacklist_success:'添加成功',
validate_file_blacklist_cid1:'不可输入中文,请使用英文逗号,区分',
validate_file_blacklist_cid2:'请输入正确的cid',
file_blacklist_title:'黑名单内容',
file_blacklist_desc:'请在此处添加需纳入黑名单的内容 CID,每行一个。',
file_blacklist_desc2:'被列入黑名单的内容将无法通过 BTFSGateway(8080端口)访问。'

};

Expand Down
18 changes: 17 additions & 1 deletion src/locale/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,23 @@ const zh_CN = {
upload_success:'上传成功',
download_success:'下载成功',
upload_fail:'上传失败',
download_fail:'下载失败'
download_fail:'下载失败',


//v1.9
file_black_list:'文件黑名单',
file_blacklist_cancel:'取消',
file_blacklist_close:'关闭',
file_blacklist_save:'保存',
file_blacklist_edit:'编辑',
day: '天',
add_file_blacklist_success:'添加成功',
validate_file_blacklist_cid1:'不可输入中文,请使用英文逗号,区分',
validate_file_blacklist_cid2:'请输入正确的cid',
file_blacklist_title:'黑名单内容',
file_blacklist_desc:'请在此处添加需纳入黑名单的内容 CID,每行一个。',
file_blacklist_desc2:'被列入黑名单的内容将无法通过 BTFSGateway(8080端口)访问。'


};

Expand Down
22 changes: 22 additions & 0 deletions src/services/filesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,25 @@ export const decryptUploadFiles = async (cid, hostid, password, t) => {
return false;
}
};


export const getFileBlackList = async () => {
try {
let data = await Client10.getFileBlackList();
return data;
} catch (e) {
console.log(e);
}
};


export const addFileBlackList = async (arg,batch) => {
try {
let data = await Client10.addFileBlackList(arg,batch);
return data;
} catch (e) {
console.log(e);
}
};


0 comments on commit ee077ba

Please sign in to comment.