added resume/pause buttons to files

This commit is contained in:
csoler 2019-01-06 18:17:42 +01:00
parent 538aaff619
commit d4260f7b95
2 changed files with 53 additions and 3 deletions

View File

@ -33,8 +33,9 @@ function cntrlBtn(file, act) {
return(
m("div.btn",{
onclick: function(){
console.log("Control button pushed");
//rs.request("transfers/control_download",{action: act, hash: file.hash});
console.log("Control button pushed. Action on file " + file.hash + " is " + act);
rs.Downloads.control(file.hash,act) ;
}
},
act)
@ -95,7 +96,7 @@ module.exports = {
m("td", fileInfo.download_status),
m("td", progressBar(fileInfo)),
m("td", [
cntrlBtn(fileInfo, fileInfo.download_status==="paused"?"start":"pause"),
cntrlBtn(fileInfo, fileInfo.download_status===rs.FT_STATE_PAUSED?"resume":"pause"),
cntrlBtn(fileInfo, "cancel")]
)
])

View File

@ -21,9 +21,27 @@ function rsJsonApiRequest(path, data, callback,async)
xhr.send(data);
}
// These constants are the onces listed in retroshare/rsfiles.h. I would like to make them "members" of Downloads
// but I dont know how to do this.
var RS_FILE_CTRL_PAUSE = 0x00000100;
var RS_FILE_CTRL_START = 0x00000200;
var RS_FILE_CTRL_FORCE_CHECK= 0x00000400;
var FT_STATE_FAILED = 0x0000 ;
var FT_STATE_OKAY = 0x0001 ;
var FT_STATE_WAITING = 0x0002 ;
var FT_STATE_DOWNLOADING = 0x0003 ;
var FT_STATE_COMPLETE = 0x0004 ;
var FT_STATE_QUEUED = 0x0005 ;
var FT_STATE_PAUSED = 0x0006 ;
var FT_STATE_CHECKING_HASH = 0x0007 ;
var Downloads = {
list: [],
// Load function for files. Populates the "list" array with Objects of type corresponding to rsfiles.h:FileInfo
load: function() {
function addDLInfo(p)
{
@ -57,6 +75,37 @@ var Downloads = {
console.log("requesting downloads...");
rsJsonApiRequest("/rsFiles/FileDownloads", "", handleHashesList,false)
},
// Control function for files. Hash is the file hash and control_action is the action to perform to be chosen as { "cancel", "pause", "resume" }
control: function(hash,control_action){
var req_action = "" ; // action requested to jsonapi
var json_params = { hash: hash } ; // params for that action
switch(control_action)
{
case "cancel": req_action = "/rsFiles/FileCancel" ;
break;
case "pause": req_action = "/rsFiles/FileControl" ;
json_params.flags = Downloads.RS_FILE_CTRL_PAUSE ;
break ;
case "resume": req_action = "/rsFiles/FileControl" ;
json_params.flags = Downloads.RS_FILE_CTRL_START ;
break ;
case "force_check": req_action = "/rsFiles/FileControl" ;
json_params.flags = Downloads.RS_FILE_CTRL_FORCE_CHECK ;
break ;
default:
console.log("Unknown action in Downloads.control()");
return ;
};
rsJsonApiRequest(req_action, JSON.stringify(json_params),false)
}
}