Skip to content

Commit

Permalink
feat: v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lulu-tro committed Jul 12, 2024
1 parent 6c574df commit 9056cb0
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 28 deletions.
7 changes: 7 additions & 0 deletions src/assets/styles/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,13 @@ video {
transition-duration: 150ms;
}

.common-select.ant-select .ant-select-selector{
border-radius: 0.5rem;

}



.setting-header {
display: flex;
align-items: center;
Expand Down
6 changes: 5 additions & 1 deletion src/components/Dropdowns/FileTableDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { removeFiles } from 'services/filesService.js';
import Emitter from 'utils/eventBus';
import { t } from 'utils/text.js';

const FileTableDropdown = ({ color, hash, name, size, path, type }) => {
const FileTableDropdown = ({ color, hash, name, size, path, type,isEncrypetd }) => {
const [dropdownPopoverShow, setDropdownPopoverShow] = React.useState(false);
const btnDropdownRef = React.createRef();
const popoverDropdownRef = React.createRef();
Expand All @@ -30,6 +30,10 @@ const FileTableDropdown = ({ color, hash, name, size, path, type }) => {
}, []);

const download = async () => {
if(isEncrypetd){
Emitter.emit('openDecryptFileModal',{ path: path });
return;
}
if (type === 1) {
Emitter.emit('openDownloadModal', { hash: hash, name: name, size: size, type: 1 });
}
Expand Down
58 changes: 47 additions & 11 deletions src/components/Modals/DecryptFileModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import React, { useEffect, useState, useRef } from 'react';
import { useIntl } from 'react-intl';
import { decryptUploadFiles } from 'services/filesService.js';
import { LoadingOutlined } from '@ant-design/icons';
import { Spin, Radio } from 'antd';
import { Spin, Radio, Select } from 'antd';
import Emitter from 'utils/eventBus';
import { t } from 'utils/text.js';
import CommonModal from './CommonModal';
import isIPFS from 'is-ipfs';
import { DECRYPT_FILE_TIME_OUT_LIST } from 'utils/constants.js';

const { Option } = Select;


const options = [
Expand All @@ -23,6 +26,7 @@ export default function EncryptFileModal({ color }) {
const [validateMsg, setValidateMsg] = useState('');
const [validateHostIdMsg, setValidateHostIdMsg] = useState('');
const [loading, setLoading] = useState(false);
const [filetimeout, setFiletimeout] = useState(30);
const [decryptType, setDecryptType] = useState('host');
const [password, setPassword] = useState('');
const [validateKeyMsg, setValidateKeyMsg] = useState('');
Expand Down Expand Up @@ -57,7 +61,7 @@ export default function EncryptFileModal({ color }) {
const closeModal = () => {
setCId('');
setValidateMsg('');
setPassword('')
setPassword('');
setValidateHostIdMsg('');
setHostId('');
setLoading(false);
Expand All @@ -67,7 +71,7 @@ export default function EncryptFileModal({ color }) {

const validateHostId = val => {
// let reg = /^[A-Za-z0-9]+$/;
let res = isIPFS.cid(val)
let res = isIPFS.cid(val);
// console.log(val,res,'-----')
if (!val || res) {
setValidateMsg('');
Expand All @@ -82,7 +86,7 @@ export default function EncryptFileModal({ color }) {
return false;
};

const checkPassword = (val) => {
const checkPassword = val => {
const reg = /^[0-9A-Za-z]{6,20}$/g;
if (!val || reg.test(val)) {
setValidateKeyMsg('');
Expand All @@ -95,7 +99,7 @@ export default function EncryptFileModal({ color }) {
setValidateKeyMsg('');
return true;
};
const validateDecryptHostId = (val)=>{
const validateDecryptHostId = val => {
let reg = /^[A-Za-z0-9]+$/;
if (!val || reg.test(val)) {
setValidateHostIdMsg('');
Expand All @@ -106,7 +110,7 @@ export default function EncryptFileModal({ color }) {
return false;
}
return true;
}
};

const cidChange = vals => {
const val = inputRef.current.value;
Expand All @@ -127,8 +131,7 @@ export default function EncryptFileModal({ color }) {
};

const DecryptFile = async () => {

if(!validateDecryptHostId(hostId)){
if (!validateDecryptHostId(hostId)) {
return;
}
if (cId && !validateHostId(cId)) {
Expand All @@ -141,7 +144,7 @@ export default function EncryptFileModal({ color }) {
return;
}

if (decryptType === 'password' && password ==='') {
if (decryptType === 'password' && password === '') {
setValidateKeyMsg(t('validate_decryptkey_null'));
return;
}
Expand All @@ -152,7 +155,7 @@ export default function EncryptFileModal({ color }) {

setLoading(true);
try {
await decryptUploadFiles(cId,hostId,password);
await decryptUploadFiles(cId, hostId, password);
setLoading(false);
Emitter.emit('showMessageAlert', {
message: 'decrypt_download_success',
Expand All @@ -167,6 +170,13 @@ export default function EncryptFileModal({ color }) {
const onChange = e => {
setDecryptType(e.target.value);
};


const handleChange = value => {
setFiletimeout(value)
}


return (
<CommonModal visible={showModal} onCancel={closeModal}>
<div className="common-modal-wrapper theme-bg">
Expand Down Expand Up @@ -217,11 +227,37 @@ export default function EncryptFileModal({ color }) {
<span className="theme-text-error text-xs pt-1">{validateHostIdMsg}</span>
</div>

<div className="flex justify-between w-full font-semibold">
<div>{t('dncrypt_file_time_out')}</div>
</div>
<div className="flex justify-between w-full text-xs font-medium theme-text-sub-info mb-3">
<div>{t('dncrypt_file_time_out_desc')}</div>
</div>
<Select
className="common-select"
popupClassName="theme-ant-select-popup"
defaultValue={filetimeout}
style={{ width: '100%' }}
onChange={handleChange}
>
{DECRYPT_FILE_TIME_OUT_LIST.map(item => {
return (
<Option key={item.value} value={item.value}>
{t(`${item.label}`)}
</Option>
);
})}
</Select>

<div className="flex justify-between w-full mb-4">
<span className="theme-text-error text-xs pt-1">{validateHostIdMsg}</span>
</div>

<div className="flex justify-between w-full font-semibold mb-3">
<div>{t('dncrypt_file_cid')}</div>
</div>
<input
id="file-input"
// id="file-input"
type="input"
className="w-full h-3 common-input theme-bg theme-border-color"
single="true"
Expand Down
95 changes: 80 additions & 15 deletions src/components/Tables/LocalFilesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import S3ApiTable from './S3ApiTable';
import { getRootFiles, getHashByPath, getFolerSize, getFiles, searchFiles } from 'services/filesService.js';
import { switchStorageUnit2 } from 'utils/BTFSUtil.js';
import { t } from 'utils/text.js';
import moment from 'moment';

import Emitter from 'utils/eventBus';

let didCancel = false;
Expand Down Expand Up @@ -177,6 +179,15 @@ export default function LocalFilesTable({ color }) {
}
};

const checkIsEncrypted = name => {
const arr = name.split('.');
const str = arr.slice(-1);
if(str === 'bte'){
return true
}
return false
};

const search = async () => {
let hash = inputRef.current.value;
let { Type, Message } = await searchFiles(hash);
Expand Down Expand Up @@ -210,7 +221,7 @@ export default function LocalFilesTable({ color }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

console.log("breadcrumbName", breadcrumbName);
console.log('breadcrumbName', breadcrumbName);

return (
<>
Expand Down Expand Up @@ -259,7 +270,6 @@ export default function LocalFilesTable({ color }) {
<div className="flex">
<ImportFilesEncryptDropdown color={color} path={breadcrumbName} />
<ImportFilesDropdown color={color} path={breadcrumbName} />

</div>
</div>
<div className="w-full overflow-x-auto">
Expand All @@ -274,10 +284,15 @@ export default function LocalFilesTable({ color }) {
onClick={selectAll}
/>
</th>
<th className="common-table-head-th" style={{ width: '70%' }}>
<th className="common-table-head-th" style={{ minWidth: '100px' }}>
{t('file_name')}
</th>
<th className="common-table-head-th">{t('size')}</th>
<th className="common-table-head-th" style={{ minWidth: '150px' }}>
{t('file_cid')}
</th>
<th className="common-table-head-th">{t('file_create')}</th>
<th className="common-table-head-th">{t('file_isencrypted')}</th>
<th className="common-table-head-th"></th>
</tr>
</thead>
Expand All @@ -294,39 +309,83 @@ export default function LocalFilesTable({ color }) {
name="checkbox"
className="bg-blue form-checkbox border-0 rounded text-blueGray-700 ml-1 w-5 h-5 ease-linear transition-all duration-150"
onClick={e => {
select(e, item['Hash'], item['Name'], item['Type'], item['Size'], breadcrumbName);
select(
e,
item['Hash'],
item['Name'],
item['Type'],
item['Size'],
breadcrumbName
);
}}
/>
</td>
<td className="common-table-body-td" style={{ minWidth: '350px' }}>
<td
className="common-table-body-td"
style={{ minWidth: '350px' }}>
<div className="flex">
<a
className="flex items-center"
onClick={() => {
addPath(item['Hash'], item['Name'], item['Type'], item['Size']);
addPath(
item['Hash'],
item['Name'],
item['Type'],
item['Size']
);
}}>
{item['Type'] === 1 && (
<img
src={require('assets/img/folder.png').default}
src={
require('assets/img/folder.png')
.default
}
className="h-12 w-12 bg-white rounded-full border"
alt="..."
/>
)}
{item['Type'] === 2 && (
<img
src={require('assets/img/file.png').default}
src={
require('assets/img/file.png')
.default
}
className="h-12 w-12 bg-white rounded-full border"
alt="..."
/>
)}
<div className="flex flex-col justify-center">
<span className="ml-3 font-bold">{item['Name']}</span>
<span className="ml-3 font-bold">{item['Hash']}</span>
<span className="ml-3 font-bold">
{item['Name']}
</span>
<span className="ml-3 font-bold">
{item['Hash']}
</span>
</div>
</a>
</div>
</td>
<td className="common-table-body-td">{switchStorageUnit2(item['Size'])}</td>
<td className="common-table-body-td">
{switchStorageUnit2(item['Size'])}
</td>
<td className="common-table-body-td">
{item.cid ? item.cid : '--'}
</td>
<td className="common-table-body-td">
{item.Created
? moment(item.Created).format(
'YYYY-MM-DD HH:mm:ss'
)
: '--'}
</td>
<td className="common-table-body-td">
{checkIsEncrypted(item['Name']) ? (
<span>{t('file_encrypted')}</span>
) : (
''
)}
</td>

<td className="common-table-body-td">
<FileTableDropdown
color={color}
Expand All @@ -335,6 +394,7 @@ export default function LocalFilesTable({ color }) {
size={item['Size']}
path={breadcrumbName}
type={item['Type']}
isEncrypetd = {checkIsEncrypted(item['Name'])}
/>
</td>
</tr>
Expand All @@ -351,7 +411,9 @@ export default function LocalFilesTable({ color }) {
/>
</div>
)}
{files && total === 0 && <div className="w-full flex justify-center p-4">{t('no_data')}</div>}
{files && total === 0 && (
<div className="w-full flex justify-center p-4">{t('no_data')}</div>
)}
</div>
<div className="mt-4 flex justify-between items-center">
<div>Total: {total}</div>
Expand All @@ -364,12 +426,15 @@ export default function LocalFilesTable({ color }) {
onChange={pageChange}
/>
</div>
<FileControl itemSelected={itemSelected} unSelect={unSelect} color={color} data={batch} />
<FileControl
itemSelected={itemSelected}
unSelect={unSelect}
color={color}
data={batch}
/>
</div>
</Tabs.TabPane>

</Tabs>

</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function Admin() {
});
} else {
window.loading = false;
window.nodeStatus = false;
window.nodeStatus = false;// true;// false;
dispatch({
type: 'SET_NODE_STATUS',
nodeStatus: false,
Expand Down
Loading

0 comments on commit 9056cb0

Please sign in to comment.