Skip to content
Merged
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
57 changes: 56 additions & 1 deletion client/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,59 @@ button:hover{

i{
transform: scale(0.8, 0.8);
}

}

.progress-container {
display: block;
position: relative;
width: 80%;
min-width: 400px;
height: 4rem;

margin: 15px auto;
padding: 0.5rem;

border-radius: 5px;

box-sizing: border-box;
background-color: rgba(255, 255, 255, 0.438);
}

.progress-container .txt {
position: absolute;
}

.progress {
width: 100%;
height: 10px;

border-radius: 10px;
background-color: #eee;
border: 1px solid #0000bb;
box-sizing: border-box;

margin-top: 2rem;
}

.progress-line {
width: 50%;
height: 100%;
border-radius: 10px;
background-color: #0000bb;
border: 1px solid #0000bb;
box-sizing: border-box;
}

.status {
position: relative;
margin-top: 0;
float: right;
color: #0000bb;
}

.no-transfer {
margin-top: 1.5rem;
color: #0000bb;
}

47 changes: 42 additions & 5 deletions client/assets/css/sent.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,54 @@

.option{
display: block;
position: relative;
width: 90%;
margin: 20px auto auto auto;
font-size: 1.5rem;
text-align: left;
}

#srvr-btn{
display: block;
width: 50%;
height: 1.5em;
#srvr-btn {
display: inline-block;
width: 43%;
min-width: 400px;
height: 4rem;
font-size: 2em;
margin-top: 10px;
margin-left: 5%;
}
}

.progress-container {
float: right;
width: 43%;
min-width: 400px;
height: 4rem;

margin-top: 10px;
margin-right: 5%;
padding: 0.5rem;

border-radius: 5px;

box-sizing: border-box;
background-color: rgba(255, 255, 255, 0.438);
}

@media screen and (max-width: 1000px) {
#srvr-btn {
display: block;
position: relative;
width: 90%;
height: 1.5em;
font-size: 2em;
margin: 10px auto;
}

.progress-container {
display: block;
position: relative;
width: 90%;
box-sizing: border-box;
}
}

105 changes: 49 additions & 56 deletions client/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,13 @@ var receivedFiles = Object.assign({}, DirectoryStruct); // Directory where rece
const chunkSize = 40000;

function redirect(path){
console.log(window.location);
fetch(window.location.origin+path).then((data)=>{
data.text().then((page)=>{
console.log(path);
$("#pageScript").remove();
$("head").append(getPageSpecificScripts(page));
$("body").html(getBody(page));
});
});
}

function getPageSpecificScripts(page){
const commnet = "<!-- PAGE SPECIFIC SCRIPTS-->";
const commentIndex = page.indexOf(commnet)+commnet.length;
return page.substring(commentIndex, page.indexOf("</body>"));
}

function getBody(page){
return page.substring(page.indexOf("<body>"),page.indexOf("</body>"));
}
Expand Down Expand Up @@ -177,23 +167,26 @@ socket.on('removeUser', function(data){

socket.on("start-transfer",function(data){
receivedSize = 0;
console.log(data);
packageSize = data.info.size;

data.info.files.forEach((file)=>{
if(receivedFiles[""+file.name])
console.log("Rewriting file");
receivedFiles[""+file.name] = {
data: new Uint8Array(),
type: "",
fileSize: file.fileSize
}
})
});

showProgressBar();
})

