2012-10-30 04:34:14 +01:00
|
|
|
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab: */
|
|
|
|
Piecon.setOptions({fallback: 'force'});
|
2012-12-26 11:57:11 +01:00
|
|
|
|
2012-08-01 17:59:12 +02:00
|
|
|
var graphSize = 15;
|
2012-08-01 12:44:20 +02:00
|
|
|
var graphData = [];
|
2012-08-04 20:37:25 +02:00
|
|
|
var globalGraphData = null;
|
2012-12-26 11:57:11 +01:00
|
|
|
var modals = {};
|
2012-08-01 12:44:20 +02:00
|
|
|
var clear_dialogs = function() {
|
|
|
|
for(var i in modals) {
|
|
|
|
modals[i].modal('hide');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var server_conf = {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 6800,
|
|
|
|
user: "",
|
2012-10-02 16:50:57 +02:00
|
|
|
pass: "",
|
2012-10-02 20:06:37 +02:00
|
|
|
encryption: false,
|
|
|
|
dirty: false
|
2012-08-01 12:44:20 +02:00
|
|
|
};
|
|
|
|
|
2012-10-02 20:06:37 +02:00
|
|
|
var ariaConnection;
|
2012-08-01 12:44:20 +02:00
|
|
|
var set_conf_cookie = function() {
|
2012-08-25 12:58:17 +02:00
|
|
|
setCookie('aria2_server_conf', JSON.stringify(server_conf), 30 * 12);
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
var get_conf_cookie = function() {
|
2012-09-05 02:21:29 +02:00
|
|
|
if (getCookie( $.trim('aria2_server_conf'))) {
|
2012-08-01 12:44:20 +02:00
|
|
|
server_conf = JSON.parse(getCookie('aria2_server_conf'));
|
2012-10-02 20:06:37 +02:00
|
|
|
server_conf.dirty = false;
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var custom_aria2_connect = function() {
|
|
|
|
clear_dialogs();
|
2012-08-24 19:44:34 +02:00
|
|
|
$("#input_host").attr("placeholder", server_conf.host);
|
|
|
|
$("#input_port").attr("placeholder", server_conf.port);
|
2012-10-02 16:50:57 +02:00
|
|
|
if(server_conf.encryption) {
|
|
|
|
$("#input_encryption").addClass("active");
|
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
modals.change_conf.modal('show');
|
|
|
|
};
|
|
|
|
var update_server_conf = function() {
|
|
|
|
var host = $('#input_host').val().trim();
|
|
|
|
var port = $('#input_port').val().trim();
|
|
|
|
server_conf.user = $('#input_user').val().trim();
|
|
|
|
server_conf.pass = $('#input_pass').val().trim();
|
2012-10-02 16:50:57 +02:00
|
|
|
server_conf.encryption = $('#input_encryption').hasClass('active');
|
2012-08-01 12:44:20 +02:00
|
|
|
if(host.length !== 0) {
|
|
|
|
server_conf.host = host;
|
|
|
|
}
|
|
|
|
if(port.length !== 0) {
|
|
|
|
server_conf.port = port;
|
|
|
|
}
|
2012-10-02 20:06:37 +02:00
|
|
|
server_conf.dirty = false;
|
2012-08-01 12:44:20 +02:00
|
|
|
set_conf_cookie();
|
2012-09-05 16:53:09 +02:00
|
|
|
ariaConnection = new AriaConnection(server_conf);
|
2012-08-01 12:44:20 +02:00
|
|
|
clear_dialogs();
|
|
|
|
update_ui();
|
|
|
|
};
|
|
|
|
|
2012-09-05 16:53:09 +02:00
|
|
|
var aria_syscall = function(conf, multicall, old) {
|
|
|
|
conf.multicall = multicall;
|
|
|
|
ariaConnection.invoke(conf);
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
var update_ui = function() {
|
2012-10-04 06:42:26 +02:00
|
|
|
if (!server_conf.dirty)
|
2012-10-02 20:06:37 +02:00
|
|
|
updateDownloads();
|
2012-08-01 12:44:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
if (window.location.protocol === "http:") {
|
|
|
|
server_conf.host = window.location.hostname;
|
|
|
|
}
|
|
|
|
get_conf_cookie();
|
|
|
|
var modal_conf = {
|
|
|
|
show: false,
|
|
|
|
backdrop: false
|
|
|
|
};
|
|
|
|
modals.err_connect = $('#error_connect').modal(modal_conf);
|
|
|
|
modals.change_conf = $('#change_conf').modal(modal_conf);
|
|
|
|
modals.newDownload_modal = $('#newDownload_modal').modal(modal_conf);
|
|
|
|
modals.global_settings_modal = $('#global_settings_modal').modal(modal_conf);
|
|
|
|
modals.download_settings_modal = $('#download_settings_modal').modal(modal_conf);
|
2012-08-04 22:08:08 +02:00
|
|
|
modals.torrent_info_modal = $('#torrent_info_modal').modal(modal_conf);
|
2012-08-01 12:44:20 +02:00
|
|
|
modals.global_statistics_modal = $('#global_statistics_modal').modal(modal_conf);
|
|
|
|
modals.about_modal = $('#about_modal').modal(modal_conf);
|
|
|
|
modals.err_file_api_modal = $('#error_file_api').modal(modal_conf);
|
|
|
|
modals.new_torrent_modal = $('#new_torrent').modal(modal_conf);
|
|
|
|
modals.new_metalink_modal = $('#new_metalink').modal(modal_conf);
|
|
|
|
|
2012-10-02 20:06:37 +02:00
|
|
|
ariaConnection = new AriaConnection(server_conf)
|
2012-08-01 12:44:20 +02:00
|
|
|
update_ui();
|
2012-08-04 20:37:25 +02:00
|
|
|
globalGraphData = {
|
|
|
|
downSpeed: [],
|
|
|
|
upSpeed: [],
|
|
|
|
add: function(arr, val) {
|
|
|
|
if (arr.length == graphSize) {
|
|
|
|
arr.shift();
|
|
|
|
}
|
|
|
|
arr.push([((new Date - this.start)/1000).toFixed(0), val]);
|
|
|
|
},
|
|
|
|
addDown: function(val) {
|
|
|
|
this.add(this.downSpeed, val);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
addUp: function(val) {
|
|
|
|
this.add(this.upSpeed, val);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
plot: createGraph('.stat_graph'),
|
|
|
|
start: new Date()
|
|
|
|
};
|
2012-08-01 12:44:20 +02:00
|
|
|
$('#newDownload').click(function() {
|
|
|
|
$('#newDownload_url').val("");
|
|
|
|
$('.download_urls').html("");
|
|
|
|
modals.newDownload_modal.modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#newDownload_torrent').click(function() {
|
|
|
|
$('#input_torrent').val("");
|
|
|
|
if(window.File && window.FileReader && window.FileList && window.Blob) {
|
|
|
|
modals.new_torrent_modal.modal('show');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
modals.err_file_api_modal.modal('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#newDownload_metalink').click(function() {
|
|
|
|
$('#input_metalink').val("");
|
|
|
|
if(window.File && window.FileReader && window.FileList && window.Blob) {
|
|
|
|
modals.new_metalink_modal.modal('show');
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
modals.err_file_api_modal.modal('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#multiple_uris').click(function() {
|
2012-08-27 08:12:52 +02:00
|
|
|
if ($('#multiple_uris i').hasClass('icon-plus-sign')) {
|
|
|
|
var txt = $('#newDownload_url').val();
|
|
|
|
$('#newDownload_url').replaceWith('<textarea style="width: 270px" id="newDownload_url" rows="5"></textarea>');
|
|
|
|
if (txt.trim().length)
|
|
|
|
$('#newDownload_url').val(txt + '\n');
|
|
|
|
$('#multiple_uris i').removeClass('icon-plus-sign').addClass('icon-minus-sign');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#newDownload_url').replaceWith('<input type="text" class="input-xlarge" id="newDownload_url" placeholder="http://example.com"/>');
|
|
|
|
$('#multiple_uris i').removeClass('icon-minus-sign').addClass('icon-plus-sign');
|
|
|
|
}
|
2012-08-27 13:12:50 +02:00
|
|
|
return false;
|
2012-08-01 12:44:20 +02:00
|
|
|
});
|
|
|
|
$('#addNewDownload').click(newDownload);
|
2012-08-27 08:12:52 +02:00
|
|
|
|
2012-08-01 12:44:20 +02:00
|
|
|
setInterval(update_ui, 1000);
|
|
|
|
});
|
|
|
|
function check_global(name) {
|
|
|
|
for(var i = 0; i < global_settings_exclude.length; i++) {
|
|
|
|
if(global_settings_exclude[i] === name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function merge_settings_data(sets, res) {
|
|
|
|
for(var i in res) {
|
|
|
|
for(var j = 0; j < sets.length; j++) {
|
|
|
|
if(sets[j].name === i) {
|
|
|
|
sets[j].value = res[i].trim();
|
|
|
|
sets[j].has_value = true;
|
|
|
|
if(sets[j].option) {
|
|
|
|
for(var k = 0; k < sets[j].options.length; k++) {
|
|
|
|
var tmp = {
|
|
|
|
val: sets[j].options[k],
|
|
|
|
disp: sets[j].options[k]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(sets[j].options[k] === sets[j].value) {
|
|
|
|
tmp.val = sets[j].value + '" selected="true';
|
|
|
|
}
|
|
|
|
sets[j].options[k] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function get_global_settings(cb) {
|
|
|
|
var sets = [];
|
|
|
|
var tmp_set = [];
|
|
|
|
for(var i = 0; i < input_file_settings.length; i++) {
|
|
|
|
tmp_set = $.extend(true, {}, input_file_settings[i]);
|
|
|
|
if(check_global(tmp_set)) {
|
|
|
|
sets.push(tmp_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(var i = 0; i < global_settings.length; i++) {
|
|
|
|
tmp_set = $.extend(true, {}, global_settings[i]);
|
|
|
|
if(check_global(tmp_set)) {
|
|
|
|
sets.push(tmp_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aria_syscall({
|
|
|
|
func: 'getGlobalOption',
|
|
|
|
success: function(data) {
|
|
|
|
var res = data.result;
|
|
|
|
merge_settings_data(sets, res);
|
|
|
|
cb(sets);
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
alert("Connection to aria server failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function custom_global_settings() {
|
|
|
|
var gen = function(name) {
|
|
|
|
return { name: name, values: [] };
|
|
|
|
};
|
|
|
|
var general_settings = gen("General Settings");
|
|
|
|
var torrent_settings = gen("Bit-Torrent Settings");
|
|
|
|
var ftp_settings = gen("FTP Settings");
|
|
|
|
var http_settings = gen("HTTP(S) Settings");
|
|
|
|
var metalink_settings = gen("Metalink Settings");
|
|
|
|
|
|
|
|
get_global_settings(function(sets) {
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var set = sets[i];
|
|
|
|
if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) {
|
|
|
|
torrent_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("metalink") !== -1) {
|
|
|
|
metalink_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("http") !== -1) {
|
|
|
|
http_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("ftp") !== -1) {
|
|
|
|
ftp_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
general_settings.values.push(set);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var templ = $('#global_general_settings_template').text();
|
|
|
|
var item = Mustache.render(templ, {
|
|
|
|
settings: [
|
|
|
|
general_settings,
|
|
|
|
http_settings,
|
|
|
|
ftp_settings,
|
|
|
|
torrent_settings,
|
|
|
|
metalink_settings
|
|
|
|
]
|
|
|
|
});
|
|
|
|
$('#dynamic_global_settings').html(item);
|
|
|
|
modals.global_settings_modal.modal('show');
|
|
|
|
$("#save_global_settings").one('click',function() {
|
|
|
|
var settings = {};
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var elem = $("#input_settings_" + sets[i].name);
|
|
|
|
if(sets[i].value) {
|
|
|
|
if(elem.val() !== sets[i].value) {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(elem.val() !== "no_val" && elem.val() !== "") {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$.isEmptyObject(settings)) {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'changeGlobalOption',
|
|
|
|
params: [settings],
|
|
|
|
success: function(data) {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDownload(uris) {
|
|
|
|
console.log("adding download:");
|
|
|
|
console.log(uris);
|
|
|
|
aria_syscall({
|
|
|
|
func: 'addUri',
|
|
|
|
params: uris,
|
|
|
|
success: function() {
|
|
|
|
clear_dialogs();
|
|
|
|
update_ui();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function newDownload() {
|
2012-08-27 13:18:47 +02:00
|
|
|
var urls = $('#newDownload_url').val().split(/\s+/)
|
2012-08-27 08:12:52 +02:00
|
|
|
.map(function(e) {
|
|
|
|
return e.trim();
|
|
|
|
})
|
|
|
|
.filter(function(e) {
|
|
|
|
return e.length;
|
|
|
|
});
|
2012-08-01 12:44:20 +02:00
|
|
|
|
|
|
|
addDownload([urls]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var d_files = {
|
|
|
|
active: [],
|
|
|
|
waiting: [],
|
|
|
|
stopped: []
|
|
|
|
};
|
|
|
|
function changeLength(len, pref) {
|
|
|
|
len = parseInt(len);
|
|
|
|
if(len <= (1<<10)) return len + " " + pref;
|
|
|
|
else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref;
|
|
|
|
else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref;
|
|
|
|
else return (len/(1<<30)).toFixed(1) + " G" + pref;
|
|
|
|
}
|
|
|
|
function changeTime(time) {
|
|
|
|
time = parseInt(time);
|
|
|
|
if(!time) return "infinite";
|
|
|
|
if(time < 60) return time + " s";
|
|
|
|
else if(time < 60*60) return (time/60).toFixed(2) + " min";
|
|
|
|
else if(time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours";
|
|
|
|
else return (time/(60*60*24)).toFixed(2) + " days!!";
|
|
|
|
|
|
|
|
}
|
2012-08-01 21:07:37 +02:00
|
|
|
function getChunksFromHex(bitfield, numOfPieces) {
|
2012-08-02 05:42:03 +02:00
|
|
|
var chunks = [], len = 0, numPieces = parseInt(numOfPieces);
|
2012-08-02 14:47:01 +02:00
|
|
|
var totalDownloaded = 0;
|
2012-08-01 21:07:37 +02:00
|
|
|
if (numPieces > 1) {
|
2012-08-04 20:37:25 +02:00
|
|
|
var chunk_ratio = 1 / numPieces;
|
2012-08-02 14:47:01 +02:00
|
|
|
var piecesProcessed = 0;
|
2012-08-01 21:07:37 +02:00
|
|
|
for (var i = 0; i < bitfield.length; i++) {
|
|
|
|
var hex = parseInt(bitfield[i], 16);
|
|
|
|
for (var j = 1; j <= 4; j++) {
|
|
|
|
var bit = hex & (1 << (4 - j));
|
2012-08-02 14:47:01 +02:00
|
|
|
if (bit) totalDownloaded++;
|
2012-08-04 20:37:25 +02:00
|
|
|
var prog = !!bit;
|
|
|
|
if (len >= 1 && chunks[len - 1].show == prog) {
|
|
|
|
chunks[len - 1].ratio += chunk_ratio;
|
2012-08-02 05:42:03 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
chunks.push({
|
2012-08-04 20:37:25 +02:00
|
|
|
ratio: chunk_ratio,
|
|
|
|
show: prog
|
2012-08-02 05:42:03 +02:00
|
|
|
});
|
|
|
|
len++;
|
|
|
|
}
|
2012-08-04 20:37:25 +02:00
|
|
|
piecesProcessed++;
|
2012-08-02 14:47:01 +02:00
|
|
|
if (piecesProcessed == numPieces)
|
|
|
|
return chunks;
|
2012-08-01 21:07:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chunks;
|
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
function getTemplateCtx(data) {
|
2013-01-19 18:46:22 +01:00
|
|
|
var obj = {
|
|
|
|
status: data.status,
|
|
|
|
gid: data.gid,
|
|
|
|
numPieces: data.numPieces,
|
|
|
|
connections: data.connections,
|
|
|
|
bittorrent: data.bittorrent
|
|
|
|
};
|
|
|
|
|
|
|
|
obj.files = data.files.map(function(e) {
|
|
|
|
e.length = changeLength(e.length, "B");
|
|
|
|
e.path = e.path.replace(/\\/g, '/').replace(obj.dir, '.');
|
|
|
|
return e;
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(['downloadSpeed', 'uploadSpeed'], function(e) {
|
|
|
|
obj[e] = changeLength(data[e], 'B/s');
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each([
|
|
|
|
'totalLength', 'completedLength', 'uploadLength', 'pieceLength'
|
|
|
|
], function(e) {
|
|
|
|
obj[e] = changeLength(data[e], 'B');
|
|
|
|
});
|
|
|
|
|
|
|
|
obj.eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed);
|
|
|
|
|
|
|
|
var percentage = (data.completedLength / data.totalLength)*100;
|
2012-08-01 12:44:20 +02:00
|
|
|
percentage = percentage.toFixed(2);
|
|
|
|
if(!percentage) percentage = 0;
|
2013-01-19 18:46:22 +01:00
|
|
|
|
|
|
|
obj.percentage = percentage;
|
|
|
|
|
|
|
|
if (obj.bittorrent && obj.bittorrent.info) {
|
|
|
|
obj.name = obj.bittorrent.info.name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var seed = (obj.files[0].path || obj.files[0].uris[0].uri).split(/[/\\]/);
|
|
|
|
obj.name = seed[seed.length - 1];
|
2012-10-30 04:03:40 +01:00
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
|
2013-01-17 07:51:03 +01:00
|
|
|
var type = data.status;
|
|
|
|
if (type == "paused") type = "waiting";
|
2013-01-19 18:46:22 +01:00
|
|
|
if (["error", "removed", "complete"].indexOf(type) != -1)
|
|
|
|
type = "stopped";
|
2013-01-17 18:13:58 +01:00
|
|
|
|
2013-01-19 18:46:22 +01:00
|
|
|
obj.type = type;
|
|
|
|
|
|
|
|
obj.dir = data.dir.replace(/\\/g, '/');
|
|
|
|
|
|
|
|
obj.chunks = percentage !== 100 && data.bitfield ? getChunksFromHex(data.bitfield, data.numPieces) : [];
|
|
|
|
|
|
|
|
obj.booleans = {
|
|
|
|
is_error: obj.status === "error",
|
|
|
|
is_complete: obj.status === "complete",
|
|
|
|
is_removed: obj.status === "removed",
|
|
|
|
has_settings: ["active", "waiting", "paused"].indexOf(obj.status) != -1,
|
|
|
|
can_pause: type == "active",
|
|
|
|
can_play: type == "waiting",
|
|
|
|
bittorrent: !!obj.bittorrent,
|
|
|
|
can_restart: type == "stopped"
|
2012-08-01 12:44:20 +02:00
|
|
|
};
|
2013-01-19 18:46:22 +01:00
|
|
|
|
|
|
|
return obj;
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
function updateDownloadTemplates(elem, ctx) {
|
|
|
|
elem = $(elem);
|
2013-01-15 09:24:09 +01:00
|
|
|
|
|
|
|
// update spans
|
2012-08-01 12:44:20 +02:00
|
|
|
for(var i in ctx) {
|
2013-01-15 09:24:09 +01:00
|
|
|
elem.find('.download-' + i).text(ctx[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update files
|
|
|
|
var html = '';
|
|
|
|
for (var i = 0; i < ctx.files.length; i++) {
|
|
|
|
html += '<li class="label">' + ctx.files[i].path + ' (' + ctx.files[i].size + ')</li>';
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
2013-01-15 09:24:09 +01:00
|
|
|
elem.find('.download-files').html(html);
|
|
|
|
|
|
|
|
// update progress bar
|
2013-01-17 08:00:33 +01:00
|
|
|
elem.find('.progress .bar').css('width', ctx.percentage + '%');
|
2013-01-15 09:24:09 +01:00
|
|
|
|
|
|
|
// update the chunks bar
|
2012-08-02 05:42:03 +02:00
|
|
|
var chunks = ctx.chunks;
|
2012-08-02 14:47:01 +02:00
|
|
|
if (!chunks || !chunks.length) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-04 20:37:25 +02:00
|
|
|
var canvas = elem.find(".chunk-canvas")[0];
|
|
|
|
if (!canvas) {
|
|
|
|
return;
|
2012-08-02 05:42:03 +02:00
|
|
|
}
|
2012-08-04 20:37:25 +02:00
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
ctx.fillStyle = "#149BDF";
|
2012-08-04 22:08:08 +02:00
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
2012-08-04 20:37:25 +02:00
|
|
|
var x = 0,
|
|
|
|
width = canvas.width,
|
|
|
|
height = canvas.height;
|
|
|
|
chunks.forEach(function(c) {
|
|
|
|
var dx = c.ratio * width;
|
|
|
|
if (c.show)
|
|
|
|
ctx.fillRect(x, 0, dx, height);
|
|
|
|
x += dx;
|
2012-08-02 05:42:03 +02:00
|
|
|
});
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
2013-01-03 18:47:38 +01:00
|
|
|
function deleteDownloadTemplates($top_elem, data) {
|
2012-08-01 12:44:20 +02:00
|
|
|
if(!data) {
|
|
|
|
graphData = [];
|
2013-01-03 18:47:38 +01:00
|
|
|
$top_elem.html("");
|
|
|
|
} else {
|
|
|
|
var elems = $top_elem.find('[data-gid]');
|
2012-08-01 12:44:20 +02:00
|
|
|
for(var i = 0; i < elems.length; i++) {
|
|
|
|
var elem = $(elems[i]);
|
|
|
|
var gid = elem.attr('data-gid').toString();
|
|
|
|
var found = false;
|
|
|
|
for(var j = 0; j < data.length; j++) {
|
|
|
|
if(gid === data[j].gid.toString())
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
if(!found) {
|
2012-08-01 15:06:25 +02:00
|
|
|
for (var k = 0; k < graphData.length; k++) {
|
|
|
|
if (graphData[k].gid == gid) {
|
|
|
|
graphData.splice(k, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
elem.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function refreshDownloadTemplates(top_elem, data) {
|
2013-01-17 07:51:03 +01:00
|
|
|
var down_template = $('#download_template').text(),
|
2013-01-03 18:47:38 +01:00
|
|
|
new_items = [],
|
|
|
|
$top_elem = $('#' + top_elem + '_downloads');
|
|
|
|
|
|
|
|
deleteDownloadTemplates($top_elem, data);
|
2012-08-01 12:44:20 +02:00
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
var ctx = getTemplateCtx(data[i]);
|
2013-01-15 09:24:09 +01:00
|
|
|
var elem = $top_elem.find('[data-gid=' + ctx.gid + ']');
|
2012-08-01 12:44:20 +02:00
|
|
|
if(elem.length) {
|
|
|
|
updateDownloadTemplates(elem, ctx);
|
|
|
|
} else {
|
|
|
|
var item = Mustache.render(down_template, ctx);
|
2013-01-05 09:41:05 +01:00
|
|
|
new_items.push(item);
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-02 21:58:37 +01:00
|
|
|
if (new_items.length > 0) {
|
2013-01-05 09:41:05 +01:00
|
|
|
$top_elem.append(new_items);
|
2013-01-02 21:58:37 +01:00
|
|
|
}
|
2013-01-03 18:47:38 +01:00
|
|
|
$top_elem.children('.hero-unit').remove();
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
function updateGraph(gid) {
|
|
|
|
var elem = $('[data-gid=' + gid + ']');
|
|
|
|
for (var i = 0; i < graphData.length; i++) {
|
|
|
|
if (graphData[i].gid == gid) {
|
|
|
|
var moreInfo = $(elem).find(".more_info");
|
|
|
|
if (moreInfo.hasClass("in")) {
|
|
|
|
graphData[i].plot.setData([{
|
|
|
|
label: "Download Speed",
|
|
|
|
data: graphData[i].downSpeed,
|
|
|
|
color: "#ff0000",
|
|
|
|
lines: { show: true }
|
|
|
|
}, {
|
|
|
|
label: "Upload Speed",
|
2012-08-01 17:59:12 +02:00
|
|
|
data: graphData[i].upSpeed,
|
2012-08-01 12:44:20 +02:00
|
|
|
color: "#00ff00",
|
|
|
|
lines: { show: true }
|
|
|
|
}]);
|
2012-12-26 11:57:11 +01:00
|
|
|
graphData[i].plot.resize();
|
2012-08-01 12:44:20 +02:00
|
|
|
graphData[i].plot.setupGrid();
|
|
|
|
graphData[i].plot.draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-04 20:37:25 +02:00
|
|
|
function createGraph(selector) {
|
2012-12-30 08:54:00 +01:00
|
|
|
var elem = $(selector);
|
|
|
|
elem.height(elem.width() / 2);
|
|
|
|
|
|
|
|
return $.plot(elem, [{
|
2012-08-01 12:44:20 +02:00
|
|
|
label: "Download Speed",
|
|
|
|
data: [],
|
|
|
|
color: "#ff0000",
|
|
|
|
lines: { show: true }
|
|
|
|
}, {
|
|
|
|
label: "Upload Speed",
|
|
|
|
data: [],
|
|
|
|
color: "#00ff00",
|
|
|
|
lines: { show: true }
|
|
|
|
}], {
|
|
|
|
legend: { show: true },
|
|
|
|
xaxis: { show: true },
|
|
|
|
yaxis: {
|
|
|
|
tickFormatter: function(val, axis) {
|
|
|
|
return changeLength(val, "B/s");
|
|
|
|
},
|
|
|
|
min: 0
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function updateGraphData(data) {
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var gid = data[i].gid;
|
2012-08-01 17:59:12 +02:00
|
|
|
var graph = null;
|
|
|
|
for (var k = 0; k < graphData.length; k++) {
|
2012-08-01 15:06:25 +02:00
|
|
|
if (graphData[k].gid == gid) {
|
|
|
|
graph = graphData[k];
|
2012-08-01 12:44:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var downSpeed = data[i].downloadSpeed;
|
|
|
|
var upSpeed = data[i].uploadSpeed;
|
|
|
|
var that = this;
|
|
|
|
if (!graph) {
|
2012-08-01 15:06:25 +02:00
|
|
|
graphData.push((function() {
|
2012-08-01 12:44:20 +02:00
|
|
|
return {
|
|
|
|
gid: gid,
|
|
|
|
downSpeed: [],
|
|
|
|
upSpeed: [],
|
|
|
|
add: function(arr, val) {
|
|
|
|
if (arr.length == graphSize) {
|
|
|
|
arr.shift();
|
|
|
|
}
|
|
|
|
arr.push([((new Date - this.start)/1000).toFixed(0), val]);
|
|
|
|
},
|
|
|
|
addDown: function(val) {
|
|
|
|
this.add(this.downSpeed, val);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
addUp: function(val) {
|
|
|
|
this.add(this.upSpeed, val);
|
|
|
|
return this;
|
|
|
|
},
|
2013-01-21 15:07:55 +01:00
|
|
|
plot: that.createGraph('[data-gid=' + gid + '] .download-graph'),
|
2012-08-01 12:44:20 +02:00
|
|
|
start: new Date()
|
|
|
|
}
|
|
|
|
})().addDown(downSpeed).addUp(upSpeed));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
graph.addDown(downSpeed).addUp(upSpeed);
|
|
|
|
}
|
|
|
|
this.updateGraph(gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getActiveSettings(gid, cb) {
|
|
|
|
var sets = [];
|
|
|
|
var tmp_set = [];
|
|
|
|
for(var i = 0; i < download_active_settings.length; i++) {
|
|
|
|
tmp_set = $.extend(true, {}, download_active_settings[i]);
|
|
|
|
sets.push(tmp_set);
|
|
|
|
}
|
|
|
|
aria_syscall({
|
|
|
|
func: 'getOption',
|
|
|
|
params: [gid],
|
|
|
|
success: function(data) {
|
|
|
|
var res = data.result;
|
|
|
|
merge_settings_data(sets, res);
|
|
|
|
cb(sets);
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
alert("Connection to aria server failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function check_waiting(name) {
|
|
|
|
for(var i = 0; i < download_waiting_exclude.length; i++) {
|
|
|
|
if(download_waiting_exclude[i] === name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function getWaitingSettings(gid, cb) {
|
|
|
|
var sets = [];
|
|
|
|
var tmp_set = [];
|
|
|
|
for(var i = 0; i < input_file_settings.length; i++) {
|
|
|
|
tmp_set = $.extend(true, {}, input_file_settings[i]);
|
|
|
|
if(check_waiting(tmp_set)) {
|
|
|
|
sets.push(tmp_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(var i = 0; i < download_active_settings.length; i++) {
|
|
|
|
tmp_set = $.extend(true, {}, download_active_settings[i]);
|
|
|
|
if(check_waiting(tmp_set)) {
|
|
|
|
sets.push(tmp_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aria_syscall({
|
|
|
|
func: 'getOption',
|
|
|
|
params: [gid],
|
|
|
|
success: function(data) {
|
|
|
|
var res = data.result;
|
|
|
|
merge_settings_data(sets, res);
|
|
|
|
cb(sets);
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
alert("Connection to aria server failed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function empty_download_set(elem) {
|
|
|
|
var len = d_files.active.length;
|
|
|
|
len += d_files.waiting.length;
|
|
|
|
len += d_files.stopped.length;
|
|
|
|
if(len === 0) {
|
|
|
|
var html = '<div class="hero-unit"><h3>';
|
|
|
|
|
|
|
|
html += 'Currently no downloads in line to display, use the Add download button to start downloading files!';
|
|
|
|
html += '</h3></div>';
|
|
|
|
$(elem).html(html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function updateActiveDownloads(data) {
|
|
|
|
refreshDownloadTemplates('active', data);
|
|
|
|
updateGraphData(data);
|
|
|
|
empty_download_set('#active_downloads');
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.active-download .download_settings').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.active-download').attr('data-gid');
|
|
|
|
var settings_name = $(this).parents('.active-download').attr('data-settingsName');
|
2012-08-01 12:44:20 +02:00
|
|
|
var gen = function(name) {
|
|
|
|
return { name: name, values: [] };
|
|
|
|
};
|
|
|
|
var general_settings = gen("General Settings");
|
|
|
|
var torrent_settings = gen("Bit-Torrent Settings");
|
|
|
|
|
|
|
|
getActiveSettings(gid, function(sets) {
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var set = sets[i];
|
|
|
|
if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) {
|
|
|
|
torrent_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
general_settings.values.push(set);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var templ = $('#download_settings_template').text();
|
|
|
|
var item = Mustache.render(templ, {
|
|
|
|
settings_name: settings_name,
|
|
|
|
gid: gid,
|
|
|
|
settings: [
|
|
|
|
general_settings,
|
|
|
|
torrent_settings
|
|
|
|
]
|
|
|
|
});
|
|
|
|
$('#download_settings_modal').html(item);
|
|
|
|
modals.download_settings_modal.modal('show');
|
|
|
|
$("#save_download_settings").one('click',function() {
|
|
|
|
var settings = {};
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var elem = $("#download_settings_" + sets[i].name);
|
|
|
|
if(sets[i].value) {
|
|
|
|
if(elem.val() !== sets[i].value) {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(elem.val() !== "no_val" && elem.val() !== "") {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$.isEmptyObject(settings)) {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'changeOption',
|
|
|
|
params: [gid, settings],
|
|
|
|
success: function(data) {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.active-download .download_pause').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.active-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'forcePause',
|
|
|
|
params: [gid],
|
|
|
|
success: function() {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error pausing active download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.active-download .torrent_info').unbind('click').click(function() {
|
|
|
|
var info_name = $(this).parents('.active-download').attr('data-settingsName');
|
|
|
|
var gid = $(this).parents('.active-download').attr('data-gid');
|
2012-08-04 22:08:08 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'getPeers',
|
|
|
|
params: [gid],
|
|
|
|
success: function(data) {
|
|
|
|
var peers = data.result.map(function(e) {
|
|
|
|
e.downloadSpeed = changeLength(e.downloadSpeed, "B/s");
|
|
|
|
e.uploadSpeed = changeLength(e.uploadSpeed, "B/s");
|
|
|
|
return e;
|
|
|
|
});
|
|
|
|
var download = d_files.active.filter(function(d) {
|
|
|
|
d.gid == gid
|
|
|
|
})[1];
|
|
|
|
var templ = $('#torrent_info_template').text();
|
|
|
|
var item = Mustache.render(templ, {
|
|
|
|
info_name: info_name,
|
|
|
|
gid: gid,
|
|
|
|
peers: peers
|
|
|
|
});
|
|
|
|
$('#torrent_info_modal').html(item);
|
|
|
|
modals.torrent_info_modal.modal('show');
|
|
|
|
console.log($('#torrent_info_modal'));
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error pausing active download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.active-download .download_remove').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.active-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'remove',
|
|
|
|
params: [gid],
|
|
|
|
success: function() {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error removing active download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function updateWaitingDownloads(data) {
|
|
|
|
refreshDownloadTemplates('waiting', data);
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.waiting-download .download_settings').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.waiting-download').attr('data-gid');
|
|
|
|
var settings_name = $(this).parents('.waiting-download').attr('data-settingsName');
|
2012-08-01 12:44:20 +02:00
|
|
|
var gen = function(name) {
|
|
|
|
return { name: name, values: [] };
|
|
|
|
};
|
|
|
|
var general_settings = gen("General Settings");
|
|
|
|
var torrent_settings = gen("Bit-Torrent Settings");
|
|
|
|
var ftp_settings = gen("FTP Settings");
|
|
|
|
var http_settings = gen("HTTP(S) Settings");
|
|
|
|
var metalink_settings = gen("Metalink Settings");
|
|
|
|
|
|
|
|
getWaitingSettings(gid, function(sets) {
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var set = sets[i];
|
|
|
|
if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) {
|
|
|
|
torrent_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("metalink") !== -1) {
|
|
|
|
metalink_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("http") !== -1) {
|
|
|
|
http_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else if(set.name.indexOf("ftp") !== -1) {
|
|
|
|
ftp_settings.values.push(set);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
general_settings.values.push(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
var templ = $('#download_settings_template').text();
|
|
|
|
var item = Mustache.render(templ, {
|
|
|
|
settings_name: settings_name,
|
|
|
|
gid: gid,
|
|
|
|
settings: [
|
|
|
|
general_settings,
|
|
|
|
http_settings,
|
|
|
|
ftp_settings,
|
|
|
|
torrent_settings,
|
|
|
|
metalink_settings
|
|
|
|
]
|
|
|
|
});
|
|
|
|
$('#download_settings_modal').html(item);
|
|
|
|
modals.download_settings_modal.modal('show');
|
|
|
|
$("#save_download_settings").one('click',function() {
|
|
|
|
var settings = {};
|
|
|
|
for(var i = 0; i < sets.length; i++) {
|
|
|
|
var elem = $("#download_settings_" + sets[i].name);
|
|
|
|
if(sets[i].value) {
|
|
|
|
if(elem.val() !== sets[i].value) {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(elem.val() !== "no_val" && elem.val() !== "") {
|
|
|
|
settings[sets[i].name] = elem.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$.isEmptyObject(settings)) {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'changeOption',
|
|
|
|
params: [gid, settings],
|
|
|
|
success: function(data) {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clear_dialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.waiting-download .download_play').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.waiting-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'unpause',
|
|
|
|
params: [gid],
|
|
|
|
success: function(data) {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error playing waiting download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.waiting-download .download_remove').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.waiting-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'remove',
|
|
|
|
params: [gid],
|
|
|
|
success: function() {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error removing waiting download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateStoppedDownloads(data) {
|
|
|
|
refreshDownloadTemplates('stopped', data);
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.stopped-download .download_remove').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.stopped-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'removeDownloadResult',
|
|
|
|
params: [gid],
|
|
|
|
success: function() {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error removing stopped download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-01-15 09:24:09 +01:00
|
|
|
$('.stopped-download .download_restart').unbind('click').click(function() {
|
|
|
|
var gid = $(this).parents('.stopped-download').attr('data-gid');
|
2012-08-01 12:44:20 +02:00
|
|
|
var files;
|
|
|
|
var uris = [];
|
|
|
|
for(var i = 0; i < d_files.stopped.length; i++) {
|
|
|
|
if(d_files.stopped[i].gid === gid) {
|
|
|
|
files = d_files.stopped[i].files;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(var i = 0; i < files.length; i++) {
|
|
|
|
var tmp_uris = [];
|
|
|
|
for(var j = 0; j < files[i].uris.length; j++) {
|
|
|
|
tmp_uris.push(files[i].uris[j].uri);
|
|
|
|
}
|
|
|
|
uris.push(tmp_uris);
|
|
|
|
}
|
|
|
|
addDownload(uris);
|
|
|
|
aria_syscall({
|
|
|
|
func: 'removeDownloadResult',
|
|
|
|
params: [gid],
|
|
|
|
success: function() {
|
|
|
|
update_ui();
|
|
|
|
},
|
|
|
|
error: function(err) {
|
|
|
|
console.log("error removing stopped download!!!");
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mergeDownloads(data) {
|
|
|
|
d_files.active = data[0][0];
|
|
|
|
d_files.waiting = data[1][0];
|
|
|
|
d_files.stopped = data[2][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateDownloads() {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'system.multicall',
|
|
|
|
params:[[{
|
|
|
|
methodName: 'aria2.tellActive'
|
|
|
|
}, {
|
|
|
|
methodName: 'aria2.tellWaiting',
|
|
|
|
params: [0,100]
|
|
|
|
}, {
|
|
|
|
methodName: 'aria2.tellStopped',
|
|
|
|
params: [0, 100]
|
|
|
|
}, {
|
|
|
|
methodName: "aria2.getGlobalStat"
|
|
|
|
}]],
|
|
|
|
success: function(data) {
|
|
|
|
mergeDownloads(data.result);
|
|
|
|
updateStoppedDownloads(d_files.stopped);
|
2012-08-01 15:06:25 +02:00
|
|
|
updateWaitingDownloads(d_files.waiting);
|
|
|
|
updateActiveDownloads(d_files.active);
|
2012-08-01 12:44:20 +02:00
|
|
|
updateGlobalStatistics(data.result[3][0]);
|
|
|
|
},
|
|
|
|
error: function() {
|
2012-10-02 20:06:37 +02:00
|
|
|
server_conf.dirty = true;
|
2012-08-01 12:44:20 +02:00
|
|
|
modals.err_connect.modal('show');
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
2012-10-30 04:34:14 +01:00
|
|
|
function calculateProg() {
|
|
|
|
var total = 0, done = 0;
|
|
|
|
_.forEach(d_files.active, function(d) {
|
|
|
|
total += d.totalLength;
|
|
|
|
done += d.completedLength;
|
|
|
|
});
|
|
|
|
return 100 * (done / total);
|
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
function updateGlobalStatistics(data) {
|
2012-10-04 18:26:59 +02:00
|
|
|
var title = "aria2 Web Client";
|
|
|
|
if (data.uploadSpeed > 0 || data.downloadSpeed > 0) {
|
|
|
|
title = "- " + title;
|
|
|
|
if (data.uploadSpeed > 0) {
|
2012-10-30 04:34:14 +01:00
|
|
|
title = "↑" + changeLength(data.uploadSpeed, "B/s") + " " + title;
|
2012-10-04 18:26:59 +02:00
|
|
|
}
|
|
|
|
if (data.downloadSpeed > 0) {
|
2012-10-30 04:34:14 +01:00
|
|
|
title = "↓" + changeLength(data.downloadSpeed, "B/s") + " " + title;
|
2012-10-04 18:26:59 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-30 04:34:14 +01:00
|
|
|
//title = '(' + calculateProg().toFixed(2) + '%) ' + title;
|
|
|
|
Piecon.setProgress(calculateProg());
|
2012-10-04 18:26:59 +02:00
|
|
|
document.title = title;
|
2012-08-01 12:44:20 +02:00
|
|
|
data.downloadSpeed = changeLength(data.downloadSpeed, "B/s");
|
|
|
|
data.uploadSpeed = changeLength(data.uploadSpeed, "B/s");
|
|
|
|
for(var i in data) {
|
|
|
|
$('.stat_' + i).text(data[i]);
|
|
|
|
}
|
2012-08-04 20:37:25 +02:00
|
|
|
if (globalGraphData) {
|
2012-08-04 22:08:08 +02:00
|
|
|
globalGraphData.addDown(parseFloat(data.downloadSpeed));
|
|
|
|
globalGraphData.addUp(parseFloat(data.uploadSpeed));
|
2012-08-04 20:37:25 +02:00
|
|
|
globalGraphData.plot.setData([{
|
|
|
|
label: "Download Speed",
|
|
|
|
data: globalGraphData.downSpeed,
|
|
|
|
color: "#ff0000",
|
|
|
|
lines: { show: true }
|
|
|
|
}, {
|
|
|
|
label: "Upload Speed",
|
|
|
|
data: globalGraphData.upSpeed,
|
|
|
|
color: "#00ff00",
|
|
|
|
lines: { show: true }
|
|
|
|
}]);
|
2012-12-26 11:57:11 +01:00
|
|
|
globalGraphData.plot.resize();
|
2012-08-04 20:37:25 +02:00
|
|
|
globalGraphData.plot.setupGrid();
|
|
|
|
globalGraphData.plot.draw();
|
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
function custom_global_statistics() {
|
|
|
|
var tmpl = $('#global_statistics_template').text();
|
|
|
|
modals.global_statistics_modal.modal('show');
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_about() {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'getVersion',
|
|
|
|
success: function(data) {
|
|
|
|
$('.about_aria_version').text(data.result.version);
|
|
|
|
$('.about_webclient_version').text('beta testing');
|
|
|
|
modals.about_modal.modal('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function force_pause_all() {
|
|
|
|
aria_syscall({
|
|
|
|
func: 'forcePauseAll',
|
|
|
|
success: update_ui
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-12-31 13:18:12 +01:00
|
|
|
function force_remove_all() {
|
2012-08-01 12:44:20 +02:00
|
|
|
var remove_params = [];
|
|
|
|
var func = function(downs) {
|
|
|
|
for(var i = 0; i < downs.length; i++) {
|
|
|
|
remove_params.push({
|
|
|
|
methodName: 'aria2.remove',
|
|
|
|
params: [downs[i].gid]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func(d_files.active);
|
|
|
|
func(d_files.waiting);
|
2012-12-31 13:18:12 +01:00
|
|
|
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
|
|
|
func: 'system.multicall',
|
|
|
|
params:[remove_params],
|
2012-12-31 13:18:12 +01:00
|
|
|
success: purge_all
|
2012-08-01 12:44:20 +02:00
|
|
|
}, true);
|
|
|
|
|
2012-12-31 13:18:12 +01:00
|
|
|
}
|
2012-08-01 12:44:20 +02:00
|
|
|
|
2012-12-31 13:18:12 +01:00
|
|
|
function purge_all() {
|
2012-08-01 12:44:20 +02:00
|
|
|
aria_syscall({
|
2012-12-31 13:18:12 +01:00
|
|
|
func: "purgeDownloadResult",
|
|
|
|
success: update_ui
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function resume_paused() {
|
|
|
|
aria_syscall({
|
|
|
|
func: "unpauseAll",
|
|
|
|
success: update_ui
|
|
|
|
});
|
2012-08-01 12:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_torrent() {
|
|
|
|
var file_node = $('#input_torrent')[0];
|
|
|
|
var files = file_node.files;
|
|
|
|
if (files.length) {
|
|
|
|
for (var i = 0, f; f = files[i]; i++) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var txt = e.target.result;
|
|
|
|
txt = txt.split(',')[1];
|
|
|
|
aria_syscall({
|
|
|
|
func: 'addTorrent',
|
|
|
|
params: [txt],
|
|
|
|
success: function() {
|
|
|
|
clear_dialogs();
|
|
|
|
update_ui();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
reader.onerror = function(e) {
|
|
|
|
alert('error reading torrent, your browser policy does not allow to read local files, please change to firefox');
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert("please select a torrent first!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function add_metalink() {
|
|
|
|
var file_node = $('#input_metalink')[0];
|
|
|
|
var files = file_node.files;
|
|
|
|
if (files.length) {
|
|
|
|
for (var i = 0, f; f = files[i]; i++) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var txt = e.target.result;
|
|
|
|
txt = txt.split(',')[1];
|
|
|
|
aria_syscall({
|
|
|
|
func: 'addMetalink',
|
|
|
|
params: [txt],
|
|
|
|
success: function() {
|
|
|
|
clear_dialogs();
|
|
|
|
update_ui();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
reader.onerror = function(e) {
|
|
|
|
alert('error reading metalink, your browser policy does not allow to read local files, please change to firefox');
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(f);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert("please select a metalink first!");
|
|
|
|
}
|
|
|
|
}
|