dsh-dl-server 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -5
- package/README.zh.md +15 -5
- package/lib/queue.js +893 -892
- package/lib/transport.js +44 -1
- package/package.json +1 -1
package/lib/transport.js
CHANGED
|
@@ -60,6 +60,30 @@ export function planTransfer(sizeBytes, cap = 16) {
|
|
|
60
60
|
const IS_WIN = process.platform === 'win32'
|
|
61
61
|
const ARIA2_BIN = IS_WIN ? 'aria2c.exe' : 'aria2c'
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The command that installs aria2 on this platform.
|
|
65
|
+
*
|
|
66
|
+
* Missing aria2 is the single most common fresh-install problem: the queue keeps
|
|
67
|
+
* working through the single-stream fallback, so nothing fails loudly and the
|
|
68
|
+
* user just concludes that DLS is slow. Every surface that mentions the fallback
|
|
69
|
+
* quotes this string, so the advice cannot drift from the detection code.
|
|
70
|
+
*
|
|
71
|
+
* @param {NodeJS.Platform} [platform]
|
|
72
|
+
* @returns {string}
|
|
73
|
+
*/
|
|
74
|
+
export function aria2InstallHint(platform = process.platform) {
|
|
75
|
+
switch (platform) {
|
|
76
|
+
case 'win32':
|
|
77
|
+
return 'winget install aria2.aria2 (或从 https://github.com/aria2/aria2/releases 下载)'
|
|
78
|
+
case 'darwin':
|
|
79
|
+
return 'brew install aria2'
|
|
80
|
+
case 'linux':
|
|
81
|
+
return 'sudo apt install aria2 (Fedora: sudo dnf install aria2,Arch: sudo pacman -S aria2)'
|
|
82
|
+
default:
|
|
83
|
+
return '安装 aria2 并把 aria2c 放进 PATH'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
63
87
|
/** Absolute locations worth checking beyond PATH. */
|
|
64
88
|
function extraCandidates() {
|
|
65
89
|
if (IS_WIN) {
|
|
@@ -196,17 +220,36 @@ export class Transport {
|
|
|
196
220
|
this.config = config
|
|
197
221
|
this.log = log
|
|
198
222
|
this.mode = 'direct'
|
|
223
|
+
this.aria2Missing = false
|
|
199
224
|
this.aria2 = undefined
|
|
200
225
|
this.rpc = undefined
|
|
201
226
|
/** @type {Map<string, { verified: string[], rejected: { url: string, reason: string }[] }>} */
|
|
202
227
|
this.mirrorReports = new Map()
|
|
203
228
|
}
|
|
204
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Channel snapshot for `download_status`. When aria2 is missing the view
|
|
232
|
+
* carries the install hint so an agent reading a slow transfer can tell the
|
|
233
|
+
* user what to fix instead of guessing.
|
|
234
|
+
*/
|
|
235
|
+
modeInfo() {
|
|
236
|
+
if (this.aria2Missing) {
|
|
237
|
+
return { mode: 'direct', aria2Missing: true, hint: aria2InstallHint() }
|
|
238
|
+
}
|
|
239
|
+
return { mode: this.mode }
|
|
240
|
+
}
|
|
241
|
+
|
|
205
242
|
/** Detect aria2 and start the daemon if possible. Never throws. */
|
|
206
243
|
async init() {
|
|
207
244
|
const binary = await findAria2(this.config.aria2Path)
|
|
208
245
|
if (!binary) {
|
|
209
|
-
this.
|
|
246
|
+
this.aria2Missing = true
|
|
247
|
+
// warn, not info: this is the difference between 136 MB/s and 13 MB/s and
|
|
248
|
+
// the fallback is silent otherwise.
|
|
249
|
+
this.log(
|
|
250
|
+
'warn',
|
|
251
|
+
`aria2c 未找到,回退到单流模式(速度约为并发的 1/10)。安装:${aria2InstallHint()}`,
|
|
252
|
+
)
|
|
210
253
|
return
|
|
211
254
|
}
|
|
212
255
|
|