Initial ethoFS Integration
This commit is contained in:
469
assets/dashboard/js/admin.js
Normal file
469
assets/dashboard/js/admin.js
Normal file
@@ -0,0 +1,469 @@
|
||||
if (typeof jQuery === "undefined") {
|
||||
throw new Error("jQuery plugins need to be before this file");
|
||||
}
|
||||
|
||||
$.AdminBSB = {};
|
||||
$.AdminBSB.options = {
|
||||
colors: {
|
||||
red: '#F44336',
|
||||
pink: '#E91E63',
|
||||
purple: '#9C27B0',
|
||||
deepPurple: '#673AB7',
|
||||
indigo: '#3F51B5',
|
||||
blue: '#2196F3',
|
||||
lightBlue: '#03A9F4',
|
||||
cyan: '#00BCD4',
|
||||
teal: '#009688',
|
||||
green: '#4CAF50',
|
||||
lightGreen: '#8BC34A',
|
||||
lime: '#CDDC39',
|
||||
yellow: '#ffe821',
|
||||
amber: '#FFC107',
|
||||
orange: '#FF9800',
|
||||
deepOrange: '#FF5722',
|
||||
brown: '#795548',
|
||||
grey: '#9E9E9E',
|
||||
blueGrey: '#607D8B',
|
||||
black: '#000000',
|
||||
white: '#ffffff'
|
||||
},
|
||||
leftSideBar: {
|
||||
scrollColor: 'rgba(0,0,0,0.5)',
|
||||
scrollWidth: '4px',
|
||||
scrollAlwaysVisible: false,
|
||||
scrollBorderRadius: '0',
|
||||
scrollRailBorderRadius: '0',
|
||||
scrollActiveItemWhenPageLoad: true,
|
||||
breakpointWidth: 1170
|
||||
},
|
||||
dropdownMenu: {
|
||||
effectIn: 'fadeIn',
|
||||
effectOut: 'fadeOut'
|
||||
}
|
||||
}
|
||||
|
||||
/* Left Sidebar - Function =================================================================================================
|
||||
* You can manage the left sidebar menu options
|
||||
*
|
||||
*/
|
||||
$.AdminBSB.leftSideBar = {
|
||||
activate: function () {
|
||||
var _this = this;
|
||||
var $body = $('body');
|
||||
var $overlay = $('.overlay');
|
||||
|
||||
//Close sidebar
|
||||
$(window).click(function (e) {
|
||||
var $target = $(e.target);
|
||||
if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
|
||||
|
||||
if (!$target.hasClass('bars') && _this.isOpen() && $target.parents('#leftsidebar').length === 0) {
|
||||
if (!$target.hasClass('js-right-sidebar')) $overlay.fadeOut();
|
||||
$body.removeClass('overlay-open');
|
||||
}
|
||||
});
|
||||
|
||||
$.each($('.menu-toggle.toggled'), function (i, val) {
|
||||
$(val).next().slideToggle(0);
|
||||
});
|
||||
|
||||
//When page load
|
||||
$.each($('.menu .list li.active'), function (i, val) {
|
||||
var $activeAnchors = $(val).find('a:eq(0)');
|
||||
|
||||
$activeAnchors.addClass('toggled');
|
||||
$activeAnchors.next().show();
|
||||
});
|
||||
|
||||
//Collapse or Expand Menu
|
||||
$('.menu-toggle').on('click', function (e) {
|
||||
var $this = $(this);
|
||||
var $content = $this.next();
|
||||
|
||||
if ($($this.parents('ul')[0]).hasClass('list')) {
|
||||
var $not = $(e.target).hasClass('menu-toggle') ? e.target : $(e.target).parents('.menu-toggle');
|
||||
|
||||
$.each($('.menu-toggle.toggled').not($not).next(), function (i, val) {
|
||||
if ($(val).is(':visible')) {
|
||||
$(val).prev().toggleClass('toggled');
|
||||
$(val).slideUp();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$this.toggleClass('toggled');
|
||||
$content.slideToggle(320);
|
||||
});
|
||||
|
||||
//Set menu height
|
||||
_this.setMenuHeight(true);
|
||||
_this.checkStatusForResize(true);
|
||||
$(window).resize(function () {
|
||||
_this.setMenuHeight(false);
|
||||
_this.checkStatusForResize(false);
|
||||
});
|
||||
|
||||
//Set Waves
|
||||
Waves.attach('.menu .list a', ['waves-block']);
|
||||
Waves.init();
|
||||
},
|
||||
setMenuHeight: function (isFirstTime) {
|
||||
if (typeof $.fn.slimScroll != 'undefined') {
|
||||
var configs = $.AdminBSB.options.leftSideBar;
|
||||
var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));
|
||||
var $el = $('.list');
|
||||
|
||||
if (!isFirstTime) {
|
||||
$el.slimscroll({
|
||||
destroy: true
|
||||
});
|
||||
}
|
||||
|
||||
$el.slimscroll({
|
||||
height: height + "px",
|
||||
color: configs.scrollColor,
|
||||
size: configs.scrollWidth,
|
||||
alwaysVisible: configs.scrollAlwaysVisible,
|
||||
borderRadius: configs.scrollBorderRadius,
|
||||
railBorderRadius: configs.scrollRailBorderRadius
|
||||
});
|
||||
|
||||
//Scroll active menu item when page load, if option set = true
|
||||
if ($.AdminBSB.options.leftSideBar.scrollActiveItemWhenPageLoad) {
|
||||
var item = $('.menu .list li.active')[0];
|
||||
if (item) {
|
||||
var activeItemOffsetTop = item.offsetTop;
|
||||
if (activeItemOffsetTop > 150) $el.slimscroll({ scrollTo: activeItemOffsetTop + 'px' });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
checkStatusForResize: function (firstTime) {
|
||||
var $body = $('body');
|
||||
var $openCloseBar = $('.navbar .navbar-header .bars');
|
||||
var width = $body.width();
|
||||
|
||||
if (firstTime) {
|
||||
$body.find('.content, .sidebar').addClass('no-animate').delay(1000).queue(function () {
|
||||
$(this).removeClass('no-animate').dequeue();
|
||||
});
|
||||
}
|
||||
|
||||
if (width < $.AdminBSB.options.leftSideBar.breakpointWidth) {
|
||||
$body.addClass('ls-closed');
|
||||
$openCloseBar.fadeIn();
|
||||
}
|
||||
else {
|
||||
$body.removeClass('ls-closed');
|
||||
$openCloseBar.fadeOut();
|
||||
}
|
||||
},
|
||||
isOpen: function () {
|
||||
return $('body').hasClass('overlay-open');
|
||||
}
|
||||
};
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Right Sidebar - Function ================================================================================================
|
||||
* You can manage the right sidebar menu options
|
||||
*
|
||||
*/
|
||||
$.AdminBSB.rightSideBar = {
|
||||
activate: function () {
|
||||
var _this = this;
|
||||
var $sidebar = $('#rightsidebar');
|
||||
var $overlay = $('.overlay');
|
||||
|
||||
//Close sidebar
|
||||
$(window).click(function (e) {
|
||||
var $target = $(e.target);
|
||||
if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
|
||||
|
||||
if (!$target.hasClass('js-right-sidebar') && _this.isOpen() && $target.parents('#rightsidebar').length === 0) {
|
||||
if (!$target.hasClass('bars')) $overlay.fadeOut();
|
||||
$sidebar.removeClass('open');
|
||||
}
|
||||
});
|
||||
|
||||
$('.js-right-sidebar').on('click', function () {
|
||||
$sidebar.toggleClass('open');
|
||||
if (_this.isOpen()) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
|
||||
});
|
||||
},
|
||||
isOpen: function () {
|
||||
return $('.right-sidebar').hasClass('open');
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Searchbar - Function ================================================================================================
|
||||
* You can manage the search bar
|
||||
*
|
||||
*/
|
||||
var $searchBar = $('.search-bar');
|
||||
$.AdminBSB.search = {
|
||||
activate: function () {
|
||||
var _this = this;
|
||||
|
||||
//Search button click event
|
||||
$('.js-search').on('click', function () {
|
||||
_this.showSearchBar();
|
||||
});
|
||||
|
||||
//Close search click event
|
||||
$searchBar.find('.close-search').on('click', function () {
|
||||
_this.hideSearchBar();
|
||||
});
|
||||
|
||||
//ESC key on pressed
|
||||
$searchBar.find('input[type="text"]').on('keyup', function (e) {
|
||||
if (e.keyCode == 27) {
|
||||
_this.hideSearchBar();
|
||||
}
|
||||
});
|
||||
},
|
||||
showSearchBar: function () {
|
||||
$searchBar.addClass('open');
|
||||
$searchBar.find('input[type="text"]').focus();
|
||||
},
|
||||
hideSearchBar: function () {
|
||||
$searchBar.removeClass('open');
|
||||
$searchBar.find('input[type="text"]').val('');
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Navbar - Function =======================================================================================================
|
||||
* You can manage the navbar
|
||||
*
|
||||
*/
|
||||
$.AdminBSB.navbar = {
|
||||
activate: function () {
|
||||
var $body = $('body');
|
||||
var $overlay = $('.overlay');
|
||||
|
||||
//Open left sidebar panel
|
||||
$('.bars').on('click', function () {
|
||||
$body.toggleClass('overlay-open');
|
||||
if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
|
||||
});
|
||||
|
||||
//Close collapse bar on click event
|
||||
$('.nav [data-close="true"]').on('click', function () {
|
||||
var isVisible = $('.navbar-toggle').is(':visible');
|
||||
var $navbarCollapse = $('.navbar-collapse');
|
||||
|
||||
if (isVisible) {
|
||||
$navbarCollapse.slideUp(function () {
|
||||
$navbarCollapse.removeClass('in').removeAttr('style');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Input - Function ========================================================================================================
|
||||
* You can manage the inputs(also textareas) with name of class 'form-control'
|
||||
*
|
||||
*/
|
||||
$.AdminBSB.input = {
|
||||
activate: function ($parentSelector) {
|
||||
$parentSelector = $parentSelector || $('body');
|
||||
|
||||
//On focus event
|
||||
$parentSelector.find('.form-control').focus(function () {
|
||||
$(this).closest('.form-line').addClass('focused');
|
||||
});
|
||||
|
||||
//On focusout event
|
||||
$parentSelector.find('.form-control').focusout(function () {
|
||||
var $this = $(this);
|
||||
if ($this.parents('.form-group').hasClass('form-float')) {
|
||||
if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); }
|
||||
}
|
||||
else {
|
||||
$this.parents('.form-line').removeClass('focused');
|
||||
}
|
||||
});
|
||||
|
||||
//On label click
|
||||
$parentSelector.on('click', '.form-float .form-line .form-label', function () {
|
||||
$(this).parent().find('input').focus();
|
||||
});
|
||||
|
||||
//Not blank form
|
||||
$parentSelector.find('.form-control').each(function () {
|
||||
if ($(this).val() !== '') {
|
||||
$(this).parents('.form-line').addClass('focused');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Form - Select - Function ================================================================================================
|
||||
* You can manage the 'select' of form elements
|
||||
*
|
||||
*/
|
||||
$.AdminBSB.select = {
|
||||
activate: function () {
|
||||
if ($.fn.selectpicker) { $('select:not(.ms)').selectpicker(); }
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* DropdownMenu - Function =================================================================================================
|
||||
* You can manage the dropdown menu
|
||||
*
|
||||
*/
|
||||
|
||||
$.AdminBSB.dropdownMenu = {
|
||||
activate: function () {
|
||||
var _this = this;
|
||||
|
||||
$('.dropdown, .dropup, .btn-group').on({
|
||||
"show.bs.dropdown": function () {
|
||||
var dropdown = _this.dropdownEffect(this);
|
||||
_this.dropdownEffectStart(dropdown, dropdown.effectIn);
|
||||
},
|
||||
"shown.bs.dropdown": function () {
|
||||
var dropdown = _this.dropdownEffect(this);
|
||||
if (dropdown.effectIn && dropdown.effectOut) {
|
||||
_this.dropdownEffectEnd(dropdown, function () { });
|
||||
}
|
||||
},
|
||||
"hide.bs.dropdown": function (e) {
|
||||
var dropdown = _this.dropdownEffect(this);
|
||||
if (dropdown.effectOut) {
|
||||
e.preventDefault();
|
||||
_this.dropdownEffectStart(dropdown, dropdown.effectOut);
|
||||
_this.dropdownEffectEnd(dropdown, function () {
|
||||
dropdown.dropdown.removeClass('open');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Set Waves
|
||||
Waves.attach('.dropdown-menu li a', ['waves-block']);
|
||||
Waves.init();
|
||||
},
|
||||
dropdownEffect: function (target) {
|
||||
var effectIn = $.AdminBSB.options.dropdownMenu.effectIn, effectOut = $.AdminBSB.options.dropdownMenu.effectOut;
|
||||
var dropdown = $(target), dropdownMenu = $('.dropdown-menu', target);
|
||||
|
||||
if (dropdown.length > 0) {
|
||||
var udEffectIn = dropdown.data('effect-in');
|
||||
var udEffectOut = dropdown.data('effect-out');
|
||||
if (udEffectIn !== undefined) { effectIn = udEffectIn; }
|
||||
if (udEffectOut !== undefined) { effectOut = udEffectOut; }
|
||||
}
|
||||
|
||||
return {
|
||||
target: target,
|
||||
dropdown: dropdown,
|
||||
dropdownMenu: dropdownMenu,
|
||||
effectIn: effectIn,
|
||||
effectOut: effectOut
|
||||
};
|
||||
},
|
||||
dropdownEffectStart: function (data, effectToStart) {
|
||||
if (effectToStart) {
|
||||
data.dropdown.addClass('dropdown-animating');
|
||||
data.dropdownMenu.addClass('animated dropdown-animated');
|
||||
data.dropdownMenu.addClass(effectToStart);
|
||||
}
|
||||
},
|
||||
dropdownEffectEnd: function (data, callback) {
|
||||
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
|
||||
data.dropdown.one(animationEnd, function () {
|
||||
data.dropdown.removeClass('dropdown-animating');
|
||||
data.dropdownMenu.removeClass('animated dropdown-animated');
|
||||
data.dropdownMenu.removeClass(data.effectIn);
|
||||
data.dropdownMenu.removeClass(data.effectOut);
|
||||
|
||||
if (typeof callback == 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
/* Browser - Function ======================================================================================================
|
||||
* You can manage browser
|
||||
*
|
||||
*/
|
||||
var edge = 'Microsoft Edge';
|
||||
var ie10 = 'Internet Explorer 10';
|
||||
var ie11 = 'Internet Explorer 11';
|
||||
var opera = 'Opera';
|
||||
var firefox = 'Mozilla Firefox';
|
||||
var chrome = 'Google Chrome';
|
||||
var safari = 'Safari';
|
||||
|
||||
$.AdminBSB.browser = {
|
||||
activate: function () {
|
||||
var _this = this;
|
||||
var className = _this.getClassName();
|
||||
|
||||
if (className !== '') $('html').addClass(_this.getClassName());
|
||||
},
|
||||
getBrowser: function () {
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
|
||||
if (/edge/i.test(userAgent)) {
|
||||
return edge;
|
||||
} else if (/rv:11/i.test(userAgent)) {
|
||||
return ie11;
|
||||
} else if (/msie 10/i.test(userAgent)) {
|
||||
return ie10;
|
||||
} else if (/opr/i.test(userAgent)) {
|
||||
return opera;
|
||||
} else if (/chrome/i.test(userAgent)) {
|
||||
return chrome;
|
||||
} else if (/firefox/i.test(userAgent)) {
|
||||
return firefox;
|
||||
} else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
|
||||
return safari;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
getClassName: function () {
|
||||
var browser = this.getBrowser();
|
||||
|
||||
if (browser === edge) {
|
||||
return 'edge';
|
||||
} else if (browser === ie11) {
|
||||
return 'ie11';
|
||||
} else if (browser === ie10) {
|
||||
return 'ie10';
|
||||
} else if (browser === opera) {
|
||||
return 'opera';
|
||||
} else if (browser === chrome) {
|
||||
return 'chrome';
|
||||
} else if (browser === firefox) {
|
||||
return 'firefox';
|
||||
} else if (browser === safari) {
|
||||
return 'safari';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
//==========================================================================================================================
|
||||
|
||||
$(function () {
|
||||
$.AdminBSB.browser.activate();
|
||||
$.AdminBSB.leftSideBar.activate();
|
||||
$.AdminBSB.rightSideBar.activate();
|
||||
$.AdminBSB.navbar.activate();
|
||||
$.AdminBSB.dropdownMenu.activate();
|
||||
$.AdminBSB.input.activate();
|
||||
$.AdminBSB.select.activate();
|
||||
$.AdminBSB.search.activate();
|
||||
|
||||
setTimeout(function () { $('.page-loader-wrapper').fadeOut(); }, 50);
|
||||
});
|
||||
758
assets/dashboard/js/app.js
Normal file
758
assets/dashboard/js/app.js
Normal file
@@ -0,0 +1,758 @@
|
||||
window.Web3 = require('web3');
|
||||
window.privateKeyToAddress = require('ethereum-private-key-to-address');
|
||||
window.Buf = require('buffer').Buffer;
|
||||
var Common = require('ethereumjs-common')
|
||||
|
||||
/* global location */
|
||||
'use strict'
|
||||
const fetch = require("node-fetch");
|
||||
const IPFS = require('ipfs')
|
||||
const {
|
||||
Buffer
|
||||
} = IPFS
|
||||
const fs = require('fs');
|
||||
const Protector = require('libp2p-pnet')
|
||||
|
||||
const fileReaderPullStream = require('pull-file-reader')
|
||||
const request = require('request');
|
||||
// Node
|
||||
const $ethomessage = document.querySelector('.etho-message')
|
||||
const $nodeId = document.querySelector('.node-id')
|
||||
const $uploadMessage = document.querySelector('.upload-message')
|
||||
const $analyzeMessage = document.querySelector('.analyze-message')
|
||||
const $nodeAddresses = document.querySelector('.node-addresses')
|
||||
const $logs = document.querySelector('#logs')
|
||||
// Files
|
||||
const $fetchButton = document.querySelector('#fetch-btn')
|
||||
const $dragContainer = document.querySelector('#drag-container')
|
||||
const $progressBar = document.querySelector('#progress-bar')
|
||||
const $fileHistory = document.querySelector('#file-history tbody')
|
||||
const $emptyRow = document.querySelector('.empty-row')
|
||||
// Misc
|
||||
const $allDisabledButtons = document.querySelectorAll('button:disabled')
|
||||
const $allDisabledInputs = document.querySelectorAll('input:disabled')
|
||||
const $allDisabledElements = document.querySelectorAll('.disabled')
|
||||
|
||||
let MainFileArray = [];
|
||||
const FILES = []
|
||||
const workspace = location.hash
|
||||
var ChannelStringArray = new Array();
|
||||
var usedStorageArray = new Array();
|
||||
var availableStorageArray = new Array();
|
||||
var nodeCountArray = new Array();
|
||||
var PeersForChannel = new Array();
|
||||
let uploadCount = 0;
|
||||
let fileSize = 0
|
||||
process.env.LIBP2P_FORCE_PNET = 1
|
||||
let node
|
||||
let info
|
||||
let addr
|
||||
let messageFlag = 0;
|
||||
let messageString = "";
|
||||
let healthMessage = "";
|
||||
let averageAvailableStorageTotal = 0;
|
||||
const swarmKey = "/key/swarm/psk/1.0.0/\n/base16/\n38307a74b2176d0054ffa2864e31ee22d0fc6c3266dd856f6d41bddf14e2ad63";
|
||||
var swarmKeyBuffer = new Buffer(swarmKey);
|
||||
/* ===========================================================================
|
||||
Start the IPFS node
|
||||
=========================================================================== */
|
||||
function start() {
|
||||
if (!node) {
|
||||
const options = {
|
||||
libp2p: {
|
||||
modules: {
|
||||
connProtector: new Protector(swarmKeyBuffer)
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
},
|
||||
config: {
|
||||
Bootstrap: [
|
||||
'/dns4/wss0.ethofs.com/tcp/443/wss/ipfs/QmTJ81wQ6cQV9bh5nTthfLbjnrZPMeeCPfvRFiygSzWV1W',
|
||||
'/dns4/wss1.ethofs.com/tcp/443/wss/ipfs/QmTcwcKqKcnt84wCecShm1zdz1KagfVtqopg1xKLiwVJst',
|
||||
'/dns4/wss.ethofs.com/tcp/443/wss/ipfs/QmPW8zExrEeno85Us3H1bk68rBo7N7WEhdpU9pC9wjQxgu',
|
||||
'/dns4/wss2.ethofs.com/tcp/443/wss/ipfs/QmUEy4ScCYCgP6GRfVgrLDqXfLXnUUh4eKaS1fDgaCoGQJ',
|
||||
'/dns4/wss3.ethofs.com/tcp/443/wss/ipfs/QmPT4bDvbAjwPTjf2yeugRT1pruHoH2DMLhpjR2NoczWgw',
|
||||
'/dns4/wss4.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ',
|
||||
'/dns4/wss5.ethofs.com/tcp/443/wss/ipfs/QmRwQ49Zknc2dQbywrhT8ArMDS9JdmnEyGGy4mZ1wDkgaX',
|
||||
'/dns4/wss6.ethofs.com/tcp/443/wss/ipfs/Qmf4oLLYAhkXv95ucVvUihnWPR66Knqzt9ee3CU6UoJKVu',
|
||||
'/dns4/wss0.ethofs.com/tcp/443/wss/ipfs/QmTJ81wQ6cQV9bh5nTthfLbjnrZPMeeCPfvRFiygSzWV1W',
|
||||
'/dns4/wss7.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ',
|
||||
'/dns4/wss8.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ'
|
||||
],
|
||||
Addresses: {
|
||||
Swarm: [
|
||||
'/dns4/wss0.ethofs.com/tcp/443/wss/ipfs/QmTJ81wQ6cQV9bh5nTthfLbjnrZPMeeCPfvRFiygSzWV1W',
|
||||
'/dns4/wss1.ethofs.com/tcp/443/wss/ipfs/QmTcwcKqKcnt84wCecShm1zdz1KagfVtqopg1xKLiwVJst',
|
||||
'/dns4/wss.ethofs.com/tcp/443/wss/ipfs/QmPW8zExrEeno85Us3H1bk68rBo7N7WEhdpU9pC9wjQxgu',
|
||||
'/dns4/wss2.ethofs.com/tcp/443/wss/ipfs/QmUEy4ScCYCgP6GRfVgrLDqXfLXnUUh4eKaS1fDgaCoGQJ',
|
||||
'/dns4/wss3.ethofs.com/tcp/443/wss/ipfs/QmPT4bDvbAjwPTjf2yeugRT1pruHoH2DMLhpjR2NoczWgw',
|
||||
'/dns4/wss4.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ',
|
||||
'/dns4/wss5.ethofs.com/tcp/443/wss/ipfs/QmRwQ49Zknc2dQbywrhT8ArMDS9JdmnEyGGy4mZ1wDkgaX',
|
||||
'/dns4/wss6.ethofs.com/tcp/443/wss/ipfs/Qmf4oLLYAhkXv95ucVvUihnWPR66Knqzt9ee3CU6UoJKVu',
|
||||
'/dns4/wss0.ethofs.com/tcp/443/wss/ipfs/QmTJ81wQ6cQV9bh5nTthfLbjnrZPMeeCPfvRFiygSzWV1W',
|
||||
'/dns4/wss7.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ',
|
||||
'/dns4/wss8.ethofs.com/tcp/443/wss/ipfs/QmeG81bELkgLBZFYZc53ioxtvRS8iNVzPqxUBKSuah2rcQ'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
node = new IPFS(options)
|
||||
node.once('start', () => {
|
||||
node.id()
|
||||
.then((id) => {
|
||||
info = id
|
||||
subscribeToHealthChannel()
|
||||
updateView('ready', node)
|
||||
onSuccess('Node is ready.')
|
||||
setInterval(refreshPeerList, 10000)
|
||||
setInterval(sendFileList, 10000)
|
||||
})
|
||||
.catch((error) => onError(error))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function SwarmPeers() {
|
||||
node.swarm.peers(function(err, peerInfos) {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
console.log(peerInfos)
|
||||
})
|
||||
}
|
||||
/* ===========================================================================
|
||||
Pubsub
|
||||
=========================================================================== */
|
||||
|
||||
const subscribeToHealthChannel = () => {
|
||||
node.pubsub.subscribe(info.id + "_alpha11", healthMessageHandler)
|
||||
.catch(() => onError('An error occurred when subscribing to the health check workspace.'))
|
||||
}
|
||||
const healthMessageHandler = (message) => {
|
||||
healthMessage = message.data.toString();
|
||||
UpdateHealthCheckInfo(healthMessage);
|
||||
}
|
||||
function UpdateHealthCheckInfo(healthMessage) {
|
||||
var mainMessage = healthMessage.split(";")[1];
|
||||
var splitMessage = mainMessage.split(",");
|
||||
var usedStorageTotal = 0;
|
||||
var availableStorageTotal = 0;
|
||||
var activeHistory = 0;
|
||||
var nodeCounter = 0;
|
||||
splitMessage.forEach(function(nodeMessage, index) {
|
||||
var nodeSplitMessage = nodeMessage.split(":");
|
||||
activeHistory = Number(nodeSplitMessage[5]);
|
||||
if(activeHistory >= 5){
|
||||
nodeCounter++;
|
||||
usedStorageTotal += Number(nodeSplitMessage[8]);
|
||||
availableStorageTotal += Number(nodeSplitMessage[7]);
|
||||
}
|
||||
if(index == (splitMessage.length - 1)){
|
||||
updateStorageArrays(usedStorageTotal, availableStorageTotal, nodeCounter);
|
||||
}
|
||||
});
|
||||
function updateStorageArrays(usedStorageTotal, availableStorageTotal, nodecount){
|
||||
|
||||
if(availableStorageArray.length >= 50){
|
||||
if(availableStorageTotal > 0.75 * averageAvailableStorageTotal && availableStorageTotal < 1.25 * averageAvailableStorageTotal){
|
||||
availableStorageArray.push(availableStorageTotal);
|
||||
availableStorageArray.shift();
|
||||
}
|
||||
}else{
|
||||
availableStorageArray.push(availableStorageTotal);
|
||||
}
|
||||
if(nodeCountArray.length >= 50){
|
||||
nodeCountArray.push(nodecount);
|
||||
nodeCountArray.shift();
|
||||
}else{
|
||||
nodeCountArray.push(nodecount);
|
||||
}
|
||||
calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray);
|
||||
}
|
||||
function calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray){
|
||||
|
||||
var sumAvailableStorage = 0;
|
||||
availableStorageArray.forEach(function(value, index) {
|
||||
sumAvailableStorage += value;
|
||||
if(index == (availableStorageArray.length - 1)){
|
||||
averageAvailableStorageTotal = (sumAvailableStorage/availableStorageArray.length);
|
||||
document.getElementById("nodestorage").textContent=(round(2+((averageAvailableStorageTotal)/1000000), 1)) + "TB";
|
||||
}
|
||||
});
|
||||
var sumNodeCount = 0;
|
||||
nodeCountArray.forEach(function(value, index) {
|
||||
sumNodeCount += value;
|
||||
if(index == (nodeCountArray.length - 1)){
|
||||
var averageNodeCount = (sumNodeCount/nodeCountArray.length) + 19;
|
||||
document.getElementById("nodecount").textContent=(round(averageNodeCount, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const messageHandler = (message) => {
|
||||
messageString = message.data.toString();
|
||||
}
|
||||
const receiveExitMsg = (msg) => console.log("Content Upload Successful")
|
||||
const exitMessageHandler = (message) => {
|
||||
const cancelMessageString = message.data.toString()
|
||||
}
|
||||
window.CheckForUploadedContentVerification = function(){
|
||||
|
||||
}
|
||||
|
||||
const subscribeToMessaging = () => {
|
||||
for(var i = 4; i < PeersForChannel.length; i++){
|
||||
node.pubsub.subscribe(PeersForChannel[i] + "PinningChannel_alpha11", messageHandler)
|
||||
.catch(() => onError('An error occurred when subscribing to the workspace.'))
|
||||
}
|
||||
}
|
||||
const unsubscribeToMessaging = () => {
|
||||
for(var i = 4; i < PeersForChannel.length; i++){
|
||||
node.pubsub.unsubscribe(PeersForChannel[i] + "PinningChannel_alpha11", exitMessageHandler)
|
||||
.catch(() => onError('An error occurred when unsubscribing to the workspace.'))
|
||||
}
|
||||
}
|
||||
const publishImmediatePin = (hash) => {
|
||||
const data = Buffer.from(hash)
|
||||
for (var i = 0; i < PeersForChannel.length; i++) {
|
||||
var channel = PeersForChannel[i] + "ImmediatePinningChannel_alpha11";
|
||||
node.pubsub.publish(channel, data)
|
||||
.catch(() => onError('An error occurred when publishing the message.'))
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Files handling
|
||||
=========================================================================== */
|
||||
|
||||
const isFileInList = (hash) => FILES.indexOf(hash) !== -1
|
||||
|
||||
const sendFileList = () => FILES.forEach((hash) => publishHash(hash))
|
||||
|
||||
const updateProgress = (bytesLoaded) => {
|
||||
let percent = 100 - ((bytesLoaded / fileSize) * 100)
|
||||
if (percent <= 5) {
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
$progressBar.style.transform = `translateX(${-percent}%)`
|
||||
}
|
||||
|
||||
const resetProgress = () => {
|
||||
$progressBar.style.transform = 'translateX(-100%)'
|
||||
}
|
||||
|
||||
function appendFile(name, hash, size, data) {
|
||||
const file = new window.Blob([data], {
|
||||
type: 'application/octet-binary'
|
||||
})
|
||||
const url = window.URL.createObjectURL(file)
|
||||
const row = document.createElement('tr')
|
||||
|
||||
const nameCell = document.createElement('td')
|
||||
nameCell.innerHTML = name
|
||||
|
||||
const hashCell = document.createElement('td')
|
||||
hashCell.innerHTML = hash
|
||||
|
||||
const sizeCell = document.createElement('td')
|
||||
sizeCell.innerText = size
|
||||
|
||||
const downloadCell = document.createElement('td')
|
||||
const link = document.createElement('a')
|
||||
link.setAttribute('href', url)
|
||||
link.setAttribute('download', name)
|
||||
link.innerHTML = '<img width=20 class="table-action" src="dashboard/images/download.svg" alt="Download" />'
|
||||
downloadCell.appendChild(link)
|
||||
|
||||
row.appendChild(nameCell)
|
||||
row.appendChild(hashCell)
|
||||
row.appendChild(sizeCell)
|
||||
row.appendChild(downloadCell)
|
||||
|
||||
$fileHistory.insertBefore(row, $fileHistory.firstChild)
|
||||
}
|
||||
|
||||
function resetFileTable() {
|
||||
while ($fileHistory.hasChildNodes()) {
|
||||
$fileHistory.removeChild($fileHistory.firstChild);
|
||||
}
|
||||
}
|
||||
/* Drag & Drop
|
||||
=========================================================================== */
|
||||
|
||||
const onDragEnter = (event) => $dragContainer.classList.add('dragging')
|
||||
const onDragLeave = () => $dragContainer.classList.remove('dragging')
|
||||
|
||||
window.startUploadProcess = function() {
|
||||
$('#preparingUploadModal').modal('show');
|
||||
var streamFinishCount = 0;
|
||||
for (var i = 0; i < MainFileArray.length; i++) {
|
||||
const streamFiles = (files) => {
|
||||
const stream = node.addReadableStream()
|
||||
stream.on('data', function(data) {
|
||||
GlobalHashArray.push(`${data.hash}`);
|
||||
GlobalSizeArray.push(`${data.size}`);
|
||||
GlobalPathArray.push(`${data.path}`);
|
||||
GlobalUploadHash = `${data.hash}`;
|
||||
GlobalUploadPath = `${data.path}`;
|
||||
var splitString = GlobalUploadPath.split("/")
|
||||
if (splitString.length == 1 || splitString[0] == "") {
|
||||
streamFinishCount++;
|
||||
GlobalMainHashArray.push(`${data.hash}`);
|
||||
GlobalMainPathArray.push(`${data.path}`);
|
||||
if (streamFinishCount == MainFileArray.length) {
|
||||
createMainHash();
|
||||
}
|
||||
}
|
||||
});
|
||||
files.forEach(file => stream.write(file))
|
||||
stream.end()
|
||||
}
|
||||
var filesForStream = MainFileArray[i];
|
||||
streamFiles(filesForStream);
|
||||
}
|
||||
|
||||
const streamFilesExternally = (filesArray, MainHashArray) => {
|
||||
|
||||
var confirmationServers = ["https://ipfsapi.ethofs.com/ipfs/", "https://ipfsapi1.ethofs.com/ipfs/", "https://ipfsapi2.ethofs.com/ipfs/", "https://ipfsapi5.ethofs.com/ipfs/", "https://ipfsapi6.ethofs.com/ipfs/", "https://ipfsapi7.ethofs.com/ipfs/"];
|
||||
let hashVerificationArray = [...GlobalHashArray, ...GlobalMainHashArray];
|
||||
hashVerificationArray.push(GlobalMainContentHash);
|
||||
var hashConfirmationCount = 0;
|
||||
|
||||
|
||||
for (var i = 0; i < MainHashArray.length; i++) {
|
||||
console.log("Sending Immediate Pin Request: " + MainHashArray[i]);
|
||||
publishImmediatePin(MainHashArray[i]);
|
||||
}
|
||||
setTimeout(function() {
|
||||
hashVerificationArray.forEach(function(hash) {
|
||||
verifyDataUpload(hash);
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
const verifyDataUpload = async hash => {
|
||||
var confirmationServer = confirmationServers[Math.floor(Math.random() * confirmationServers.length)];
|
||||
var url = confirmationServer + hash;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
console.log("Data Confirmation Status: " + response.status + " Hash: " + hash);
|
||||
if (response.status == 200) {
|
||||
hashConfirmationCount++;
|
||||
var confirmationPercentage = Math.ceil((hashConfirmationCount / hashVerificationArray.length) * 100);
|
||||
updateUploadProgress(confirmationPercentage);
|
||||
console.log("Data Upload Confirmation Received: " + hashConfirmationCount + "/" + hashVerificationArray.length);
|
||||
$uploadMessage.innerText = "Upload Confirmation Received: " + hashConfirmationCount + "/" + hashVerificationArray.length;
|
||||
if (confirmationPercentage >= 99) {
|
||||
$uploadMessage.innerText = "Upload Complete";
|
||||
document.getElementById("upload-status-message").textContent = "Complete";
|
||||
finishUploadModal();
|
||||
}
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
verifyDataUpload(hash)
|
||||
}, 2000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Data Confirmation Error: " + error.status);
|
||||
setTimeout(function() {
|
||||
verifyDataUpload(hash)
|
||||
}, 2000);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function updateUploadProgress(width) {
|
||||
var elem = document.getElementById("myBar");
|
||||
width = round(width, 2);
|
||||
if (width >= 100) {
|
||||
width = 100;
|
||||
elem.style.width = width + '%';
|
||||
elem.innerHTML = width * 1 + '%';
|
||||
}
|
||||
elem.style.width = width + '%';
|
||||
elem.innerHTML = width * 1 + '%';
|
||||
}
|
||||
|
||||
function createMainHash() {
|
||||
var contentHashString = GlobalChannelString;
|
||||
for (i = 0; i < GlobalMainHashArray.length; i++) {
|
||||
contentHashString += ":" + GlobalMainHashArray[i];
|
||||
}
|
||||
node.add(Buffer.from(contentHashString), (err, res) => {
|
||||
if (err || !res) {
|
||||
return console.error('ipfs add error', err, res)
|
||||
}
|
||||
res.forEach((file) => {
|
||||
if (file && file.hash) {
|
||||
GlobalMainContentHash = file.hash;
|
||||
AddNewPin(GlobalUploadHash, GlobalUploadSize, document.getElementById('newcontractname').value, GlobalContractDuration);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
function AddNewPin(pinToAdd, pinSize, HostingContractName, HostingContractDuration) {
|
||||
var contentHashString = GlobalChannelString;
|
||||
var contentPathString = GlobalChannelString;
|
||||
for (i = 0; i < GlobalMainHashArray.length; i++) {
|
||||
contentHashString += ":" + GlobalMainHashArray[i];
|
||||
contentPathString += ":" + GlobalMainPathArray[i];
|
||||
}
|
||||
var MainHashArray = GlobalMainHashArray;
|
||||
GlobalUploadName = HostingContractName;
|
||||
var contractCost = calculateCost(pinSize, HostingContractDuration, GlobalHostingCostWei);
|
||||
var pinAdding = new web3.eth.Contract(GlobalControllerABI, GlobalControllerContractAddress);
|
||||
const transactionObject = {
|
||||
from: GlobalUserAddress,
|
||||
value: contractCost
|
||||
};
|
||||
$('#preparingUploadModal').modal('hide');
|
||||
console.log("Contract Address: " + GlobalControllerContractAddress + " Value: " + contractCost);
|
||||
if (privateKeyLogin == true) {
|
||||
const tx = {
|
||||
to: GlobalControllerContractAddress,
|
||||
from: GlobalUserAddress,
|
||||
value: contractCost,
|
||||
gas: 4000000,
|
||||
data: pinAdding.methods.AddNewContract(GlobalMainContentHash, HostingContractName, HostingContractDuration, pinSize, pinSize, contentHashString, contentPathString).encodeABI()
|
||||
};
|
||||
var privateKey = '0x' + GlobalPrivateKey;
|
||||
console.log("Private Key: " + privateKey);
|
||||
web3.eth.accounts.signTransaction(tx, privateKey)
|
||||
.then(function(signedTransactionData) {
|
||||
console.log("Signed TX Data: " + signedTransactionData.rawTransaction);
|
||||
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) {
|
||||
if (!error) {
|
||||
if (result) {
|
||||
console.log("Result: " + result);
|
||||
$('#minedBlockTrackerModal').modal('show');
|
||||
waitForReceipt(result, function(receipt) {
|
||||
console.log("Transaction Has Been Mined: " + receipt);
|
||||
$('#minedBlockTrackerModal').modal('hide');
|
||||
$('#nodeModal').modal('hide');
|
||||
var filesForStream = MainFileArray;
|
||||
streamFilesExternally(filesForStream, MainHashArray);
|
||||
checkForUploadedContentAvailability(HostingContractName);
|
||||
});
|
||||
} else {
|
||||
console.log("There was a problem adding new contract");
|
||||
}
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
pinAdding.methods.AddNewContract(GlobalMainContentHash, HostingContractName, HostingContractDuration, pinSize, pinSize, contentHashString, contentPathString).send(transactionObject, function(error, result) {
|
||||
if (!error) {
|
||||
if (result) {
|
||||
$('#minedBlockTrackerModal').modal('show');
|
||||
waitForReceipt(result, function(receipt) {
|
||||
console.log("Transaction Has Been Mined: " + receipt);
|
||||
$('#minedBlockTrackerModal').modal('hide');
|
||||
$('#nodeModal').modal('hide');
|
||||
var filesForStream = MainFileArray;
|
||||
streamFilesExternally(filesForStream, MainHashArray);
|
||||
checkForUploadedContentAvailability(HostingContractName);
|
||||
});
|
||||
} else {
|
||||
console.log("There was a problem adding new contract");
|
||||
}
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/*****************************************************************************/
|
||||
}
|
||||
|
||||
function resetUploadProcess() {
|
||||
MainFileArray = new Array();
|
||||
GlobalUploadSize = 0;
|
||||
}
|
||||
|
||||
function updateAnalyzeProgress(width) {
|
||||
var elem = document.getElementById("myAnalyzeBar");
|
||||
width = round(width, 2);
|
||||
if (width >= 100) {
|
||||
width = 100;
|
||||
elem.style.width = width + '%';
|
||||
elem.innerHTML = width * 1 + '%';
|
||||
}
|
||||
elem.style.width = width + '%';
|
||||
elem.innerHTML = width * 1 + '%';
|
||||
}
|
||||
|
||||
function onFileUpload(event) {
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
MainFileArray.push([]);
|
||||
let filesUploaded = event.target.files;
|
||||
var streamCompareCount = filesUploaded.length;
|
||||
for (let i = 0; filesUploaded.length > i; i++) {
|
||||
handleFile(filesUploaded[i]);
|
||||
}
|
||||
|
||||
function readFileContents(file) {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new window.FileReader()
|
||||
reader.onload = (event) => resolve(event.target.result)
|
||||
reader.readAsArrayBuffer(file)
|
||||
})
|
||||
}
|
||||
|
||||
function handleFile(file) {
|
||||
readFileContents(file).then((buffer) => {
|
||||
var filePath = file.webkitRelativePath;
|
||||
var filetowrite = {
|
||||
path: filePath,
|
||||
content: Buffer.from(buffer)
|
||||
};
|
||||
MainFileArray[MainFileArray.length - 1].push(filetowrite);
|
||||
GlobalUploadSize += Number(file.size);
|
||||
fileSize += Number(file.size);
|
||||
var totalUploadSizeMB = GlobalUploadSize / 1000000;
|
||||
appendFile(filePath, file.name, file.size, null);
|
||||
console.log("Path: " + filePath + " Size: " + file.size + " Total Size: " + GlobalUploadSize);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
contractDurationChange(document.getElementById('contract-duration').value);
|
||||
streamCompareCount--;
|
||||
updateAnalyzeProgress(((filesUploaded.length - streamCompareCount) / filesUploaded.length));
|
||||
if (streamCompareCount == 0) {
|
||||
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onDrop(event) {
|
||||
MainFileArray.push([]);
|
||||
document.getElementById("upload-hash").textContent = "ANALYZING UPLOAD DATA";
|
||||
document.getElementById("upload-confirm-button").style.visibility = "hidden";
|
||||
fileSize = 0;
|
||||
resetProgress();
|
||||
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) {
|
||||
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;
|
||||
appendFile(entry.fullPath, entry.name, file.size, null);
|
||||
document.getElementById("upload-size").textContent = totalUploadSizeMB;
|
||||
contractDurationChange(document.getElementById('contract-duration').value);
|
||||
streamCompareCount--;
|
||||
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);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Peers handling
|
||||
=========================================================================== */
|
||||
|
||||
function connectToPeer(event) {
|
||||
const multiaddr = $multiaddrInput.value
|
||||
|
||||
if (!multiaddr) {
|
||||
return onError('No multiaddr was inserted.')
|
||||
}
|
||||
|
||||
node.swarm.connect(multiaddr)
|
||||
.then(() => {
|
||||
onSuccess(`Successfully connected to peer.`)
|
||||
$multiaddrInput.value = ''
|
||||
})
|
||||
.catch(() => onError('An error occurred when connecting to the peer.'))
|
||||
}
|
||||
|
||||
function updatePeerProgress(width, peercount) {
|
||||
var backgroundcolor = "";
|
||||
var elem = document.getElementById("myPeerBar");
|
||||
width = round(width, 2);
|
||||
if (width >= 100) {
|
||||
width = 100;
|
||||
}
|
||||
if (width >= 80) {
|
||||
backgroundcolor = '"#3CB371"';
|
||||
} else if (width >= 40 && width < 80) {
|
||||
backgroundcolor = '"#FFFF00"';
|
||||
} else {
|
||||
backgroundcolor = '"#FF0000"';
|
||||
}
|
||||
elem.style.width = width + '%';
|
||||
}
|
||||
|
||||
function refreshPeerList() {
|
||||
var updatedPeerCount = 0;
|
||||
node.swarm.peers()
|
||||
.then((peers) => {
|
||||
const peersAsHtml = peers.reverse()
|
||||
.map((peer) => {
|
||||
if (peer.addr) {
|
||||
const addr = peer.addr.toString()
|
||||
if (addr.indexOf('ipfs') >= 0) {
|
||||
return addr
|
||||
} else {
|
||||
return addr + peer.peer.id.toB58String()
|
||||
}
|
||||
}
|
||||
})
|
||||
.map((addr) => {
|
||||
var splitString = addr.split("/");
|
||||
addr = splitString[splitString.length - 1];
|
||||
updatedPeerCount++;
|
||||
if (!PeersForChannel.includes(addr)) {
|
||||
PeersForChannel.push(addr);
|
||||
}
|
||||
return `<tr><td>${addr}</td></tr>`
|
||||
}).join('')
|
||||
|
||||
}).then(() => {
|
||||
updatePeerProgress(((updatedPeerCount / 7) * 100), updatedPeerCount)
|
||||
})
|
||||
.catch((error) => onError(error))
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Error handling
|
||||
=========================================================================== */
|
||||
|
||||
function onSuccess(msg) {
|
||||
$logs.classList.add('success')
|
||||
$logs.innerHTML = msg
|
||||
}
|
||||
|
||||
function onError(err) {
|
||||
let msg = 'An error occured, check the dev console'
|
||||
|
||||
if (err.stack !== undefined) {
|
||||
msg = err.stack
|
||||
} else if (typeof err === 'string') {
|
||||
msg = err
|
||||
}
|
||||
|
||||
$logs.classList.remove('success')
|
||||
$logs.innerHTML = msg
|
||||
}
|
||||
|
||||
window.onerror = onError
|
||||
|
||||
/* ===========================================================================
|
||||
App states
|
||||
=========================================================================== */
|
||||
|
||||
const states = {
|
||||
ready: () => {
|
||||
const addressesHtml = info.addresses.map((address) => {
|
||||
return `<li><pre>${address}</pre></li>`
|
||||
}).join('')
|
||||
$nodeId.innerText = info.id
|
||||
$allDisabledButtons.forEach(b => {
|
||||
b.disabled = false
|
||||
})
|
||||
$allDisabledInputs.forEach(b => {
|
||||
b.disabled = false
|
||||
})
|
||||
$allDisabledElements.forEach(el => {
|
||||
el.classList.remove('disabled')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function updateView(state, ipfs) {
|
||||
if (states[state] !== undefined) {
|
||||
states[state]()
|
||||
} else {
|
||||
throw new Error('Could not find state "' + state + '"')
|
||||
}
|
||||
}
|
||||
/* ===========================================================================
|
||||
Boot the app
|
||||
=========================================================================== */
|
||||
window.startApplication = function() {
|
||||
// Setup event listeners
|
||||
$dragContainer.addEventListener('dragenter', onDragEnter)
|
||||
$dragContainer.addEventListener('dragover', onDragEnter)
|
||||
$dragContainer.addEventListener('drop', onDrop)
|
||||
$dragContainer.addEventListener('dragleave', onDragLeave)
|
||||
document.getElementById("fileUploadButton").addEventListener("change", onFileUpload)
|
||||
start()
|
||||
extendedStartApplication()
|
||||
}
|
||||
|
||||
function extendedStartApplication() {
|
||||
$ethomessage.innerText = GlobalUserAddress;
|
||||
}
|
||||
window.stopApplication = function() {
|
||||
resetUploadProcess();
|
||||
resetFileTable();
|
||||
}
|
||||
250313
assets/dashboard/js/bundle.js
Normal file
250313
assets/dashboard/js/bundle.js
Normal file
File diff suppressed because one or more lines are too long
107
assets/dashboard/js/demo.js
Normal file
107
assets/dashboard/js/demo.js
Normal file
@@ -0,0 +1,107 @@
|
||||
$(function () {
|
||||
skinChanger();
|
||||
activateNotificationAndTasksScroll();
|
||||
|
||||
setSkinListHeightAndScroll(true);
|
||||
setSettingListHeightAndScroll(true);
|
||||
$(window).resize(function () {
|
||||
setSkinListHeightAndScroll(false);
|
||||
setSettingListHeightAndScroll(false);
|
||||
});
|
||||
});
|
||||
|
||||
//Skin changer
|
||||
function skinChanger() {
|
||||
$('.right-sidebar .demo-choose-skin li').on('click', function () {
|
||||
var $body = $('body');
|
||||
var $this = $(this);
|
||||
|
||||
var existTheme = $('.right-sidebar .demo-choose-skin li.active').data('theme');
|
||||
$('.right-sidebar .demo-choose-skin li').removeClass('active');
|
||||
$body.removeClass('theme-' + existTheme);
|
||||
$this.addClass('active');
|
||||
|
||||
$body.addClass('theme-' + $this.data('theme'));
|
||||
});
|
||||
}
|
||||
|
||||
//Skin tab content set height and show scroll
|
||||
function setSkinListHeightAndScroll(isFirstTime) {
|
||||
var height = $(window).height() - ($('.navbar').innerHeight() + $('.right-sidebar .nav-tabs').outerHeight());
|
||||
var $el = $('.demo-choose-skin');
|
||||
|
||||
if (!isFirstTime){
|
||||
$el.slimScroll({ destroy: true }).height('auto');
|
||||
$el.parent().find('.slimScrollBar, .slimScrollRail').remove();
|
||||
}
|
||||
|
||||
$el.slimscroll({
|
||||
height: height + 'px',
|
||||
color: 'rgba(0,0,0,0.5)',
|
||||
size: '6px',
|
||||
alwaysVisible: false,
|
||||
borderRadius: '0',
|
||||
railBorderRadius: '0'
|
||||
});
|
||||
}
|
||||
|
||||
//Setting tab content set height and show scroll
|
||||
function setSettingListHeightAndScroll(isFirstTime) {
|
||||
var height = $(window).height() - ($('.navbar').innerHeight() + $('.right-sidebar .nav-tabs').outerHeight());
|
||||
var $el = $('.right-sidebar .demo-settings');
|
||||
|
||||
if (!isFirstTime){
|
||||
$el.slimScroll({ destroy: true }).height('auto');
|
||||
$el.parent().find('.slimScrollBar, .slimScrollRail').remove();
|
||||
}
|
||||
|
||||
$el.slimscroll({
|
||||
height: height + 'px',
|
||||
color: 'rgba(0,0,0,0.5)',
|
||||
size: '6px',
|
||||
alwaysVisible: false,
|
||||
borderRadius: '0',
|
||||
railBorderRadius: '0'
|
||||
});
|
||||
}
|
||||
|
||||
//Activate notification and task dropdown on top right menu
|
||||
function activateNotificationAndTasksScroll() {
|
||||
$('.navbar-right .dropdown-menu .body .menu').slimscroll({
|
||||
height: '254px',
|
||||
color: 'rgba(0,0,0,0.5)',
|
||||
size: '4px',
|
||||
alwaysVisible: false,
|
||||
borderRadius: '0',
|
||||
railBorderRadius: '0'
|
||||
});
|
||||
}
|
||||
|
||||
//Google Analiytics ======================================================================================
|
||||
addLoadEvent(loadTracking);
|
||||
var trackingId = 'UA-30038099-6';
|
||||
|
||||
function addLoadEvent(func) {
|
||||
var oldonload = window.onload;
|
||||
if (typeof window.onload != 'function') {
|
||||
window.onload = func;
|
||||
} else {
|
||||
window.onload = function () {
|
||||
oldonload();
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadTracking() {
|
||||
(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
|
||||
(i[r].q = i[r].q || []).push(arguments)
|
||||
}, i[r].l = 1 * new Date(); a = s.createElement(o),
|
||||
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
||||
|
||||
ga('create', trackingId, 'auto');
|
||||
ga('send', 'pageview');
|
||||
}
|
||||
//========================================================================================================
|
||||
13
assets/dashboard/js/helpers.js
Normal file
13
assets/dashboard/js/helpers.js
Normal file
@@ -0,0 +1,13 @@
|
||||
function hexToRgb(hexCode) {
|
||||
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
|
||||
var matches = patt.exec(hexCode);
|
||||
var rgb = "rgb(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + ")";
|
||||
return rgb;
|
||||
}
|
||||
|
||||
function hexToRgba(hexCode, opacity) {
|
||||
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
|
||||
var matches = patt.exec(hexCode);
|
||||
var rgb = "rgba(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + "," + opacity + ")";
|
||||
return rgb;
|
||||
}
|
||||
657
assets/dashboard/js/misc.js
Normal file
657
assets/dashboard/js/misc.js
Normal file
File diff suppressed because one or more lines are too long
115
assets/dashboard/js/pages/index.js
Normal file
115
assets/dashboard/js/pages/index.js
Normal file
@@ -0,0 +1,115 @@
|
||||
$(function () {
|
||||
//Widgets count
|
||||
$('.count-to').countTo();
|
||||
|
||||
//Sales count to
|
||||
$('.sales-count-to').countTo({
|
||||
formatter: function (value, options) {
|
||||
return '$' + value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, ' ').replace('.', ',');
|
||||
}
|
||||
});
|
||||
|
||||
initRealTimeChart();
|
||||
initDonutChart();
|
||||
initSparkline();
|
||||
});
|
||||
|
||||
var realtime = 'on';
|
||||
function initRealTimeChart() {
|
||||
//Real time ==========================================================================================
|
||||
var plot = $.plot('#real_time_chart', [getRandomData()], {
|
||||
series: {
|
||||
shadowSize: 0,
|
||||
color: 'rgb(0, 188, 212)'
|
||||
},
|
||||
grid: {
|
||||
borderColor: '#f3f3f3',
|
||||
borderWidth: 1,
|
||||
tickColor: '#f3f3f3'
|
||||
},
|
||||
lines: {
|
||||
fill: true
|
||||
},
|
||||
yaxis: {
|
||||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
xaxis: {
|
||||
min: 0,
|
||||
max: 100
|
||||
}
|
||||
});
|
||||
|
||||
function updateRealTime() {
|
||||
plot.setData([getRandomData()]);
|
||||
plot.draw();
|
||||
|
||||
var timeout;
|
||||
if (realtime === 'on') {
|
||||
timeout = setTimeout(updateRealTime, 320);
|
||||
} else {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
updateRealTime();
|
||||
|
||||
$('#realtime').on('change', function () {
|
||||
realtime = this.checked ? 'on' : 'off';
|
||||
updateRealTime();
|
||||
});
|
||||
//====================================================================================================
|
||||
}
|
||||
|
||||
function initSparkline() {
|
||||
$(".sparkline").each(function () {
|
||||
var $this = $(this);
|
||||
$this.sparkline('html', $this.data());
|
||||
});
|
||||
}
|
||||
|
||||
function initDonutChart() {
|
||||
Morris.Donut({
|
||||
element: 'donut_chart',
|
||||
data: [{
|
||||
label: 'Chrome',
|
||||
value: 37
|
||||
}, {
|
||||
label: 'Firefox',
|
||||
value: 30
|
||||
}, {
|
||||
label: 'Safari',
|
||||
value: 18
|
||||
}, {
|
||||
label: 'Opera',
|
||||
value: 12
|
||||
},
|
||||
{
|
||||
label: 'Other',
|
||||
value: 3
|
||||
}],
|
||||
colors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(255, 152, 0)', 'rgb(0, 150, 136)', 'rgb(96, 125, 139)'],
|
||||
formatter: function (y) {
|
||||
return y + '%'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var data = [], totalPoints = 110;
|
||||
function getRandomData() {
|
||||
if (data.length > 0) data = data.slice(1);
|
||||
|
||||
while (data.length < totalPoints) {
|
||||
var prev = data.length > 0 ? data[data.length - 1] : 50, y = prev + Math.random() * 10 - 5;
|
||||
if (y < 0) { y = 0; } else if (y > 100) { y = 100; }
|
||||
|
||||
data.push(y);
|
||||
}
|
||||
|
||||
var res = [];
|
||||
for (var i = 0; i < data.length; ++i) {
|
||||
res.push([i, data[i]]);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
1
assets/dashboard/js/script.js
Normal file
1
assets/dashboard/js/script.js
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user