Browse Source

merge AriaNg commit (https://github.com/mayswind/AriaNg/commit/52b53532ec8cd50e24e34c94ced729311fac90fa)

MaysWind 3 years ago
parent
commit
0e6488a61f

+ 1 - 0
app/index.html

@@ -408,6 +408,7 @@
 <script src="scripts/directives/pieceBar.js"></script>
 <script src="scripts/directives/pieceMap.js"></script>
 <script src="scripts/directives/chart.js"></script>
+<script src="scripts/directives/exportCommandApiDialog.js"></script>
 <script src="scripts/directives/indeterminate.js"></script>
 <script src="scripts/directives/placeholder.js"></script>
 <script src="scripts/directives/setting.js"></script>

+ 6 - 0
app/langs/zh_Hans.txt

@@ -159,6 +159,12 @@ Failed to load file!=加载文件失败!
 Download Completed=下载完成
 BT Download Completed=BT 下载完成
 Download Error=下载出错
+AriaNg Url=AriaNg 地址
+Command API Url=命令行 API 地址
+Export Command API=导出命令行 API
+Export=导出
+Copied=已复制
+Pause After Task Created=任务创建后暂停
 Check Update=检查更新
 Latest Version=最新版本
 You have installed the latest version!=您已经安装了最新的版本!

+ 6 - 0
app/langs/zh_Hant.txt

@@ -159,6 +159,12 @@ Failed to load file!=載入檔案失敗!
 Download Completed=下載完成
 BT Download Completed=BT 下載完成
 Download Error=下載出錯
+AriaNg Url=AriaNg 連結
+Command API Url=命令行 API 連結
+Export Command API=匯出命令行 API
+Export=匯出
+Copied=已複製
+Pause After Task Created=工作建立後暫停
 Check Update=檢查更新
 Latest Version=最新版本
 You have installed the latest version!=您已經安裝了最新的版本!

+ 6 - 0
app/scripts/config/defaultLanguage.js

@@ -163,6 +163,12 @@
             'Download Completed': 'Download Completed',
             'BT Download Completed': 'BT Download Completed',
             'Download Error': 'Download Error',
+            'AriaNg Url': 'AriaNg Url',
+            'Command API Url': 'Command API Url',
+            'Export Command API': 'Export Command API',
+            'Export': 'Export',
+            'Copied': 'Copied',
+            'Pause After Task Created': 'Pause After Task Created',
             'Check Update': 'Check Update',
             'Latest Version': 'Latest Version',
             'You have installed the latest version!': 'You have installed the latest version!',

+ 21 - 3
app/scripts/controllers/new.js

@@ -65,11 +65,14 @@
             return selectedFileIndex;
         };
 
-        var downloadByLinks = function (pauseOnAdded, responseCallback) {
+        var getDownloadTasksByLinks = function (options) {
             var urls = ariaNgCommonService.parseUrlsFromOriginInput($scope.context.urls);
-            var options = angular.copy($scope.context.options);
             var tasks = [];
 
+            if (!options) {
+                options = angular.copy($scope.context.options);
+            }
+
             for (var i = 0; i < urls.length; i++) {
                 if (urls[i] === '' || urls[i].trim() === '') {
                     continue;
@@ -81,6 +84,13 @@
                 });
             }
 
+            return tasks;
+        };
+
+        var downloadByLinks = function (pauseOnAdded, responseCallback) {
+            var options = angular.copy($scope.context.options);
+            var tasks = getDownloadTasksByLinks(options);
+
             saveDownloadPath(options);
 
             return aria2TaskService.newUriTasks(tasks, pauseOnAdded, responseCallback);
@@ -257,7 +267,8 @@
                 global: true,
                 http: false,
                 bittorrent: false
-            }
+            },
+            exportCommandApiOptions: null
         };
 
         if (parameters.url) {
@@ -730,6 +741,13 @@
             }
         };
 
+        $scope.showExportCommandAPIModal = function () {
+            $scope.context.exportCommandApiOptions = {
+                type: 'new-task',
+                data: getDownloadTasksByLinks()
+            };
+        };
+
         $scope.setOption = function (key, value, optionStatus) {
             if (value !== '') {
                 $scope.context.options[key] = value;

+ 9 - 1
app/scripts/controllers/settings-ariang.js

@@ -90,7 +90,8 @@
             isSupportDarkMode: ariaNgSettingService.isBrowserSupportDarkMode(),
             importSettings: null,
             exportSettings: null,
-            exportSettingsCopied: false
+            exportSettingsCopied: false,
+            exportCommandApiOptions: null
         };
 
         $scope.context.titlePreview = getFinalTitle();
@@ -433,6 +434,13 @@
             });
         };
 
