after uploading torrent/metalink file, task would not be created directly

This commit is contained in:
MaysWind 2017-03-28 08:35:24 +08:00
parent 75f5ea0cc9
commit e6ff345db5
5 changed files with 100 additions and 60 deletions

View file

@ -67,6 +67,9 @@ Remain Time=剩余时间
Download Speed=下载速度 Download Speed=下载速度
Upload Speed=上传速度 Upload Speed=上传速度
Links=链接 Links=链接
Torrent File=种子文件
Metalink File=Metalink 文件
File Name:=文件名:
Options=选项 Options=选项
Overview=总览 Overview=总览
Blocks=区块信息 Blocks=区块信息

View file

@ -71,6 +71,9 @@
'Download Speed': 'Download Speed', 'Download Speed': 'Download Speed',
'Upload Speed': 'Upload Speed', 'Upload Speed': 'Upload Speed',
'Links': 'Links', 'Links': 'Links',
'Torrent File': 'Torrent File',
'Metalink File': 'Metalink File',
'File Name:': 'File Name:',
'Options': 'Options', 'Options': 'Options',
'Overview': 'Overview', 'Overview': 'Overview',
'Blocks': 'Blocks', 'Blocks': 'Blocks',

View file

@ -1,12 +1,51 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'aria2SettingService', 'aria2TaskService', 'ariaNgFileService', function ($rootScope, $scope, $location, $timeout, aria2SettingService, aria2TaskService, ariaNgFileService) { angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgCommonService', 'ariaNgFileService', 'aria2SettingService', 'aria2TaskService', function ($rootScope, $scope, $location, $timeout, ariaNgCommonService, ariaNgFileService, aria2SettingService, aria2TaskService) {
var tabOrders = ['links', 'options']; var tabOrders = ['links', 'options'];
var downloadByLinks = function (pauseOnAdded, responseCallback) {
var urls = $scope.context.urls.split('\n');
var options = angular.copy($scope.context.options);
var tasks = [];
for (var i = 0; i < urls.length; i++) {
if (urls[i] === '' || urls[i].trim() === '') {
continue;
}
tasks.push({
urls: [urls[i].trim()],
options: options
});
}
return aria2TaskService.newUriTasks(tasks, pauseOnAdded, responseCallback);
};
var downloadByTorrent = function (pauseOnAdded, responseCallback) {
var task = {
content: $scope.context.uploadFile.base64Content,
options: angular.copy($scope.context.options)
};
return aria2TaskService.newTorrentTask(task, pauseOnAdded, responseCallback);
};
var downloadByMetalink = function (pauseOnAdded, responseCallback) {
var task = {
content: $scope.context.uploadFile.base64Content,
options: angular.copy($scope.context.options)
};
return aria2TaskService.newMetalinkTask(task, pauseOnAdded, responseCallback);
};
$scope.context = { $scope.context = {
currentTab: 'links', currentTab: 'links',
taskType: 'urls',
urls: '', urls: '',
uploadFile: null,
availableOptions: (function () { availableOptions: (function () {
var keys = aria2SettingService.getNewTaskOptionKeys(); var keys = aria2SettingService.getNewTaskOptionKeys();
@ -67,56 +106,27 @@
$scope.openTorrent = function () { $scope.openTorrent = function () {
ariaNgFileService.openFileContent('.torrent', function (result) { ariaNgFileService.openFileContent('.torrent', function (result) {
var task = { $scope.context.uploadFile = result;
content: result.base64Content, $scope.context.taskType = 'torrent';
options: angular.copy($scope.context.options) $scope.changeTab('options');
}; }, function (error) {
ariaNgCommonService.showError(error);
$rootScope.loadPromise = aria2TaskService.newTorrentTask(task, true, function (response) {
if (!response.success) {
return;
}
$location.path('/task/detail/' + response.data);
});
}); });
}; };
$scope.openMetalink = function () { $scope.openMetalink = function () {
ariaNgFileService.openFileContent('.meta4,.metalink', function (result) { ariaNgFileService.openFileContent('.meta4,.metalink', function (result) {
var task = { $scope.context.uploadFile = result;
content: result.base64Content, $scope.context.taskType = 'metalink';
options: angular.copy($scope.context.options) $scope.changeTab('options');
}; }, function (error) {
ariaNgCommonService.showError(error);
$rootScope.loadPromise = aria2TaskService.newMetalinkTask(task, true, function (response) {
if (!response.success) {
return;
}
$location.path('/task/detail/' + response.data);
});
}); });
}; };
$scope.startDownload = function (pauseOnAdded) { $scope.startDownload = function (pauseOnAdded) {
var urls = $scope.context.urls.split('\n'); var responseCallback = function (response) {
var options = angular.copy($scope.context.options); if (!response.hasSuccess && !response.success) {
var tasks = [];
for (var i = 0; i < urls.length; i++) {
if (urls[i] === '' || urls[i].trim() === '') {
continue;
}
tasks.push({
urls: [urls[i].trim()],
options: options
});
}
$rootScope.loadPromise = aria2TaskService.newUriTasks(tasks, pauseOnAdded, function (response) {
if (!response.hasSuccess) {
return; return;
} }
@ -125,7 +135,15 @@
} else { } else {
$location.path('/downloading'); $location.path('/downloading');
} }
}); };
if ($scope.context.taskType === 'urls') {
$rootScope.loadPromise = downloadByLinks(pauseOnAdded, responseCallback);
} else if ($scope.context.taskType === 'torrent') {
$rootScope.loadPromise = downloadByTorrent(pauseOnAdded, responseCallback);
} else if ($scope.context.taskType === 'metalink') {
$rootScope.loadPromise = downloadByMetalink(pauseOnAdded, responseCallback);
}
}; };
$scope.setOption = function (key, value, optionStatus) { $scope.setOption = function (key, value, optionStatus) {

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').factory('ariaNgFileService', ['$window', 'ariaNgCommonService', function ($window, ariaNgCommonService) { angular.module('ariaNg').factory('ariaNgFileService', ['$window', function ($window) {
var isSupportFileReader = !!$window.FileReader; var isSupportFileReader = !!$window.FileReader;
var getAllowedExtensions = function (fileFilter) { var getAllowedExtensions = function (fileFilter) {
@ -46,9 +46,12 @@
}; };
return { return {
openFileContent: function (fileFilter, callback) { openFileContent: function (fileFilter, successCallback, errorCallback) {
if (!isSupportFileReader) { if (!isSupportFileReader) {
ariaNgCommonService.showError('Your browser does not support loading file!'); if (errorCallback) {
errorCallback('Your browser does not support loading file!');
}
return; return;
} }
@ -63,7 +66,10 @@
var fileName = file.name; var fileName = file.name;
if (!checkFileExtension(fileName, allowedExtensions)) { if (!checkFileExtension(fileName, allowedExtensions)) {
ariaNgCommonService.showError('The selected file type is invalid!'); if (errorCallback) {
errorCallback('The selected file type is invalid!');
}
return; return;
} }
@ -75,13 +81,15 @@
base64Content: this.result.replace(/.*?base64,/, '') base64Content: this.result.replace(/.*?base64,/, '')
}; };
if (callback) { if (successCallback) {
callback(result); successCallback(result);
} }
}; };
reader.onerror = function () { reader.onerror = function () {
ariaNgCommonService.showError('Failed to load file!'); if (errorCallback) {
errorCallback('Failed to load file!');
}
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);

View file

@ -3,7 +3,7 @@
<div class="nav-tabs-custom"> <div class="nav-tabs-custom">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li ng-class="{'active': context.currentTab == 'links'}"> <li ng-class="{'active': context.currentTab == 'links'}">
<a class="pointer-cursor" ng-click="changeTab('links')" translate>Links</a> <a class="pointer-cursor" ng-click="changeTab('links')" ng-bind="(context.taskType === 'torrent' ? 'Torrent File' : (context.taskType === 'metalink' ? 'Metalink File' : 'Links') | translate)">Links</a>
</li> </li>
<li ng-class="{'active': context.currentTab == 'options'}"> <li ng-class="{'active': context.currentTab == 'options'}">
<a class="pointer-cursor" ng-click="changeTab('options')" translate>Options</a> <a class="pointer-cursor" ng-click="changeTab('options')" translate>Options</a>
@ -21,12 +21,12 @@
</div> </div>
<div class="btn-group"> <div class="btn-group">
<button type="submit" class="btn btn-sm" <button type="submit" class="btn btn-sm"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}" ng-class="{'btn-default': !context.uploadFile && newTaskForm.$invalid, 'btn-success': context.uploadFile || !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" translate>Start Download ng-disabled="!context.uploadFile && newTaskForm.$invalid" translate>Start Download
</button>&nbsp; </button>&nbsp;
<button type="button" class="btn btn-sm dropdown-toggle" <button type="button" class="btn btn-sm dropdown-toggle"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}" ng-class="{'btn-default': !context.uploadFile && newTaskForm.$invalid, 'btn-success': context.uploadFile || !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" data-toggle="dropdown"> ng-disabled="!context.uploadFile && newTaskForm.$invalid" data-toggle="dropdown">
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu right-align"> <ul class="dropdown-menu right-align">
@ -38,7 +38,7 @@
<div class="tab-content no-padding"> <div class="tab-content no-padding">
<div class="tab-pane" ng-class="{'active': context.currentTab == 'links'}"> <div class="tab-pane" ng-class="{'active': context.currentTab == 'links'}">
<div class="new-task-table"> <div class="new-task-table" ng-if="context.taskType === 'urls'">
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<p translate>Download Links:</p> <p translate>Download Links:</p>
@ -54,6 +54,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="new-task-table" ng-if="context.taskType === 'torrent' || context.taskType === 'metalink'">
<div class="row">
<div class="col-sm-12">
<p translate>File Name:</p>
<input class="form-control" ng-model="context.uploadFile ? context.uploadFile.fileName : ''" readonly="readonly"/>
</div>
</div>
</div>
</div> </div>
<div class="tab-pane" ng-class="{'active': context.currentTab == 'options'}"> <div class="tab-pane" ng-class="{'active': context.currentTab == 'options'}">
<div class="settings-table striped hoverable"> <div class="settings-table striped hoverable">