refactor code
This commit is contained in:
parent
f12965dd6b
commit
c30c0751ef
|
@ -21,34 +21,6 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) {
|
|
||||||
if (downloadSpeed == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return remainBytes / downloadSpeed;
|
|
||||||
};
|
|
||||||
|
|
||||||
var processDownloadTask = function (task) {
|
|
||||||
task.totalLength = parseInt(task.totalLength);
|
|
||||||
task.completedLength = parseInt(task.completedLength);
|
|
||||||
task.uploadSpeed = parseInt(task.uploadSpeed);
|
|
||||||
task.downloadSpeed = parseInt(task.downloadSpeed);
|
|
||||||
task.completePercent = (task.totalLength > 0 ? task.completedLength / task.totalLength * 100 : 0);
|
|
||||||
task.idle = task.downloadSpeed == 0;
|
|
||||||
|
|
||||||
var remainLength = task.totalLength - task.completedLength;
|
|
||||||
task.remainTime = calculateDownloadRemainTime(remainLength, task.downloadSpeed);
|
|
||||||
|
|
||||||
if (task.bittorrent && task.bittorrent.info) {
|
|
||||||
task.taskName = task.bittorrent.info.name;
|
|
||||||
} else if (task.files && task.files.length >= 1) {
|
|
||||||
task.taskName = utils.getFileNameFromPath(task.files[0].path);
|
|
||||||
} else {
|
|
||||||
task.taskName = translateFilter('Unknown');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var refreshDownloadTask = function () {
|
var refreshDownloadTask = function () {
|
||||||
var invokeMethod = null;
|
var invokeMethod = null;
|
||||||
var params = [];
|
var params = [];
|
||||||
|
@ -82,7 +54,7 @@
|
||||||
callback: function (result) {
|
callback: function (result) {
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
for (var i = 0; i < result.length; i++) {
|
for (var i = 0; i < result.length; i++) {
|
||||||
processDownloadTask(result[i]);
|
utils.processDownloadTask(result[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').factory('utils', ['$location', '$timeout', '$base64', 'SweetAlert', 'translateFilter', 'ariaNgConstants', function ($location, $timeout, $base64, SweetAlert, translateFilter, ariaNgConstants) {
|
angular.module('ariaNg').factory('utils', ['$location', '$timeout', '$base64', 'SweetAlert', 'translateFilter', 'ariaNgConstants', function ($location, $timeout, $base64, SweetAlert, translateFilter, ariaNgConstants) {
|
||||||
|
var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) {
|
||||||
|
if (downloadSpeed == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return remainBytes / downloadSpeed;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
generateUniqueId: function () {
|
generateUniqueId: function () {
|
||||||
var sourceId = ariaNgConstants.appPrefix + '_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
|
var sourceId = ariaNgConstants.appPrefix + '_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
|
||||||
|
@ -47,6 +55,31 @@
|
||||||
|
|
||||||
return path.substring(index + 1);
|
return path.substring(index + 1);
|
||||||
},
|
},
|
||||||
|
processDownloadTask: function (task) {
|
||||||
|
if (!task) {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
task.totalLength = parseInt(task.totalLength);
|
||||||
|
task.completedLength = parseInt(task.completedLength);
|
||||||
|
task.uploadSpeed = parseInt(task.uploadSpeed);
|
||||||
|
task.downloadSpeed = parseInt(task.downloadSpeed);
|
||||||
|
task.completePercent = (task.totalLength > 0 ? task.completedLength / task.totalLength * 100 : 0);
|
||||||
|
task.idle = task.downloadSpeed == 0;
|
||||||
|
|
||||||
|
var remainLength = task.totalLength - task.completedLength;
|
||||||
|
task.remainTime = calculateDownloadRemainTime(remainLength, task.downloadSpeed);
|
||||||
|
|
||||||
|
if (task.bittorrent && task.bittorrent.info) {
|
||||||
|
task.taskName = task.bittorrent.info.name;
|
||||||
|
} else if (task.files && task.files.length >= 1) {
|
||||||
|
task.taskName = this.getFileNameFromPath(task.files[0].path);
|
||||||
|
} else {
|
||||||
|
task.taskName = translateFilter('Unknown');
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
},
|
||||||
isUrlMatchUrl2: function (url, url2) {
|
isUrlMatchUrl2: function (url, url2) {
|
||||||
if (url === url2) {
|
if (url === url2) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Reference in a new issue