Skip to content

A full-featured download manager.

fix: split & max-connection-per-server failed #270

Dr_rOot9d17b3e9b2b0
diff --git a/src/main/core/ConfigManager.js b/src/main/core/ConfigManager.js
index fa762e49..73e9194a 100644
--- a/src/main/core/ConfigManager.js
+++ b/src/main/core/ConfigManager.js
@@ -69,7 +69,7 @@ export default class ConfigManager {
'rpc-secret': EMPTY_STRING,
'seed-ratio': 1,
'seed-time': 60,
- 'split': 128,
+ 'split': getMaxConnectionPerServer(),
'user-agent': 'Transmission/2.94'
}
/* eslint-enable quote-props */
diff --git a/src/renderer/api/Api.js b/src/renderer/api/Api.js
index 508dd132..566440a9 100644
--- a/src/renderer/api/Api.js
+++ b/src/renderer/api/Api.js
@@ -1,6 +1,6 @@
import { ipcRenderer, remote } from 'electron'
import is from 'electron-is'
-import { isEmpty } from 'lodash'
+import { isEmpty, clone } from 'lodash'
import Aria2 from 'aria2'
import {
separateConfig,
@@ -18,13 +18,14 @@ export default class Api {
constructor (options = {}) {
this.options = options
- this.client = null
this.init()
}
init () {
- this.loadConfig()
- this.initClient()
+ this.config = this.loadConfig()
+
+ this.client = this.initClient()
+ this.client.open()
}
loadConfigFromLocalStorage () {
@@ -47,7 +48,7 @@ export default class Api {
: this.loadConfigFromLocalStorage()
result = changeKeysToCamelCase(result)
- this.config = result
+ return result
}
initClient () {
@@ -56,12 +57,11 @@ export default class Api {
rpcSecret: secret
} = this.config
const host = ENGINE_RPC_HOST
- this.client = new Aria2({
+ return new Aria2({
host,
port,
secret
})
- this.client.open()
}
closeClient () {
@@ -76,7 +76,7 @@ export default class Api {
fetchPreference () {
return new Promise((resolve) => {
- this.loadConfig()
+ this.config = this.loadConfig()
resolve(this.config)
})
}
@@ -160,11 +160,10 @@ export default class Api {
}
changeOption (params = {}) {
- let { gid, options = {} } = params
- options = formatOptionsForEngine(options)
+ const { gid, options = {} } = params
- const kebabOptions = changeKeysToKebabCase(options)
- const args = compactUndefined([gid, kebabOptions])
+ const engineOptions = formatOptionsForEngine(options)
+ const args = compactUndefined([gid, engineOptions])
return this.client.call('changeOption', ...args)
}
@@ -180,11 +179,11 @@ export default class Api {
options
} = params
const tasks = uris.map((uri, index) => {
- const kebabOptions = changeKeysToKebabCase(options)
+ const engineOptions = formatOptionsForEngine(options)
if (outs && outs[index]) {
- kebabOptions.out = outs[index]
+ engineOptions.out = outs[index]
}
- const args = compactUndefined([[uri], kebabOptions])
+ const args = compactUndefined([[uri], engineOptions])
return ['aria2.addUri', ...args]
})
return this.client.multicall(tasks)
@@ -195,8 +194,8 @@ export default class Api {
torrent,
options
} = params
- const kebabOptions = changeKeysToKebabCase(options)
- const args = compactUndefined([torrent, [], kebabOptions])
+ const engineOptions = formatOptionsForEngine(options)
+ const args = compactUndefined([torrent, [], engineOptions])
return this.client.call('addTorrent', ...args)
}
@@ -205,8 +204,8 @@ export default class Api {
metalink,
options
} = params
- const kebabOptions = changeKeysToKebabCase(options)
- const args = compactUndefined([metalink, kebabOptions])
+ const engineOptions = formatOptionsForEngine(options)
+ const args = compactUndefined([metalink, engineOptions])
return this.client.call('addMetalink', ...args)
}
@@ -328,8 +327,8 @@ export default class Api {
options = formatOptionsForEngine(options)
const data = gids.map((gid, index) => {
- const kebabOptions = changeKeysToKebabCase(options)
- const args = compactUndefined([gid, kebabOptions])
+ const _options = clone(options)
+ const args = compactUndefined([gid, _options])
return [method, ...args]
})
return this.client.multicall(data)
diff --git a/src/renderer/components/Task/AddTask.vue b/src/renderer/components/Task/AddTask.vue
index 3e667036..d9316015 100644
--- a/src/renderer/components/Task/AddTask.vue
+++ b/src/renderer/components/Task/AddTask.vue
@@ -49,7 +49,7 @@
:label-width="formLabelWidth"
>
<el-input-number
- v-model="form.maxConnectionPerServer"
+ v-model="form.split"
controls-position="right"
:min="1"
:max="config.engineMaxConnectionPerServer"
@@ -185,7 +185,8 @@
dir,
engineMaxConnectionPerServer,
maxConnectionPerServer,
- newTaskShowDownloading
+ newTaskShowDownloading,
+ split
} = state.preference.config
const result = {
allProxy,
@@ -197,6 +198,7 @@
out: '',
referer: '',
selectFile: NONE_SELECTED_FILES,
+ split,
torrent: '',
uris: addTaskUrl,
userAgent: '',
@@ -230,23 +232,23 @@
}
},
computed: {
- isRenderer () { return is.renderer() },
- isMas () { return is.mas() },
- taskType: function () {
- return this.type
- },
- downloadDir: function () {
- return prettifyDir(this.form.dir)
- },
+ isRenderer: () => is.renderer(),
+ isMas: () => is.mas(),
...mapState('app', {
taskList: state => state.taskList
}),
...mapState('preference', {
config: state => state.config
- })
+ }),
+ taskType () {
+ return this.type
+ },
+ downloadDir () {
+ return prettifyDir(this.form.dir)
+ }
},
watch: {
- taskType: function (current, previous) {
+ taskType (current, previous) {
if (this.visible && previous === ADD_TASK_TYPE.URI) {
return
}
@@ -336,7 +338,13 @@
return result
},
buildOption (type, form) {
- const { allProxy, dir, out, selectFile } = form
+ const {
+ allProxy,
+ dir,
+ out,
+ selectFile,
+ split
+ } = form
const result = {}
if (!isEmpty(allProxy)) {
@@ -351,6 +359,10 @@
result.out = out
}
+ if (split > 0) {
+ result.split = split
+ }
+
if (type === ADD_TASK_TYPE.TORRENT) {
if (
selectFile !== SELECTED_ALL_FILES &&
diff --git a/src/renderer/components/Task/Index.vue b/src/renderer/components/Task/Index.vue
index 76258908..fd5cbab6 100644
--- a/src/renderer/components/Task/Index.vue
+++ b/src/renderer/components/Task/Index.vue
@@ -261,11 +261,11 @@
this.$store.dispatch('task/getTaskOption', gid)
.then((data) => {
console.log('[Motrix] get task option:', data)
- const { dir, header, maxConnectionPerServer } = data
+ const { dir, header, split } = data
const options = {
dir,
header,
- maxConnectionPerServer,
+ split,
out: taskName
}