diff --git a/src/index.html b/src/index.html index 30d1a56..699c485 100644 --- a/src/index.html +++ b/src/index.html @@ -360,6 +360,7 @@ + diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index 61309df..fa8be9b 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -243,6 +243,7 @@ time.minutes={{value}} 分钟 time.hour={{value}} 小时 time.hours={{value}} 小时 requires.aria2-version=需要 aria2 v{{version}} 或更高版本 +task.new.download-links=下载链接 ({{count}} 个链接): task.pieceinfo=已完成: {{completed}}, 共计: {{total}} 块 task.error-occurred=发生错误 ({{errorcode}}) settings.file-count=({{count}} 个文件) diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 8ec7105..3552ec1 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -243,6 +243,7 @@ time.minutes={{value}} 分鐘 time.hour={{value}} 小時 time.hours={{value}} 小時 requires.aria2-version=需要 aria2 v{{version}} 或更高版本 +task.new.download-links=下載鏈接 ({{count}} 个鏈接): task.pieceinfo=已完成: {{completed}}, 共計: {{total}} 塊 task.error-occurred=發生錯誤 ({{errorcode}}) settings.file-count=({{count}} 個文件) diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index fbf23fe..51f3bb1 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -246,6 +246,7 @@ 'time.hour': '{{value}} Hour', 'time.hours': '{{value}} Hours', 'requires.aria2-version': 'Requires aria2 v{{version}} or higher', + 'task.new.download-links': 'Download Links ({{count}} Links):', 'task.pieceinfo': 'Completed: {{completed}}, Total: {{total}}', 'task.error-occurred': 'Error Occurred ({{errorcode}})', 'settings.file-count': '({{count}} Files)', diff --git a/src/scripts/controllers/new.js b/src/scripts/controllers/new.js index 361601d..e979bf5 100644 --- a/src/scripts/controllers/new.js +++ b/src/scripts/controllers/new.js @@ -5,7 +5,7 @@ var tabOrders = ['links', 'options']; var downloadByLinks = function (pauseOnAdded, responseCallback) { - var urls = $scope.context.urls.split('\n'); + var urls = ariaNgCommonService.parseUrlsFromOriginInput($scope.context.urls); var options = angular.copy($scope.context.options); var tasks = []; @@ -174,6 +174,11 @@ } }; + $scope.getValidUrlsCount = function () { + var urls = ariaNgCommonService.parseUrlsFromOriginInput($scope.context.urls); + return urls ? urls.length : 0; + }; + $rootScope.loadPromise = $timeout(function () {}, 100); }]); }()); diff --git a/src/scripts/directives/validUrls.js b/src/scripts/directives/validUrls.js new file mode 100644 index 0000000..4119146 --- /dev/null +++ b/src/scripts/directives/validUrls.js @@ -0,0 +1,28 @@ +(function () { + 'use strict'; + + angular.module('ariaNg').directive('ngValidUrls', ['ariaNgCommonService', function (ariaNgCommonService) { + var DIRECTIVE_ID = 'invalidUrls'; + + return { + restrict: 'A', + require: '?ngModel', + link: function (scope, element, attrs, ngModel) { + var handleChange = function (value) { + if (angular.isUndefined(value) || value === '') { + return; + } + + var urls = ariaNgCommonService.parseUrlsFromOriginInput(value); + var valid = urls && urls.length > 0; + + ngModel.$setValidity(DIRECTIVE_ID, valid); + }; + + scope.$watch(function () { + return ngModel.$viewValue; + }, handleChange); + } + }; + }]); +}()); diff --git a/src/scripts/services/ariaNgCommonService.js b/src/scripts/services/ariaNgCommonService.js index 79463bb..5ad0186 100644 --- a/src/scripts/services/ariaNgCommonService.js +++ b/src/scripts/services/ariaNgCommonService.js @@ -58,6 +58,26 @@ return filePath.substring(filePath.lastIndexOf('.')); }, + parseUrlsFromOriginInput: function (s) { + if (!s) { + return []; + } + + var lines = s.split('\n'); + var result = []; + + for (var i = 0; i < lines.length; i++) { + var line = lines[i]; + + if (line.match(/^(http|https|ftp|sftp):\/\/.+$/)) { + result.push(line); + } else if (line.match(/^magnet:\?.+$/)) { + result.push(line); + } + } + + return result; + }, decodePercentEncodedString: function (s) { if (!s) { return s; diff --git a/src/views/new.html b/src/views/new.html index b1627d7..ebeef18 100644 --- a/src/views/new.html +++ b/src/views/new.html @@ -41,12 +41,11 @@
Download Links:
+Download Links: