added basic display of downloads

This commit is contained in:
csoler 2019-01-05 00:03:09 +01:00
parent 9c76a0c6c8
commit f99ee66210
4 changed files with 146 additions and 4 deletions

View File

@ -12,15 +12,23 @@
This is the node's certificate:
</h3>
<textarea rows="30" cols="64" placeholder="Node certificate should appear here!" id="node_certificate" maxlength="10000"></textarea>
<textarea rows="30" cols="64" placeholder="Downloads" id="downloads" maxlength="10000"></textarea>
<script type="text/javascript">
function load_cert(cert) {
document.getElementById("node_certificate").value = cert
}
function load_downloads(dls) {
document.getElementById("downloads").value = dls
}
function load_ui(){
var ui = require("rswebui");
ui.requestCertificate(load_cert);
var dl = require("downloads");
dl.view(load_downloads);
}
</script>
<noscript>Sorry but JavaScript is needed here! Please enable it in your browser.</noscript>
</div>

View File

@ -0,0 +1,96 @@
var m = require("mithril");
var rs = require("rswebui");
function makeFriendlyUnit(bytes)
{
if(bytes < 1e3)
return bytes.toFixed(1) + "B";
if(bytes < 1e6)
return (bytes/1e3).toFixed(1) + "kB";
if(bytes < 1e9)
return (bytes/1e6).toFixed(1) + "MB";
if(bytes < 1e12)
return (bytes/1e9).toFixed(1) + "GB";
return (bytes/1e12).toFixed(1) + "TB";
}
function progressBar(file){
return m("div[style=border:5px solid lime;"
+ 'border-radius:3mm;'
+ 'padding:2mm;'
+ 'height:5mm'
+ "]", [
m("div[style="
+ 'background-color:lime;'
+ 'height:100%;'
+ 'width:' + (file.transferred / file.size * 100)+'%'
+ ']'
,"")
]);
};
//function cntrlBtn(file, act) {
// return(
// m("div.btn",{
// onclick: function(){
// rs.request("transfers/control_download",{action: act, hash: file.hash});
// }
// },
// act)
// )
//}
module.exports = {
view: function(callback){
rs.requestDownloads(callback);
// var filestreamer_url = "/fstream/";
// if (paths === undefined) {
// return m("div", "Downloads ... please wait ...");
// }
// return m("div", [
// m("h2","Downloads (" + paths.length +")"),
// m("div.btn2", {
// onclick: function(){
// m.route("/downloads/add");
// }
//
// m("hr"),
// m('table', [
// m("tr",[
// m("th","name"),
// m("th","size"),
// m("th","progress"),
// m("th","transfer rate"),
// m("th","status"),
// m("th","progress"),
// m("th","action")
// ]),
// paths.map(function (file){
// var ctrlBtn = m("div","");
// var progress = file.transferred / file.size * 100;
// return m("tr",[
// m("td",[
// m("a.filelink",
// {
// target: "blank",
// href: filestreamer_url + file.hash + "/" + encodeURIComponent(file.name)
// },
// file.name
// )
// ]),
// m("td", makeFriendlyUnit(file.size)),
// m("td", progress.toPrecision(3) + "%"),
// m("td", makeFriendlyUnit(file.transfer_rate*1e3)+"/s"),
// m("td", file.download_status),
// m("td", progressBar(file)),
// m("td", [
// cntrlBtn(file, file.download_status==="paused"?"start":"pause"),
// cntrlBtn(file, "cancel")]
// )
// ])
// })
// ])
// ]);
}
};

View File

@ -29,8 +29,46 @@ module.exports = {
var jsonData = JSON.parse(p)
callback(jsonData.retval)
}
rsJsonApiRequest("/rsPeers/GetRetroshareInvite", "", setNodeCertificate,true) // call is synced because we want to return the result
}
rsJsonApiRequest("/rsPeers/GetRetroshareInvite", "", setNodeCertificate,true)
},
requestDownloads:function(callback) {
var downloads_info = ""
function displayDLInfo(p)
{
var jsonData = JSON.parse(p)
if(jsonData.retval === "false")
console.warning("Cannot retrieve info!!");
downloads_info += jsonData.info.hash + ": size=" + jsonData.info.size + ": progress=" + jsonData.info.avail + "\n";
}
function requestDLData(hash)
{
var json_params = {
hash: hash,
hintflags: 16 // = RS_FILE_HINTS_DOWNLOAD
}
console.log("requesting DL data for hash: "+hash)
rsJsonApiRequest("/rsFiles/FileDetails", JSON.stringify(json_params), displayDLInfo,false)
}
function setDownloads(p)
{
var jsonData = JSON.parse(p)
// now for each hash, request the current progress
jsonData.hashs.forEach(requestDLData);
// and send back the result
callback(downloads_info);
}
rsJsonApiRequest("/rsFiles/FileDownloads", "", setDownloads,true)
}
};

View File

@ -42,11 +42,12 @@ linux-* {
WEBUI_SRC_JS += webui-src/app/rswebui.js
WEBUI_SRC_JS += webui-src/app/mithril.js
WEBUI_SRC_JS += webui-src/app/mithril.min.js
WEBUI_SRC_JS += webui-src/app/downloads.js
# WEBUI_SRC_JS += webui-src/app/peers.js
# WEBUI_SRC_JS += webui-src/app/main.js
# WEBUI_SRC_JS += webui-src/app/menudef.js
# WEBUI_SRC_JS += webui-src/app/menu.js
# WEBUI_SRC_JS += webui-src/app/peers.js
# WEBUI_SRC_JS += webui-src/app/retroshare.js
# WEBUI_SRC_JS += webui-src/app/accountselect.js
# WEBUI_SRC_JS += webui-src/app/adddownloads.js
@ -54,7 +55,6 @@ linux-* {
# WEBUI_SRC_JS += webui-src/app/addpeer.js
# WEBUI_SRC_JS += webui-src/app/chat.js
# WEBUI_SRC_JS += webui-src/app/createlogin.js
# WEBUI_SRC_JS += webui-src/app/downloads.js
# WEBUI_SRC_JS += webui-src/app/forums.js
# WEBUI_SRC_JS += webui-src/app/home.js
# WEBUI_SRC_JS += webui-src/app/identities.js