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

master
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=下载速度
Upload Speed=上传速度
Links=链接
Torrent File=种子文件
Metalink File=Metalink 文件
File Name:=文件名:
Options=选项
Overview=总览
Blocks=区块信息

View File

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

View File

@ -1,12 +1,51 @@
(function () {
'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 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 = {
currentTab: 'links',
taskType: 'urls',
urls: '',
uploadFile: null,
availableOptions: (function () {
var keys = aria2SettingService.getNewTaskOptionKeys();
@ -67,56 +106,27 @@
$scope.openTorrent = function () {
ariaNgFileService.openFileContent('.torrent', function (result) {
var task = {
content: result.base64Content,
options: angular.copy($scope.context.options)
};
$rootScope.loadPromise = aria2TaskService.newTorrentTask(task, true, function (response) {
if (!response.success) {
return;
}
$location.path('/task/detail/' + response.data);
});
$scope.context.uploadFile = result;
$scope.context.taskType = 'torrent';
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
});
};
$scope.openMetalink = function () {
ariaNgFileService.openFileContent('.meta4,.metalink', function (result) {
var task = {
content: result.base64Content,
options: angular.copy($scope.context.options)
};
$rootScope.loadPromise = aria2TaskService.newMetalinkTask(task, true, function (response) {
if (!response.success) {
return;
}
$location.path('/task/detail/' + response.data);
});
$scope.context.uploadFile = result;
$scope.context.taskType = 'metalink';
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
});
};
$scope.startDownload = function (pauseOnAdded) {
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
});
}
$rootScope.loadPromise = aria2TaskService.newUriTasks(tasks, pauseOnAdded, function (response) {
if (!response.hasSuccess) {
var responseCallback = function (response) {
if (!response.hasSuccess && !response.success) {
return;
}
@ -125,7 +135,15 @@
} else {
$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) {

View File

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

View File

@ -3,7 +3,7 @@
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<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 ng-class="{'active': context.currentTab == 'options'}">
<a class="pointer-cursor" ng-click="changeTab('options')" translate>Options</a>
@ -21,12 +21,12 @@
</div>
<div class="btn-group">
<button type="submit" class="btn btn-sm"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" translate>Start Download
ng-class="{'btn-default': !context.uploadFile && newTaskForm.$invalid, 'btn-success': context.uploadFile || !newTaskForm.$invalid}"
ng-disabled="!context.uploadFile && newTaskForm.$invalid" translate>Start Download
</button>&nbsp;
<button type="button" class="btn btn-sm dropdown-toggle"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" data-toggle="dropdown">
ng-class="{'btn-default': !context.uploadFile && newTaskForm.$invalid, 'btn-success': context.uploadFile || !newTaskForm.$invalid}"
ng-disabled="!context.uploadFile && newTaskForm.$invalid" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu right-align">
@ -38,15 +38,15 @@
<div class="tab-content no-padding">
<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="col-sm-12">
<p translate>Download Links:</p>
<div class="form-group has-feedback no-margin" ng-class="{ 'has-error' : newTaskForm.urls.$invalid && newTaskForm.urls.$dirty, 'has-success' : newTaskForm.urls.$valid && newTaskForm.urls.$dirty }">
<textarea name="urls" class="form-control" rows="10" autofocus="autofocus" ng-auto-focus
ng-model="context.urls" ng-required="true" ng-keydown="urlTextboxKeyDown($event)"
ng-placeholder="'Support multiple URLs, one URL per line.' | translate"
ng-pattern="/^(\n?(((http|https|ftp|ssh):\/\/.+)|(magnet:\?.+)))*$/i"></textarea>
<textarea name="urls" class="form-control" rows="10" autofocus="autofocus" ng-auto-focus
ng-model="context.urls" ng-required="true" ng-keydown="urlTextboxKeyDown($event)"
ng-placeholder="'Support multiple URLs, one URL per line.' | translate"
ng-pattern="/^(\n?(((http|https|ftp|ssh):\/\/.+)|(magnet:\?.+)))*$/i"></textarea>
<div class="form-control-icon" ng-if="newTaskForm.urls.$dirty">
<i class="fa form-control-feedback" ng-class="{'fa-check':newTaskForm.urls.$valid, 'fa-times':newTaskForm.urls.$invalid}"></i>
</div>
@ -54,6 +54,14 @@
</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 class="tab-pane" ng-class="{'active': context.currentTab == 'options'}">
<div class="settings-table striped hoverable">