socket.on('data',function(data){
console.log(data);
var fileName = data.file.name;

receivedSize += data.file.data.byteLength;

updateReceivingBar();

if(receivedFiles[fileName]){
var concat = new Uint8Array(receivedFiles[fileName].data.byteLength + data.file.data.byteLength);
concat.set(new Uint8Array(receivedFiles[fileName].data));
Expand All @@ -202,15 +195,12 @@ socket.on('data',function(data){
receivedFiles[fileName].data = concat;

if(receivedFiles[fileName].data.byteLength == receivedFiles[fileName].fileSize){
console.log(`Making new ${fileName} file...`);
var newOriginal = new File([receivedFiles[fileName].data], fileName, {type:data.file.type});
var newFile = Object.assign({}, FileStruct);
newFile.original = newOriginal
newFile.path = data.file.path;

insertFile(newFile);

console.log(newFile);
}

writeLoadedFiles(workspaceFiles, filesListDiv);
Expand All @@ -228,7 +218,6 @@ socket.on('data',function(data){

function insertFile(file){
var pathSteps = file.path.split("/");
console.log(pathSteps);
var pathPassed = "/";

var dir = workspaceFiles;
Expand All @@ -251,10 +240,6 @@ function insertFile(file){
}

socket.on('request data',async function(data){
console.log("==================================");
console.log('Requested Data');
console.log('data');
console.log("==================================");
var fileToSent = null;
for(let i=0; i<selectedFiles.length; ++i){
if((selectedFiles[i].chunks == 0) ||
Expand All @@ -268,7 +253,9 @@ socket.on('request data',async function(data){
if(fileToSent == null){
socket.emit("transfer end",data);
alert("Data is sent!");
setTimeout(function() {$(".progress").hide();}, 1000);
setTimeout(function(){
removeProgressBar();
}, 1000);
return;
}

Expand All @@ -295,27 +282,28 @@ socket.on('request data',async function(data){
data: chunk
}
});

updateSendingBar();
});

socket.on("transfer end",function(data){
setTimeout(function() {$(".progress").hide();}, 1000);
receivedFiles = {};
setTimeout(function(){
removeProgressBar();
}, 1000);
});

async function sendToUser(name, id){
var files = extractFiles(workspaceFiles);
console.log(files);

for(let i=0;i<files.length;++i){
console.log("Processing "+i+"...");
selectedFiles.push(files[i]);
}

sentSize = 0;
packageSize = 0;
selectedFiles.forEach(function(item, idx){
packageSize += item.size();
console.log(item);
});

socket.emit("start-transfer",{
Expand All @@ -332,6 +320,8 @@ async function sendToUser(name, id){
}
});

showProgressBar();

var chunk = -1;
if(selectedFiles[0].size() < chunkSize){
chunk = await selectedFiles[0].data();
Expand All @@ -357,10 +347,7 @@ async function sendToUser(name, id){
sentSize += chunk.byteLength;
let percent = Math.round((sentSize*100)/packageSize);

$(".progress").show();
$(".progress-done").css("width", percent+'%');
$(".progress-done").css("opacity", "1");
$(".progress-done").html(percent+'%');
updateSendingBar();
};

function extractFiles(dir){
Expand Down Expand Up @@ -418,28 +405,6 @@ function updateUser(username){

updateUser(window.sessionStorage.getItem("username"));

/*function showUsers(){
if(activeUsers.length > 0){
$("#users").show();
}else{
$("#users").hide();
}

$("#users").empty();

if(activeUsers.length > 2){
$("users").css("height", `${(150+(activeUsers.length-2)*60)}px`);
}

var data = "<h3>Send to:</h3>\n";
activeUsers.forEach(function(val, idx){
let newButton = `<button class="button" onclick="sendToUser('${val.name}', '${val.id}');">${val.name}</button>\n`;
data += newButton;
});

$("#users").html(data);
}*/

function extractFileName(fullPath){
if (fullPath) {
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
Expand All @@ -451,10 +416,38 @@ function extractFileName(fullPath){
}
}

function showProgressBar(){
$("#no-transfer").hide();
$("#progress").show();
$("#status").show();
}

function updateSendingBar(){
if($("#progress").css('display') != 'block') return;

$("#progress-line").width( $("#progress").width() * (sentSize/packageSize) );
$("#status").html(`${sentSize}/${packageSize}`);
}

async function updateReceivingBar(){
if($("#progress").css('display') != 'block') return;

$("#progress-line").width( $("#progress").width() * (receivedSize/packageSize) );
$("#status").html(`${receivedSize}/${packageSize}`);
}

function removeProgressBar(){
$("#no-transfer").css("display", "block");

$("#progress-line").width(0);
$("#progress").css("display", "none");

$("#status").html("");
$("#status").css("display", "none");
}

function addFileToList(file){
var htmlData = $("#data ol").html();
console.log(`Adding ${file.name} to the page...`);
console.log(file);

let blob = new Blob([file.data], {type: file.type});
let url = window.URL.createObjectURL(blob);
Expand Down
12 changes: 10 additions & 2 deletions client/assets/js/sent.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ function sendToServer(){
}

(function(){
var head = $("head");
var link = $("<link rel='stylesheet' type='text/css' href='./assets/css/sent.css'>");
var head = document.getElementsByTagName("head")[0];

document.getElementsByName("css").forEach((node)=>node.remove());

var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", "./assets/css/sent.css");
link.setAttribute("name", "css");

head.append(link);

//Update server address on SEND page
Expand Down
12 changes: 10 additions & 2 deletions client/assets/js/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ $(".headerContainer").on('click', ()=>{
});

(function(){
var head = $("head");
var link = $("<link rel='stylesheet' type='text/css' href='./assets/css/index.css'>");
var head = document.getElementsByTagName("head")[0];
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", "./assets/css/index.css");
link.setAttribute("name", "css");

document.getElementsByName("css").forEach((node)=>node.remove());

head.append(link);

updateUser(window.sessionStorage.getItem("username"));
})();

Expand Down
Loading