Skip to content

Commit

Permalink
Merge pull request #74 from bittorrent/v3.0.0
Browse files Browse the repository at this point in the history
V3.0.0
  • Loading branch information
lulu-tro authored Jun 3, 2024
2 parents 687f005 + 62e23de commit 8975f5a
Show file tree
Hide file tree
Showing 14 changed files with 844 additions and 415 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"chartjs-gauge": "^0.3.0",
"file-type": "^16.5.3",
"ipfs-http-client": "^54.0.0",
"is-ipfs": "6.0.2",
"moment": "^2.29.4",
"qrcode": "^1.5.0",
"qrcode.react": "^1.0.1",
Expand Down
9 changes: 5 additions & 4 deletions src/APIClient/APIClient10.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,19 @@ class APIClient10 {
}
}

encrypt(formData,to,onUploadProgress) {
return this.request(`/api/v1/encrypt?${to?'to='+to:''}`,formData,{
encrypt(formData,to,password,onUploadProgress) {
return this.request(`/api/v1/encrypt?${to?'to='+to:''}${password?'p='+password:''}`,formData,{
'headers':{
'Content-Type':'application/x-www-form-urlencoded',
},
'timeout': 0,
// signal: signal,
onUploadProgress:onUploadProgress
});
}

decrypt(hash, body, config) {
return this.request('/api/v1/decrypt?arg=' + hash, body, config);
decrypt({cid,hostid,password}, body, config) {
return this.request(`/api/v1/decrypt?arg=${cid}&from=${hostid}&p=${password}`, body, config);
}

// s3 api
Expand Down
Binary file added src/assets/img/key2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions src/assets/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,63 @@
}

}


.encrypt_upload_select{
.ant-radio-button-wrapper{
width: 50%;
text-align: center;
height: 38px;
line-height: 36px;
border-color:#3257f6;
color: #3257f6;
}
.ant-radio-button-wrapper:first-child{
border-radius:0.5rem 0 0 0.5rem;
}
.ant-radio-button-wrapper:last-child{
border-radius:0 0.5rem 0.5rem 0;
}
&.ant-radio-group-solid .ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled){
background: #3257f6;
border-color: #3257f6;
}

}

.common-input.random_key {
// height: 36px;
// background: #ffffff;
// box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.03);
// border-radius: 12px;
// opacity: 0.99;
// border: 1px solid #d7dbec;
// transition: all 0.5s;
padding: 4px 4px 4px 11px;
&:hover {
border-color: #d7dbec !important;
}

.get_key_btn.ant-btn {
// width: 239px;
height: 30px;
background: #888faf;
border-radius: 15px;
margin-top: 0;
line-height: 30px;
color: #fff;
.ant-btn-icon {
line-height: 30px;
vertical-align: text-bottom;
}
.key_img {
width: 14px;
height: 14px;
margin-right: 6px;
}
&:hover {
background: #3257f6 !important;
}
}
}

157 changes: 149 additions & 8 deletions src/components/Modals/DecryptFileModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@ 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 } from 'antd';
import { Spin, Radio } from 'antd';
import Emitter from 'utils/eventBus';
import { t } from 'utils/text.js';
import CommonModal from './CommonModal';
import isIPFS from 'is-ipfs';


let inputMaxLength = 80;
const options = [
{ label: 'decrypt_file_with_host', value: 'host' },
{ label: 'decrypt_file_with_password', value: 'password' },
];
let inputMaxLength = 100;

