Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,862 changes: 11,491 additions & 1,371 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@dfinity/identity": "^0.8.9",
"antd": "^4.16.1",
"axios": "^0.21.1",
"crypto-js": "^4.1.1",
"dropbox": "^4.0.30",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
17 changes: 0 additions & 17 deletions src/icdrive/FileHandle.mo
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ shared (msg) actor class FileHandle (){

stable var fileEntries : [(FileId, FileInfo)] = [];
stable var chunkEntries : [(ChunkId, ChunkData)] = [];
stable var public_file_url_entries : [(Text, FileId)] = [];

var state = FileTypes.empty();
stable var owner:Principal = msg.caller;
var fileUrlTrieMap = TrieMap.TrieMap<Text, FileId>(Text.equal, Text.hash);

public query(msg) func getOwner() : async Principal{
owner
Expand Down Expand Up @@ -214,7 +212,6 @@ shared (msg) actor class FileHandle (){
do ? {
assert(msg.caller==owner);
let fileInfo = state.files.get(fileId)!;
fileUrlTrieMap.put(fileHash, fileId);
state.files.put(fileId, {
userName = fileInfo.userName;
createdAt = fileInfo.createdAt ;
Expand All @@ -233,13 +230,6 @@ shared (msg) actor class FileHandle (){
}
};

public query(msg) func getPublicFileMeta(fileHash : Text) : async ?FileInfo {
do?{
let fileId = fileUrlTrieMap.get(fileHash)!;
let fileInfo = state.files.get(fileId)!;
};
};

public query(msg) func getPublicFileChunk(fileId : FileId, chunkNum : Nat) : async ?ChunkData {
do?{
let fileInfo = state.files.get(fileId)!;
Expand Down Expand Up @@ -322,7 +312,6 @@ shared (msg) actor class FileHandle (){
system func preupgrade() {
fileEntries := Iter.toArray(state.files.entries());
chunkEntries := Iter.toArray(state.chunks.entries());
public_file_url_entries := Iter.toArray(fileUrlTrieMap.entries());
};

system func postupgrade() {
Expand All @@ -349,15 +338,9 @@ shared (msg) actor class FileHandle (){
for ((chunkId, chunkData) in chunkEntries.vals()) {
state.chunks.put(chunkId, chunkData);
};

//Restore URL Hash and Data
for ((hash, data) in public_file_url_entries.vals()) {
fileUrlTrieMap.put(hash, data);
};

fileEntries := [];
chunkEntries := [];
public_file_url_entries := [];
};

///////////////////////////////////////////////////// TEST //////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions src/icdrive/backend/database.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module {
type FileCanister = ProfileTypes.FileCanister;
type UserName = ProfileTypes.UserName;

func makeProfile(userId: UserId, userName: UserName, fileCanister: FileCanister, email: Text): Profile {
func makeProfile(userId: UserId, userName: UserName, fileCanister: FileCanister, email: Text, name: Text): Profile {
{
id = userId;
fileCanister = fileCanister;
userName = userName;
name = "Anonymous";
name = name;
email = email;
createdAt = Time.now();
updateCanister = false;
Expand All @@ -32,8 +32,8 @@ module {
let hashMap = HashMap.HashMap<UserId, Profile>(1, isEq, Principal.hash);
let hashMapUserName = HashMap.HashMap<UserName, UserId>(1, isEqUserName, Text.hash);

public func createOne(userId: UserId, userName: UserName, fileCanister: FileCanister, email: Text) {
hashMap.put(userId, makeProfile(userId, userName, fileCanister, email));
public func createOne(userId: UserId, userName: UserName, fileCanister: FileCanister, email: Text, name: Text) {
hashMap.put(userId, makeProfile(userId, userName, fileCanister, email, name));
hashMapUserName.put(userName, userId);
};

Expand Down
4 changes: 2 additions & 2 deletions src/icdrive/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ shared (msg) actor class icdrive (){
stable var feedback : [Text] = [];
stable var userCount : Nat = 0;

public shared(msg) func createProfile(userName: UserName, email: Text) : async ?FileCanister {
public shared(msg) func createProfile(userName: UserName, email: Text, name: Text) : async ?FileCanister {
switch(user.findOne(msg.caller)){
case null{
Cycles.add(600_000_000_000);
let fileHandleObj = await FileHandle.FileHandle(); // dynamically install a new Canister

let canId = await fileHandleObj.createOwner(msg.caller);
user.createOne(msg.caller, userName, canId, email);
user.createOne(msg.caller, userName, canId, email, name);

let settings: CanisterSettings = {
controllers = [admin, msg.caller];
Expand Down
Binary file modified src/icdrive_assets/assets/FileHandle.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/icdrive_assets/assets/css/Profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
width: 100vw;
}
.innercontainer{
padding-top: calc(50vh - 100px);
padding-left: calc(50vw - 125px);
padding-top: calc(50vh - 125px);
padding-left: calc(50vw - 150px);
}
.waiting{
height: 200px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ListViewSearch from './SearchFile/ListViewSearch';
import GridViewSearch from './SearchFile/GridViewSearch';

// 3rd party imports
import { Progress, Menu, Dropdown, Input, Button, Modal } from 'antd';
import { Progress, Menu, Dropdown, Input, Button, Modal, Spin } from 'antd';
import { useSelector, useDispatch } from 'react-redux';
import {
MenuOutlined, AppstoreOutlined, CaretDownOutlined, CaretUpOutlined,
Expand Down Expand Up @@ -180,7 +180,7 @@ const CenterPortion = () => {
<div id="cp-right-section">
{
uploadSize / (1024 * 1024) < 2
? null
? <Spin size="small" />
: <Progress steps={4} percent={uploadProgress} />
}
</div>
Expand Down
35 changes: 19 additions & 16 deletions src/icdrive_assets/src/components/CenterPortion/Home/GridView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const GridView = () => {
const handleSharePublic = async () => {
setPublicLoadingFlag(true);
const response = await shareFilePublic(fileObj.current);
console.log(response)
if (response) {
fileObj.current.fileHash = response;
} else {
Expand All @@ -113,6 +114,9 @@ const GridView = () => {

const menu = (
<Menu>
<Menu.Item key="0" onClick={() => { }}>
<span id="context-download" role="button" tabIndex={0}></span>
</Menu.Item>
<Menu.Item key="1" onClick={() => { handleDownload(); }}>
<span id="context-download" role="button" tabIndex={0}>Download</span>
</Menu.Item>
Expand Down Expand Up @@ -156,26 +160,25 @@ const GridView = () => {
dispatch(switchFolder(value))
}
// Drag and Drop method begins
const onDragStart = (e) =>{
e.dataTransfer.setData("fileTransfer", [fileObj.current])
const onDragStart = (e, value) =>{
fileObj.current = value;
e.dataTransfer.setData("fileTransfer", [value])
}
const onDragOver = (e) =>{
e.preventDefault()
}
const onDrop = (e, value) =>{
const temp = [];
for (let i = 0; i < files.length; i+=1) {
if (files[i].id===fileObj.current.id) {
let current = Object.assign(fileObj.current);
current['folder'] = value;
temp.push(current);
continue;
let temp = [...files]

for (let i = 0; i < temp.length; i+=1) {
if (temp[i]['fileId']===fileObj.current.fileId) {
temp[i]['folder'] = value;
}
temp.push(files[i]);
}
console.log(temp)
dispatch(filesUpdate(temp));
dispatch(refreshComponents(true));
changeFileDirectory(temp);
changeFileDirectory(fileObj.current.fileId, value);
}
// Drag and Drop method ends

Expand All @@ -188,7 +191,7 @@ const GridView = () => {
<img id="display-icon" src="./icons/folder.svg" alt="file icon" />
</div>
<div className="grid-view-text-part truncate-overflow">
{value}
<p align="center">{value}</p>
</div>
</div>
))
Expand All @@ -198,7 +201,7 @@ const GridView = () => {
data.map((value) => (
<Dropdown overlayStyle={{ width: '150px', background: '#324851 !important', color: '#fff !important' }} overlay={menu} trigger={['contextMenu']}>
<Tooltip placement="right" title={()=>getToolTipText(value)}>
<div className="file-div" onDoubleClick={()=>{fileObj.current = value; handleView() }} onContextMenu={() => { fileObj.current = value; }} onDragStart={e=>{fileObj.current = value;onDragStart(e)}} draggable>
<div className="file-div" style={{zIndex:"2"}} onDoubleClick={()=>{fileObj.current = value; handleView() }} onContextMenu={() => { fileObj.current = value; }} onDragStart={e=>{onDragStart(e, value)}} draggable>
<div className="grid-view-icon-part">
{
isImage(value.mimeType)?
Expand All @@ -218,7 +221,7 @@ const GridView = () => {
}
</div>
<div className="grid-view-text-part truncate-overflow">
{value.name}
<p align="center">{value.name}</p>
</div>
</div>
</Tooltip>
Expand Down Expand Up @@ -266,9 +269,9 @@ const GridView = () => {
)
: (
<div>
<span id="public-url" style={{color:'#4D85BD'}} onClick={() => { navigator.clipboard.writeText(`${window.location.href}icdrive/${localStorage.getItem('fileCanister')}/${fileObj.current.fileHash}`); message.info('copied to clipboard'); }}>
<span id="public-url" style={{color:'#4D85BD'}} onClick={() => { navigator.clipboard.writeText(`${window.location.href}icdrive/*${fileObj.current.fileHash}`); message.info('copied to clipboard'); }}>
{window.location.href}
icdrive/{localStorage.getItem('fileCanister')}/
icdrive/*
{fileObj.current.fileHash}
</span>
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const GridViewMarked = () => {
}
</div>
<div className="grid-view-text-part truncate-overflow">
{value.name}
<p align="center">{value.name}</p>
</div>
</div>
</Tooltip>
Expand Down
11 changes: 6 additions & 5 deletions src/icdrive_assets/src/components/CenterPortion/Methods.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { idlFactory as FileHandleIdl } from 'dfx-generated/FileHandle';
// import * as streamSaver from 'streamsaver';
// import { WritableStream } from 'web-streams-polyfill/ponyfill'
import sha256 from 'sha256';
import AES from 'crypto-js/aes';
import { Actor } from '@dfinity/agent';
import { httpAgent, canisterHttpAgent, httpAgentIdentity } from '../../httpAgent';
/* Contain Download, File View, Mark File, Delete File and File Share Implementation */
Expand Down Expand Up @@ -126,9 +127,9 @@ export const shareFilePublic = async (fileObj) => {
if (flag) {
const userAgent = await canisterHttpAgent();
const data = `${fileObj.mimeType}$${fileObj.chunkCount.toString()}$${localStorage.getItem('fileCanister')}$${fileObj.fileId}`;
const fileHash = sha256(data);
await userAgent.makeFilePublic(fileObj.fileId, fileHash);
return (fileHash);
const encrypt = AES.encrypt(data, 'secret key 123').toString();
await userAgent.makeFilePublic(fileObj.fileId, encrypt);
return (encrypt);
}
return (false);
};
Expand Down Expand Up @@ -209,9 +210,9 @@ export const sendFeedback = async (feed) => {
await icdrive.addFeedback(feed);
};

export const changeFileDirectory = async (fileInfo) => {
export const changeFileDirectory = async (fileId, folder) => {
const userAgent = await canisterHttpAgent();
await userAgent.changeFileDirectory(fileInfo[0].fileId, fileInfo[0].folder);
await userAgent.changeFileDirectory(fileId, folder);
};

/* ----------------------------------------------Testing--------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const GridViewSearch = () => {
}
</div>
<div className="grid-view-text-part truncate-overflow">
{value.name}
<p align="center">{value.name}</p>
</div>
</div>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const GridViewShared = () => {
}
</div>
<div className="grid-view-text-part truncate-overflow">
{value.name}
<p align="center">{value.name}</p>
</div>
</div>
</Tooltip>
Expand Down
43 changes: 7 additions & 36 deletions src/icdrive_assets/src/components/LoginPage/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import { idlFactory as FileHandleIdl } from 'dfx-generated/FileHandle';
const Profile = () => {
const [dashboardFlag, setDashboardFlag] = React.useState(false);
const [userNameFlag, setUserNameFlag] = React.useState(false);
const [emailFlag, setEmailFlag] = React.useState(false);
const [emailId, setEmailId] = React.useState('');
const [loadingFlag, setLoadingFlag] = React.useState(false);
const userName = React.useRef('');
const userEmail = React.useRef('');

const createCanister = async () => {
setLoadingFlag(true);
Expand All @@ -28,15 +25,15 @@ const Profile = () => {
const icdrive = await httpAgent();
const checkName = await icdrive.checkUserName(userName.current.state.value);
if (!checkName) {
const create = await icdrive.createProfile(userName.current.state.value, emailId);
const create = await icdrive.createProfile(userName.current.state.value, '', '');
if (create.length === 1) {
localStorage.setItem('userName', userName.current.state.value);
localStorage.setItem('fileCanister', create[0].toText());
setUserNameFlag(false);
setLoadingFlag(false);
setDashboardFlag(true);
} else {
message.error('Cant access using this Email!');
message.error('Something Went Wrong!');
setLoadingFlag(false);
}
} else {
Expand All @@ -46,26 +43,16 @@ const Profile = () => {
}
};

const checkEmail = () =>{
setEmailId(userEmail.current.state.value)
setEmailFlag(false);
userEmail.current.state.value = '';
setUserNameFlag(true);
}

React.useEffect(() => {
const createGetProfile = async () => {
const icdrive = await httpAgent();
const profile = await icdrive.getProfile();
//console.log(profile)
// Check if user already exist else create his canister
if (profile.length === 0) {
setEmailFlag(true);
//setUserNameFlag(true);
setUserNameFlag(true);
} else {
if(profile[0].updateCanister){
//Update canister
//console.log(profile[0].fileCanister.toText());
const agent = await httpAgentIdentity();
const wasm_file = await fetch("./FileHandle.wasm");
const buffer = await wasm_file.arrayBuffer();
Expand All @@ -91,33 +78,17 @@ const Profile = () => {
{
dashboardFlag
? <Dashboard />
: emailFlag
? (
<div className="innercontainer">
<div className="waiting">
<div style={{ paddingTop: '20%' }}>
<span id="username">
Your Email:&nbsp;
<Input style={{ width: '80% !important' }} ref={userEmail} />
</span>
<br />
<br />
<Button type="primary" onClick={checkEmail}>Check Access</Button>
</div>
</div>
</div>
) : userNameFlag
: userNameFlag
? (
<div className="innercontainer">
<div className="waiting">
<div style={{ paddingTop: '20%' }}>
<span id="username">
Create Username:&nbsp;
Username:&nbsp;
<Input style={{ width: '80% !important' }} ref={userName} />
</span>
<br />
<br />
<Button type="primary" loading={loadingFlag} onClick={createCanister}>Continue</Button>
<br/><br/>
<Button type="primary" loading={loadingFlag} onClick={createCanister}>Create Account</Button>
</div>
</div>
</div>
Expand Down
Loading