ethoFS Upload Reset Bug Fix
This commit is contained in:
@@ -7,7 +7,7 @@ const path = require("path");
|
||||
const Buf = require('buffer').Buffer;
|
||||
const Common = require('ethereumjs-common');
|
||||
const fetch = require("node-fetch");
|
||||
const fs = require('fs');
|
||||
const fs = require("fs");
|
||||
const fileReaderPullStream = require('pull-file-reader')
|
||||
const request = require('request');
|
||||
const keythereum = require("keythereum");
|
||||
@@ -147,6 +147,9 @@ class Uploads {
|
||||
$('#ethofsLoginModal').iziModal();
|
||||
$('#ethofsLoginModal').iziModal('close');
|
||||
$('#ethofsRegistrationModal').iziModal('close');
|
||||
EthoUploads.resetUploadSystem();
|
||||
EthoUploads.resetUploadProcess();
|
||||
EthoUploads.resetUploadModal();
|
||||
//CREATE ETHER-1 CHAIN CONNECTION AND LOOK FOR EXISTING USER ACCOUNT
|
||||
if (privateKey != "") {
|
||||
GlobalPrivateKey = privateKey;
|
||||
@@ -528,7 +531,6 @@ class Uploads {
|
||||
document.getElementById("contract-cost").innerHTML = EthoUploads.round(GlobalContractCost, 2);
|
||||
document.getElementById("upload-hash").innerHTML = GlobalUploadHash;
|
||||
document.getElementById("upload-size").innerHTML = GlobalUploadSizeMB;
|
||||
GlobalContractCost = 0;
|
||||
return;
|
||||
}
|
||||
//CHECK FOR PROPAGATED & AVAILABLE DATA ON NETWORK - FINAL VERIFICATION FOR UPLOADED CONTENT
|
||||
@@ -912,6 +914,7 @@ class Uploads {
|
||||
}
|
||||
|
||||
resetFileTable() {
|
||||
document.getElementById("fileUploadButton").value = null;
|
||||
if (typeof ($fileHistory) != 'undefined' && $fileHistory != null) {
|
||||
while ($fileHistory.hasChildNodes()) {
|
||||
$fileHistory.removeChild($fileHistory.firstChild);
|
||||
@@ -1145,6 +1148,13 @@ class Uploads {
|
||||
MainFileArray = new Array();
|
||||
GlobalUploadSize = 0;
|
||||
GlobalUploadSizeMB = 0;
|
||||
GlobalMainHashArray = new Array();
|
||||
GlobalMainPathArray = new Array();
|
||||
GlobalHashArray = new Array();
|
||||
GlobalPathArray = new Array();
|
||||
GlobalUploadHash = "";
|
||||
GlobalUploadPath = "";
|
||||
GlobalContractCost = 0;
|
||||
}
|
||||
|
||||
updateAnalyzeProgress(width) {
|
||||
@@ -1159,153 +1169,6 @@ class Uploads {
|
||||
elem.innerHTML = width * 1 + '%';
|
||||
}
|
||||
|
||||
onFileUpload(event) {
|
||||
event.preventDefault()
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
MainFileArray.push([]);
|
||||
let dirSelected = event.target.files;
|
||||
let dirName = dirSelected[0].name;
|
||||
let dirPath = dirSelected[0].path;
|
||||
var streamCompareCount = 0;
|
||||
var totalUploadItems = 0;
|
||||
readDirectoryContents(dirPath);
|
||||
|
||||
function readDirectoryContents(directory) {
|
||||
console.log("Directory Path: " + directory);
|
||||
fs.readdir(directory, function(err, filesUploaded) {
|
||||
if (!err) {
|
||||
for (let i = 0; filesUploaded.length > i; i++) {
|
||||
handleItem(filesUploaded[i], directory);
|
||||
}
|
||||
} else {
|
||||
console.log("File Upload Error: " + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleItem(filename, relativePath) {
|
||||
var filepath = relativePath.concat(pathSymbol, filename);
|
||||
fs.stat(filepath, function(err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory()) {
|
||||
readDirectoryContents(filepath)
|
||||
} else {
|
||||
streamCompareCount++;
|
||||
totalUploadItems++;
|
||||
console.log("File Path: " + filepath);
|
||||
fs.readFile(filepath, function(err, file) {
|
||||
var updatedPath = filepath.replace(dirPath, dirName);
|
||||
var filetowrite = {
|
||||
path: updatedPath,
|
||||
content: file
|
||||
};
|
||||
var filename = updatedPath;
|
||||
MainFileArray[MainFileArray.length - 1].push(filetowrite);
|
||||
GlobalUploadSize += Number(stats.size);
|
||||
GlobalUploadSizeMB += Number(stats.size) / 1000000;
|
||||
fileSize += Number(stats.size) / 1000000;
|
||||
var totalUploadSizeMB = GlobalUploadSizeMB;
|
||||
EthoUploads.appendFile(updatedPath, filename, stats.size, null);
|
||||
console.log("Path: " + filepath + " Size: " + stats.size + " Total Size: " + GlobalUploadSize);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
EthoUploads.contractDurationChange(document.getElementById('contract-duration'));
|
||||
EthoUploads.updateAnalyzeProgress(((totalUploadItems - streamCompareCount) / totalUploadItems));
|
||||
if (streamCompareCount == 0) {
|
||||
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("File Stats Error: " + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
onDrop(event) {
|
||||
console.log(event);
|
||||
MainFileArray.push([]);
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
fileSize = 0;
|
||||
EthoUploads.resetProgress();
|
||||
EthoUploads.onDragLeave()
|
||||
event.preventDefault()
|
||||
if (GlobalUploadHash != "" && GlobalUploadPath != "") {
|
||||
GlobalMainHashArray.push(GlobalUploadHash);
|
||||
GlobalMainPathArray.push(GlobalUploadPath);
|
||||
}
|
||||
const dt = event.dataTransfer
|
||||
//const filesDropped = dt.files
|
||||
const itemsDropped = dt.items
|
||||
|
||||
function readFileContents(file) {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new window.FileReader()
|
||||
reader.onload = (event) => resolve(event.target.result)
|
||||
reader.readAsArrayBuffer(file)
|
||||
})
|
||||
}
|
||||
var totalItemCount = 0;
|
||||
var streamCompareCount = 0;
|
||||
|
||||
function initialHandleItems(items) {
|
||||
const files = [];
|
||||
totalItemCount = items.length;
|
||||
streamCompareCount = items.length;
|
||||
for (var item of items) {
|
||||
var awaitHandleEntry = handleEntry(item.webkitGetAsEntry());
|
||||
}
|
||||
|
||||
function handleEntry(entry) {
|
||||
if (entry.isFile) {
|
||||
getFile(entry);
|
||||
|
||||
function getFile(entry) {
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
entry.file(function(file) {
|
||||
readFileContents(file)
|
||||
.then((buffer) => {
|
||||
var filePath = entry.fullPath;
|
||||
var filetowrite = {
|
||||
path: entry.fullPath,
|
||||
content: Buffer.from(buffer)
|
||||
};
|
||||
MainFileArray[MainFileArray.length - 1].push(filetowrite);
|
||||
GlobalUploadSize += Number(file.size);
|
||||
fileSize += Number(file.size);
|
||||
var totalUploadSizeMB = GlobalUploadSize / 1000000;
|
||||
EthoUploads.appendFile(entry.fullPath, entry.name, file.size, null);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
EthoUploads.contractDurationChange(document.getElementById('contract-duration'));
|
||||
streamCompareCount--;
|
||||
EthoUploads.updateAnalyzeProgress(((totalItemCount - streamCompareCount) / totalItemCount));
|
||||
if (streamCompareCount == 0) {
|
||||
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} else if (entry.isDirectory) {
|
||||
let directoryReader = entry.createReader();
|
||||
directoryReader.readEntries(function(entries) {
|
||||
streamCompareCount += entries.length - 1;
|
||||
totalItemCount += entries.length - 1;
|
||||
entries.forEach(function(newEntry) {
|
||||
handleEntry(newEntry);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
initialHandleItems(event.dataTransfer.items);
|
||||
}
|
||||
|
||||
connectToPeer(event) {
|
||||
const multiaddr = $multiaddrInput.value
|
||||
|
||||
@@ -1409,7 +1272,7 @@ class Uploads {
|
||||
}
|
||||
|
||||
|
||||
renderUploads() {
|
||||
renderUploads(ethofsRenderFlag) {
|
||||
EthoMainGUI.renderTemplate("uploads.html", {});
|
||||
$(document).trigger("render_uploads");
|
||||
}
|
||||
@@ -1419,6 +1282,156 @@ class Uploads {
|
||||
EthoUploads = new Uploads();
|
||||
|
||||
|
||||
function onFileUpload(event) {
|
||||
event.preventDefault()
|
||||
GlobalUploadSize = 0;
|
||||
GlobalUploadSizeMB = 0;
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
MainFileArray.push([]);
|
||||
let dirSelected = event.target.files;
|
||||
let dirName = dirSelected[0].name;
|
||||
let dirPath = dirSelected[0].path;
|
||||
var streamCompareCount = 0;
|
||||
var totalUploadItems = 0;
|
||||
readDirectoryContents(dirPath);
|
||||
|
||||
function readDirectoryContents(directory) {
|
||||
console.log("Directory Path: " + directory);
|
||||
fs.readdir(directory, function (err, filesUploaded) {
|
||||
if (!err) {
|
||||
for (let i = 0; filesUploaded.length > i; i++) {
|
||||
handleItem(filesUploaded[i], directory);
|
||||
}
|
||||
} else {
|
||||
console.log("File Upload Error: " + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleItem(filename, relativePath) {
|
||||
var filepath = relativePath.concat(pathSymbol, filename);
|
||||
fs.stat(filepath, function (err, stats) {
|
||||
if (!err) {
|
||||
if (stats.isDirectory()) {
|
||||
readDirectoryContents(filepath)
|
||||
} else {
|
||||
streamCompareCount++;
|
||||
totalUploadItems++;
|
||||
console.log("File Path: " + filepath);
|
||||
fs.readFile(filepath, function (err, file) {
|
||||
var updatedPath = filepath.replace(dirPath, dirName);
|
||||
var filetowrite = {
|
||||
path: updatedPath,
|
||||
content: file
|
||||
};
|
||||
var filename = updatedPath;
|
||||
MainFileArray[MainFileArray.length - 1].push(filetowrite);
|
||||
GlobalUploadSize += Number(stats.size);
|
||||
GlobalUploadSizeMB += Number(stats.size) / 1000000;
|
||||
fileSize += Number(stats.size) / 1000000;
|
||||
var totalUploadSizeMB = GlobalUploadSizeMB;
|
||||
EthoUploads.appendFile(updatedPath, filename, stats.size, null);
|
||||
console.log("Path: " + filepath + " Size: " + stats.size + " Total Size: " + GlobalUploadSize);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
EthoUploads.contractDurationChange(document.getElementById('contract-duration'));
|
||||
EthoUploads.updateAnalyzeProgress(((totalUploadItems - streamCompareCount) / totalUploadItems));
|
||||
if (streamCompareCount == 0) {
|
||||
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("File Stats Error: " + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onDrop(event) {
|
||||
console.log(event);
|
||||
MainFileArray.push([]);
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
fileSize = 0;
|
||||
EthoUploads.resetProgress();
|
||||
EthoUploads.onDragLeave()
|
||||
event.preventDefault()
|
||||
if (GlobalUploadHash != "" && GlobalUploadPath != "") {
|
||||
GlobalMainHashArray.push(GlobalUploadHash);
|
||||
GlobalMainPathArray.push(GlobalUploadPath);
|
||||
}
|
||||
const dt = event.dataTransfer
|
||||
//const filesDropped = dt.files
|
||||
const itemsDropped = dt.items
|
||||
|
||||
function readFileContents(file) {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new window.FileReader()
|
||||
reader.onload = (event) => resolve(event.target.result)
|
||||
reader.readAsArrayBuffer(file)
|
||||
})
|
||||
}
|
||||
var totalItemCount = 0;
|
||||
var streamCompareCount = 0;
|
||||
|
||||
function initialHandleItems(items) {
|
||||
const files = [];
|
||||
totalItemCount = items.length;
|
||||
streamCompareCount = items.length;
|
||||
for (var item of items) {
|
||||
var awaitHandleEntry = handleEntry(item.webkitGetAsEntry());
|
||||
}
|
||||
|
||||
function handleEntry(entry) {
|
||||
if (entry.isFile) {
|
||||
getFile(entry);
|
||||
|
||||
function getFile(entry) {
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
entry.file(function (file) {
|
||||
readFileContents(file)
|
||||
.then((buffer) => {
|
||||
var filePath = entry.fullPath;
|
||||
var filetowrite = {
|
||||
path: entry.fullPath,
|
||||
content: Buffer.from(buffer)
|
||||
};
|
||||
MainFileArray[MainFileArray.length - 1].push(filetowrite);
|
||||
GlobalUploadSize += Number(file.size);
|
||||
fileSize += Number(file.size);
|
||||
var totalUploadSizeMB = GlobalUploadSize / 1000000;
|
||||
EthoUploads.appendFile(entry.fullPath, entry.name, file.size, null);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
EthoUploads.contractDurationChange(document.getElementById('contract-duration'));
|
||||
streamCompareCount--;
|
||||
EthoUploads.updateAnalyzeProgress(((totalItemCount - streamCompareCount) / totalItemCount));
|
||||
if (streamCompareCount == 0) {
|
||||
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} else if (entry.isDirectory) {
|
||||
let directoryReader = entry.createReader();
|
||||
directoryReader.readEntries(function (entries) {
|
||||
streamCompareCount += entries.length - 1;
|
||||
totalItemCount += entries.length - 1;
|
||||
entries.forEach(function (newEntry) {
|
||||
handleEntry(newEntry);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
initialHandleItems(event.dataTransfer.items);
|
||||
}
|
||||
|
||||
$(document).on("render_uploads", function () {
|
||||
$('#privatekeytable').hide();
|
||||
$('#walletpasswordtable').hide();
|
||||
@@ -1450,6 +1463,23 @@ $(document).on("render_uploads", function() {
|
||||
EthoUploads.beforeLoginState();
|
||||
EthoUploads.checkExistingLogin(GlobalPrivateKey);
|
||||
|
||||
fetch('https://api.coinmarketcap.com/v2/ticker/3452/').then(response => {
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
var ethoPriceUSD = data.data.quotes.USD.price;
|
||||
document.getElementById("ethoprice").textContent = EthoUploads.round(ethoPriceUSD, 4);
|
||||
}).catch(err => {});
|
||||
});
|
||||
|
||||
function getKeyStoreLocation() {
|
||||
switch (os.type()) {
|
||||
case "Darwin":
|
||||
return path.join(os.homedir(), "Library", "Ether1");
|
||||
break;
|
||||
default:
|
||||
return path.join(process.env.APPDATA, "Ether1");
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on("dragenter", "#drag-container", function (event) {
|
||||
EthoUploads.onDragEnter(event);
|
||||
@@ -1460,7 +1490,7 @@ $(document).on("render_uploads", function() {
|
||||
});
|
||||
|
||||
$(document).on("drop", "#drag-container", function (event) {
|
||||
EthoUploads.onDrop(event.originalEvent);
|
||||
onDrop(event.originalEvent);
|
||||
});
|
||||
|
||||
$(document).on("dragleave", "#drag-container", function (event) {
|
||||
@@ -1468,7 +1498,7 @@ $(document).on("render_uploads", function() {
|
||||
});
|
||||
|
||||
$(document).on("change", "#fileUploadButton", function (event) {
|
||||
EthoUploads.onFileUpload(event);
|
||||
onFileUpload(event);
|
||||
});
|
||||
|
||||
$(document).on("click", "#main-login-button", function (event) {
|
||||
@@ -1559,13 +1589,23 @@ $(document).on("render_uploads", function() {
|
||||
$(document).on("click", "#defaultModal-close", function (event) {
|
||||
$('#defaultModal').iziModal('close');
|
||||
EthoUploads.resetUploadSystem();
|
||||
EthoUploads.resetUploadProcess();
|
||||
EthoUploads.resetUploadModal();
|
||||
});
|
||||
|
||||
$(document).on("click", "#defaultModal-next", function (event) {
|
||||
$('#defaultModal2').iziModal({
|
||||
onOpened: function () {
|
||||
//EthoUploads.resetFileTable();
|
||||
},
|
||||
onOpening: function () {
|
||||
EthoUploads.resetFileTable();
|
||||
},
|
||||
onClosed: function () {
|
||||
//document.getElementById("fileUploadButton").value = "";
|
||||
},
|
||||
onHide: function () {
|
||||
//document.getElementById("fileUploadButton").value = "";
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1577,6 +1617,7 @@ $(document).on("render_uploads", function() {
|
||||
$(document).on("click", "#defaultModal2-close", function (event) {
|
||||
$('#defaultModal2').iziModal('close');
|
||||
EthoUploads.resetUploadSystem();
|
||||
EthoUploads.resetUploadProcess();
|
||||
EthoUploads.resetUploadModal();
|
||||
});
|
||||
|
||||
@@ -1585,7 +1626,14 @@ $(document).on("render_uploads", function() {
|
||||
});
|
||||
|
||||
$(document).on("click", "#confirm-files-button", function (event) {
|
||||
$('#defaultModal3').iziModal();
|
||||
$('#defaultModal3').iziModal({
|
||||
onClosed: function () {
|
||||
document.getElementById("fileUploadButton").value = null;
|
||||
},
|
||||
onHidden: function () {
|
||||
document.getElementById("fileUploadButton").value = null;
|
||||
}
|
||||
});
|
||||
$('#defaultModal3').iziModal('open');
|
||||
document.getElementById("contract-cost").innerHTML = EthoUploads.round(GlobalContractCost, 2);
|
||||
$('#defaultModal2').iziModal('close');
|
||||
@@ -1597,6 +1645,7 @@ $(document).on("render_uploads", function() {
|
||||
$(document).on("click", "#defaultModal3-close", function (event) {
|
||||
$('#defaultModal3').iziModal('close');
|
||||
EthoUploads.resetUploadSystem();
|
||||
EthoUploads.resetUploadProcess();
|
||||
EthoUploads.resetUploadModal();
|
||||
});
|
||||
|
||||
@@ -1631,21 +1680,3 @@ $(document).on("render_uploads", function() {
|
||||
$(document).on("change", "#extend-contract", function (event) {
|
||||
EthoUploads.contractExtensionChange(document.getElementById('extend-contract'));
|
||||
});
|
||||
|
||||
fetch('https://api.coinmarketcap.com/v2/ticker/3452/').then(response => {
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
var ethoPriceUSD = data.data.quotes.USD.price;
|
||||
document.getElementById("ethoprice").textContent = EthoUploads.round(ethoPriceUSD, 4);
|
||||
}).catch(err => {});
|
||||
});
|
||||
|
||||
function getKeyStoreLocation() {
|
||||
switch (os.type()) {
|
||||
case "Darwin":
|
||||
return path.join(os.homedir(), "Library", "Ether1");
|
||||
break;
|
||||
default:
|
||||
return path.join(process.env.APPDATA, "Ether1");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user