export default function EncryptFileModal({ color }) {
const intl = useIntl();
const [showModal, setShowModal] = useState(false);
const [cId, setCId] = useState('');
const [hostId, setHostId] = useState('');
const [validateMsg, setValidateMsg] = useState('');
const [validateHostIdMsg, setValidateHostIdMsg] = useState('');
const [loading, setLoading] = useState(false);
const [decryptType, setDecryptType] = useState('host');
const [password, setPassword] = useState('');
const [validateKeyMsg, setValidateKeyMsg] = useState('');
const inputRef = useRef(null);

const inputHostIdRef = useRef(null);
const inputKeyRef = useRef(null);

useEffect(() => {
const set = async function (params) {
console.log('openDecryptFileModal event has occured');
setCId('');
setValidateMsg('');
setPassword('');
setHostId('');
setValidateHostIdMsg('');
setLoading(false);
openModal();
};
Expand All @@ -43,31 +57,80 @@ export default function EncryptFileModal({ color }) {
const closeModal = () => {
setCId('');
setValidateMsg('');
setPassword('')
setValidateHostIdMsg('');
setHostId('');
setLoading(false);
setShowModal(false);
window.body.style.overflow = '';
};

const validateHostId = val => {
let reg = /^[A-Za-z0-9]+$/;
if (!val || reg.test(val)) {
// let reg = /^[A-Za-z0-9]+$/;
let res = isIPFS.cid(val)
// console.log(val,res,'-----')
if (!val || res) {
setValidateMsg('');
return true;
}
if (!reg.test(val)) {
// if (!reg.test(val)) {
// setValidateMsg(t('decrypt_file_cid_validate'));
// }
if (!res) {
setValidateMsg(t('decrypt_file_cid_validate'));
}
return false;
};

const checkPassword = (val) => {
const reg = /^[0-9A-Za-z]{6,20}$/g;
if (!val || reg.test(val)) {
setValidateKeyMsg('');
return true;
}
if (!reg.test(val)) {
setValidateKeyMsg(t('validate_encryptkey'));
return false;
}
setValidateKeyMsg('');
return true;
};
const validateDecryptHostId = (val)=>{
let reg = /^[A-Za-z0-9]+$/;
if (!val || reg.test(val)) {
setValidateHostIdMsg('');
return true;
}
if (!reg.test(val)) {
setValidateHostIdMsg(t('decrypt_file_hostId_validate'));
return false;
}
return true;
}

const cidChange = vals => {
const val = inputRef.current.value;
setCId(val);
validateHostId(val);
};

const hostIdChange = vals => {
const val = inputHostIdRef.current.value;
setHostId(val);
validateDecryptHostId(val);
};

const passwordChange = vals => {
const val = inputKeyRef.current.value;
setPassword(val);
checkPassword(val);
};

const DecryptFile = async () => {

if(!validateDecryptHostId(hostId)){
return;
}
if (cId && !validateHostId(cId)) {
setValidateMsg(t('decrypt_file_cid_validate'));
return;
Expand All @@ -78,9 +141,18 @@ export default function EncryptFileModal({ color }) {
return;
}

if (decryptType === 'password' && password ==='') {
setValidateKeyMsg(t('validate_decryptkey_null'));
return;
}

if (decryptType === 'password' && !checkPassword(password)) {
return;
}

setLoading(true);
try {
await decryptUploadFiles(cId);
await decryptUploadFiles(cId,hostId,password);
setLoading(false);
Emitter.emit('showMessageAlert', {
message: 'decrypt_download_success',
Expand All @@ -92,7 +164,9 @@ export default function EncryptFileModal({ color }) {
}
closeModal();
};

const onChange = e => {
setDecryptType(e.target.value);
};
return (
<CommonModal visible={showModal} onCancel={closeModal}>
<div className="common-modal-wrapper theme-bg">
Expand All @@ -102,6 +176,47 @@ export default function EncryptFileModal({ color }) {
{t('decrypt_upload_file_desc')}
</div>

<div className="font-semibold w-full mb-3">
<Radio.Group
onChange={onChange}
optionType="button"
buttonStyle="solid"
className="flex justify-between w-full encrypt_upload_select"
value={decryptType}>
{options.map(v => {
return (
<Radio value={v.value} key={v.value}>
<div className=" w-full font-semibold mb-3">
<p>{t(`${v.label}`)}</p>
</div>
</Radio>
);
})}
</Radio.Group>
</div>

<div className="flex justify-between w-full font-semibold">
<div>{t('dncrypt_file_hostid')}</div>
</div>
<div className="flex justify-between w-full text-xs font-medium theme-text-sub-info mb-3">
<div>{t('dncrypt_file_hostid_desc')}</div>
</div>
<input
id="file-input"
type="input"
className="w-full h-3 common-input theme-bg theme-border-color"
single="true"
// placeholder={intl.formatMessage({ id: 'decrypt_input_cid_placeholder' })}
maxLength={inputMaxLength}
ref={inputHostIdRef}
onChange={hostIdChange}
value={hostId}
readOnly={loading}
/>
<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>
Expand All @@ -115,6 +230,7 @@ export default function EncryptFileModal({ color }) {
ref={inputRef}
onChange={cidChange}
value={cId}
readOnly={loading}
/>
<div className="flex justify-between w-full mb-4">
<span className="theme-text-error text-xs pt-1">{validateMsg}</span>
Expand All @@ -124,6 +240,31 @@ export default function EncryptFileModal({ color }) {
// </span>
}
</div>

<div className={decryptType === 'host' ? 'w-full hidden' : 'w-full '}>
<div className="flex justify-between w-full font-semibold mb-3">
{t('decrypt_file_password')}
</div>
<div>
<input
placeholder={intl.formatMessage({ id: 'set_decrypt_key_placeholder' })}
className="common-input random_key"
maxLength={inputMaxLength}
ref={inputKeyRef}
onChange={passwordChange}
readOnly={loading}
value={password}
/>
<div className="flex justify-between text-xs w-full mb-4">
<span className="theme-text-error">{validateKeyMsg}</span>
{
// <span>
// {hostId.length || 0}/{inputMaxLength}
// </span>
}
</div>
</div>
</div>
<div className="mt-2">
<button
className="ml-2 common-btn theme-fill-gray text-gray-900 mr-6"
Expand Down
Loading

0 comments on commit 8975f5a

Please sign in to comment.