fix sometimes file name is empty

This commit is contained in:
MaysWind 2016-06-23 22:45:55 +08:00
parent de4bebf9ce
commit c0946491b9

View file

@ -2,9 +2,15 @@
'use strict'; 'use strict';
angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'aria2RpcService', 'ariaNgCommonService', function ($q, $translate, aria2RpcService, ariaNgCommonService) { angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'aria2RpcService', 'ariaNgCommonService', function ($q, $translate, aria2RpcService, ariaNgCommonService) {
var getFileNameFromPath = function (path) { var getFileName = function (file) {
if (!path) { if (!file) {
return path; return '';
}
var path = file.path;
if (!path && file.uris && file.uris.length > 0) {
path = file.uris[0].uri;
} }
var index = path.lastIndexOf('/'); var index = path.lastIndexOf('/');
@ -32,12 +38,8 @@
taskName = task.bittorrent.info.name; taskName = task.bittorrent.info.name;
} }
if (!taskName && task.files && task.files.length >= 1) { if (!taskName && task.files && task.files.length > 0) {
taskName = getFileNameFromPath(task.files[0].path); taskName = getFileName(task.files[0]);
}
if (!taskName && task.files && task.files.length >= 1 && task.files[0].uris && task.files[0].uris.length >= 1) {
taskName = getFileNameFromPath(task.files[0].uris[0].uri);
} }
if (!taskName) { if (!taskName) {
@ -77,7 +79,7 @@
if (task.files) { if (task.files) {
for (var i = 0; i < task.files.length; i++) { for (var i = 0; i < task.files.length; i++) {
var file = task.files[i]; var file = task.files[i];
file.fileName = getFileNameFromPath(file.path); file.fileName = getFileName(file);
file.length = parseInt(file.length); file.length = parseInt(file.length);
file.selected = (file.selected == 'true'); file.selected = (file.selected == 'true');
file.completedLength = parseInt(file.completedLength); file.completedLength = parseInt(file.completedLength);