Browse Source

merge AriaNg commits (https://github.com/mayswind/AriaNg/commit/dac0f2925592257cc6e42006e4d98fbd733fbc00 https://github.com/mayswind/AriaNg/commit/a31c0551670d16f19c59ea7b5b4576a49559399b)

MaysWind 5 years ago
parent
commit
220bb180f6
2 changed files with 19 additions and 3 deletions
  1. 5 0
      app/scripts/config/aria2Options.js
  2. 14 3
      app/scripts/services/aria2TaskService.js

+ 5 - 0
app/scripts/config/aria2Options.js

@@ -17,6 +17,11 @@
         //     [max: 0,] //SUPPORT 'integer', 'float'
         //     [pattern: '']
         // }
+        'gid': {
+            type: 'string',
+            readonly: true,
+            required: true
+        },
         'dir': {
             type: 'string',
             required: true

+ 14 - 3
app/scripts/services/aria2TaskService.js

@@ -9,9 +9,11 @@
             }
 
             var path = file.path;
+            var needUrlDecode = false;
 
             if (!path && file.uris && file.uris.length > 0) {
                 path = file.uris[0].uri;
+                needUrlDecode = true;
             }
 
             var index = path.lastIndexOf('/');
@@ -22,12 +24,21 @@
 
             var fileNameAndQueryString = path.substring(index + 1);
             var queryStringStartPos = fileNameAndQueryString.indexOf('?');
+            var fileName = fileNameAndQueryString;
 
-            if (queryStringStartPos <= 0) {
-                return fileNameAndQueryString;
+            if (queryStringStartPos > 0) {
+                fileName = fileNameAndQueryString.substring(0, queryStringStartPos);
             }
 
-            return fileNameAndQueryString.substring(0, queryStringStartPos);
+            if (needUrlDecode) {
+                try {
+                    fileName = decodeURI(fileName);
+                } catch (ex) {
+                    ariaNgLogService.warn('[aria2TaskService.getFileName] failed to url decode file name, original file name: ' + fileName, ex);
+                }
+            }
+
+            return fileName;
         };
 
         var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) {