+        $scope.showExportCommandAPIModal = function (setting) {
+            $scope.context.exportCommandApiOptions = {
+                type: 'setting',
+                data: setting
+            };
+        };
+
         $scope.setDefaultRpcSetting = function (setting) {
             if (setting.isDefault) {
                 return;

+ 110 - 0
app/scripts/directives/exportCommandApiDialog.js

@@ -0,0 +1,110 @@
+(function () {
+    'use strict';
+
+    angular.module('ariaNg').directive('ngExportCommandApiDialog', ['clipboard', 'ariaNgCommonService', function (clipboard, ariaNgCommonService) {
+        return {
+            restrict: 'E',
+            templateUrl: 'views/export-command-api-dialog.html',
+            replace: true,
+            scope: {
+                options: '='
+            },
+            link: function (scope, element, attrs) {
+                scope.context = {
+                    trueFalseOptions: [{name: 'Enabled', value: true}, {name: 'Disabled', value: false}],
+                    baseUrl: 'http://ariang.mayswind.net/latest',
+                    commandAPIUrl: null,
+                    pauseOnAdded: true,
+                    isCopied: false
+                };
+
+                var getNewTaskCommandAPIUrl = function (task) {
+                    var commandAPIUrl = scope.context.baseUrl + '#!/new/task?' +
+                        'url=' + ariaNgCommonService.base64UrlEncode(task.urls[0]);
+
+                    if (scope.context.pauseOnAdded) {
+                        commandAPIUrl += '&pause=true';
+                    }
+
+                    if (task.options) {
+                        for (var key in task.options) {
+                            if (!task.options.hasOwnProperty(key)) {
+                                continue;
+                            }
+
+                            commandAPIUrl += '&' + key + '=' + task.options[key];
+                        }
+                    }
+
+                    return commandAPIUrl;
+                };
+
+                var getNewTasksCommandAPIUrl = function (tasks) {
+                    var commandAPIUrls = '';
+
+                    for (var i = 0; i < tasks.length; i++) {
+                        if (i > 0) {
+                            commandAPIUrls += '\n';
+                        }
+
+                        commandAPIUrls += getNewTaskCommandAPIUrl(tasks[i]);
+                    }
+
+                    return commandAPIUrls;
+                };
+
+                var getSettingCommandAPIUrl = function (setting) {
+                    var commandAPIUrl = scope.context.baseUrl + '#!/settings/rpc/set?' +
+                        'protocol=' + setting.protocol +
+                        '&host=' + setting.rpcHost +
+                        '&port=' + setting.rpcPort +
+                        '&interface=' + setting.rpcInterface;
+
+                    if (setting.secret) {
+                        commandAPIUrl += '&secret=' + ariaNgCommonService.base64UrlEncode(setting.secret);
+                    }
+
+                    return commandAPIUrl;
+                };
+
+                scope.generateCommandAPIUrl = function () {
+                    if (!scope.options) {
+                        return;
+                    }
+
+                    if (scope.options.type === 'new-task') {
+                        scope.context.commandAPIUrl = getNewTasksCommandAPIUrl(scope.options.data);
+                    } else if (scope.options.type === 'setting') {
+                        scope.context.commandAPIUrl = getSettingCommandAPIUrl(scope.options.data);
+                    }
+
+                    scope.context.isCopied = false;
+                };
+
+                scope.copyCommandAPI = function () {
+                    clipboard.copyText(scope.context.commandAPIUrl, {
+                        container: angular.element('#exportCommandAPIModal')[0]
+                    });
+                    scope.context.isCopied = true;
+                };
+
+                angular.element('#exportCommandAPIModal').on('hidden.bs.modal', function () {
+                    scope.$apply(function () {
+                        scope.options = null;
+                        scope.context.commandAPIUrl = null;
+                        scope.context.isCopied = false;
+                    });
+                });
+
+                scope.$watch('options', function (options) {
+                    if (options) {
+                        scope.generateCommandAPIUrl();
+                        scope.context.isCopied = false;
+
+                        angular.element('#exportCommandAPIModal').modal('show');
+                    }
+                }, true);
+            }
+        };
+    }]);
+}());

+ 10 - 1
app/scripts/services/ariaNgCommonService.js

@@ -1,7 +1,7 @@
 (function () {
     'use strict';
 
-    angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', 'ariaNgConstants', 'ariaNgLocalizationService', function ($location, $timeout, base64, moment, SweetAlert, ariaNgConstants, ariaNgLocalizationService) {
+    angular.module('ariaNg').factory('ariaNgCommonService', ['$window', '$location', '$timeout', 'base64', 'moment', 'SweetAlert', 'ariaNgConstants', 'ariaNgLocalizationService', function ($window, $location, $timeout, base64, moment, SweetAlert, ariaNgConstants, ariaNgLocalizationService) {
         var getTimeOption = function (time) {
             var name = '';
             var value = time;
@@ -70,12 +70,21 @@
         }
 
         return {
+            getFullPageUrl: function () {
+                return $window.location.protocol + '//'
+                    + $window.location.host
+                    + $window.location.pathname
+                    + ($window.location.search ? $window.location.search : '');
+            },
             base64Encode: function (value) {
                 return base64.encode(value);
             },
             base64Decode: function (value) {
                 return base64.decode(value);
             },
+            base64UrlEncode: function (value) {
+                return base64.urlencode(value);
+            },
             base64UrlDecode: function (value) {
                 return base64.urldecode(value);
             },

+ 54 - 0
app/views/export-command-api-dialog.html

@@ -0,0 +1,54 @@
+<div id="exportCommandAPIModal" class="modal fade" tabindex="-1" role="dialog">
+    <div class="modal-dialog modal-lg" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title">
+                    <span translate>Export Command API</span>
+                </h4>
+            </div>
+            <div class="modal-body no-padding">
+                <div class="settings-table striped">
+                    <div class="row">
+                        <div class="setting-key setting-key-without-desc col-sm-2">
+                            <span translate>AriaNg Url</span>
+                        </div>
+                        <div class="setting-value col-sm-10">
+                            <input class="form-control" type="text" ng-model="context.baseUrl"
+                                   ng-change="generateCommandAPIUrl()"/>
+                        </div>
+                    </div>
+                    <div class="row" ng-if="options.type === 'new-task'">
+                        <div class="setting-key setting-key-without-desc col-sm-2">
+                            <span translate>Pause After Task Created</span>
+                        </div>
+                        <div class="setting-value col-sm-10">
+                            <select class="form-control" style="width: 100%;"
+                                    ng-model="context.pauseOnAdded"
+                                    ng-change="generateCommandAPIUrl()"
+                                    ng-options="option.value as (option.name | translate) for option in context.trueFalseOptions">
+                            </select>
+                        </div>
+                    </div>
+                    <div class="row">
+                        <div class="setting-key setting-key-without-desc col-sm-2">
+                            <span translate>Command API Url</span>
+                            <span class="description">
+                                <a class="pointer-cursor" title="{{'Copy' | translate}}" ng-click="copyCommandAPI()">
+                                    <i class="icon-primary fa fa-copy"></i>
+                                </a>
+                                <span class="label label-default fade-in" ng-if="context.isCopied" translate>Copied</span>
+                            </span>
+                        </div>
+                        <div class="setting-value col-sm-10">
+                            <textarea class="form-control" ng-model="context.commandAPIUrl" rows="4" readonly="readonly"></textarea>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal" translate>Cancel</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 3 - 0
app/views/new.html

@@ -33,6 +33,8 @@
                         </button>
                         <ul class="dropdown-menu right-align">
                             <li><a class="pointer-cursor" ng-click="startDownload(true)" translate>Download Later</a></li>
+                            <li ng-if="context.taskType === 'urls'" class="divider"></li>
+                            <li ng-if="context.taskType === 'urls'"><a class="pointer-cursor" ng-click="showExportCommandAPIModal()" translate>Export Command API</a></li>
                         </ul>
                     </div>
                 </li>
@@ -302,5 +304,6 @@
                 </div>
             </div>
         </div>
+        <ng-export-command-api-dialog options="context.exportCommandApiOptions"></ng-export-command-api-dialog>
     </form>
 </section>

+ 11 - 0
app/views/settings-ariang.html

@@ -475,6 +475,16 @@
                             </div>
                         </div>
                     </div>
+                    <div class="row">
+                        <div class="setting-key setting-key-without-desc col-sm-4">
+                            <span translate>Export Command API</span>
+                        </div>
+                        <div class="setting-value col-sm-8">
+                            <button class="btn btn-sm btn-default" ng-click="showExportCommandAPIModal(setting)">
+                                <span translate>Export</span>
+                            </button>
+                        </div>
+                    </div>
                     <div class="row tip no-background no-hover">
                         <span class="asterisk">*</span>
                         <span translate>Changes to the settings take effect after refreshing page.</span>
@@ -546,4 +556,5 @@
             </div>
         </div>
     </div>
+    <ng-export-command-api-dialog options="context.exportCommandApiOptions"></ng-export-command-api-dialog>
 </section>