support add bt/metalink task via file
This commit is contained in:
parent
a8a5461d38
commit
90a4de8a87
|
@ -301,6 +301,7 @@
|
|||
<script src="scripts/filters/taskStatus.js"></script>
|
||||
<script src="scripts/filters/volumn.js"></script>
|
||||
<script src="scripts/services/ariaNgCommonService.js"></script>
|
||||
<script src="scripts/services/ariaNgFileService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
<script src="scripts/services/ariaNgMonitorService.js"></script>
|
||||
<script src="scripts/services/aria2TaskService.js"></script>
|
||||
|
|
|
@ -82,6 +82,9 @@
|
|||
"Open Torrent File": "打开种子文件",
|
||||
"Open Metalink File": "打开 Metalink 文件",
|
||||
"Support multiple URLs, one URL per line.": "支持多个 URL 地址, 每个地址占一行.",
|
||||
"Your browser does not support loading file!": "您的浏览器不支持加载文件!",
|
||||
"The selected file type is invalid!": "选择的文件类型无效!",
|
||||
"Failed to load file!": "加载文件失败!",
|
||||
"More Options": "更多选项",
|
||||
"Language": "语言",
|
||||
"Aria2 RPC Host": "Aria2 RPC 主机",
|
||||
|
|
|
@ -86,6 +86,9 @@
|
|||
'Start Download': 'Start Download',
|
||||
'Manual Download': 'Manual Download',
|
||||
'Support multiple URLs, one URL per line.': 'Support multiple URLs, one URL per line.',
|
||||
'Your browser does not support loading file!': 'Your browser does not support loading file!',
|
||||
'The selected file type is invalid': 'The selected file type is invalid',
|
||||
'Failed to load file!': 'Failed to load file!',
|
||||
'More Options': 'More Options',
|
||||
'Language': 'Language',
|
||||
'Aria2 RPC Host': 'Aria2 RPC Host',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'aria2SettingService', 'aria2TaskService', function ($rootScope, $scope, $location, $timeout, aria2SettingService, aria2TaskService) {
|
||||
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'aria2SettingService', 'aria2TaskService', 'ariaNgFileService', function ($rootScope, $scope, $location, $timeout, aria2SettingService, aria2TaskService, ariaNgFileService) {
|
||||
var tabOrders = ['links', 'options'];
|
||||
|
||||
$scope.context = {
|
||||
|
@ -58,6 +58,40 @@
|
|||
});
|
||||
};
|
||||
|
||||
$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.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.startDownload = function (pauseOnAdded) {
|
||||
var urls = $scope.context.urls.split('\n');
|
||||
var options = angular.copy($scope.context.options);
|
||||
|
|
|
@ -186,12 +186,26 @@
|
|||
|
||||
return invokeMulti(this.addUri, contexts, context.callback);
|
||||
},
|
||||
// addTorrent: function (context) {
|
||||
// return invoke('addTorrent', context);
|
||||
// },
|
||||
// addMetalink: function (context) {
|
||||
// return invoke('addMetalink', context);
|
||||
// },
|
||||
addTorrent: function (context) {
|
||||
var content = context.task.content;
|
||||
var options = angular.copy(context.task.options);
|
||||
|
||||
if (context.pauseOnAdded) {
|
||||
options.pause = 'true';
|
||||
}
|
||||
|
||||
return invoke(buildRequestContext('addTorrent', context, content, [], options));
|
||||
},
|
||||
addMetalink: function (context) {
|
||||
var content = context.task.content;
|
||||
var options = angular.copy(context.task.options);
|
||||
|
||||
if (context.pauseOnAdded) {
|
||||
options.pause = 'true';
|
||||
}
|
||||
|
||||
return invoke(buildRequestContext('addMetalink', context, content, [], options));
|
||||
},
|
||||
remove: function (context) {
|
||||
return invoke(buildRequestContext('remove', context, context.gid));
|
||||
},
|
||||
|
|
|
@ -266,6 +266,22 @@
|
|||
callback: callback
|
||||
});
|
||||
},
|
||||
newTorrentTask: function (task, pauseOnAdded, callback, silent) {
|
||||
return aria2RpcService.addTorrent({
|
||||
task: task,
|
||||
pauseOnAdded: !!pauseOnAdded,
|
||||
silent: !!silent,
|
||||
callback: callback
|
||||
});
|
||||
},
|
||||
newMetalinkTask: function (task, pauseOnAdded, callback, silent) {
|
||||
return aria2RpcService.addMetalink({
|
||||
task: task,
|
||||
pauseOnAdded: !!pauseOnAdded,
|
||||
silent: !!silent,
|
||||
callback: callback
|
||||
});
|
||||
},
|
||||
startTasks: function (gids, callback, silent) {
|
||||
return aria2RpcService.unpauseMulti({
|
||||
gids: gids,
|
||||
|
|
92
src/scripts/services/ariaNgFileService.js
Normal file
92
src/scripts/services/ariaNgFileService.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgFileService', ['ariaNgCommonService', function (ariaNgCommonService) {
|
||||
var isSupportFileReader = !!FileReader;
|
||||
|
||||
var getAllowedExtensions = function (fileFilter) {
|
||||
var extensions = [];
|
||||
|
||||
if (!fileFilter || fileFilter.length < 1) {
|
||||
extensions.push(/.+$/);
|
||||
return extensions;
|
||||
}
|
||||
|
||||
var fileFilters = fileFilter.split(',');
|
||||
|
||||
for (var i = 0; i < fileFilters.length; i++) {
|
||||
var extension = fileFilters[i];
|
||||
|
||||
if (extension == '*.*') {
|
||||
extensions.push(/.+$/);
|
||||
continue;
|
||||
}
|
||||
|
||||
extension = extension.replace('.', '\\.');
|
||||
extension = extension + '$';
|
||||
|
||||
extensions.push(new RegExp(extension));
|
||||
}
|
||||
|
||||
return extensions;
|
||||
};
|
||||
|
||||
var checkFileExtension = function (fileName, extensions) {
|
||||
if (!extensions || extensions.length < 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < extensions.length; i++) {
|
||||
if (extensions[i].test(fileName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
openFileContent: function (fileFilter, callback) {
|
||||
if (!isSupportFileReader) {
|
||||
ariaNgCommonService.showError('Your browser does not support loading file!');
|
||||
return;
|
||||
}
|
||||
|
||||
var allowedExtensions = getAllowedExtensions(fileFilter);
|
||||
|
||||
angular.element('<input type="file" style="display: none"/>').change(function () {
|
||||
if (!this.files || this.files.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var file = this.files[0];
|
||||
var fileName = file.name;
|
||||
|
||||
if (!checkFileExtension(fileName, allowedExtensions)) {
|
||||
ariaNgCommonService.showError('The selected file type is invalid!');
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function () {
|
||||
var result = {
|
||||
fileName: fileName,
|
||||
base64Content: this.result.replace(/.*?base64,/, '')
|
||||
};
|
||||
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = function () {
|
||||
ariaNgCommonService.showError('Failed to load file!');
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
}).trigger('click');
|
||||
}
|
||||
}
|
||||
}]);
|
||||
})();
|
|
@ -28,9 +28,9 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<div class="new-task-toollink hide">
|
||||
<a class="pointer-cursor" translate>Open Torrent File</a>
|
||||
<a class="pointer-cursor" translate>Open Metalink File</a>
|
||||
<div class="new-task-toollink">
|
||||
<a class="pointer-cursor" ng-click="openTorrent()" translate>Open Torrent File</a>
|
||||
<a class="pointer-cursor" ng-click="openMetalink()" translate>Open Metalink File</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
|
|
Reference in a new issue