justget 0.1.2
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/LICENSE +21 -0
- package/README.md +263 -0
- package/dist/chunks/strategy.d.ts +39 -0
- package/dist/chunks/strategy.d.ts.map +1 -0
- package/dist/chunks/strategy.js +97 -0
- package/dist/chunks/strategy.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +117 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +71 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +158 -0
- package/dist/config.js.map +1 -0
- package/dist/core/downloader.d.ts +22 -0
- package/dist/core/downloader.d.ts.map +1 -0
- package/dist/core/downloader.js +555 -0
- package/dist/core/downloader.js.map +1 -0
- package/dist/core/http.d.ts +51 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +186 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/temp.d.ts +47 -0
- package/dist/core/temp.d.ts.map +1 -0
- package/dist/core/temp.js +137 -0
- package/dist/core/temp.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/speed/ewma.d.ts +38 -0
- package/dist/speed/ewma.d.ts.map +1 -0
- package/dist/speed/ewma.js +87 -0
- package/dist/speed/ewma.js.map +1 -0
- package/dist/speed/speed-monitor.d.ts +56 -0
- package/dist/speed/speed-monitor.d.ts.map +1 -0
- package/dist/speed/speed-monitor.js +94 -0
- package/dist/speed/speed-monitor.js.map +1 -0
- package/dist/types.d.ts +236 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/hash.d.ts +38 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +89 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/validator.d.ts +21 -0
- package/dist/utils/validator.d.ts.map +1 -0
- package/dist/utils/validator.js +72 -0
- package/dist/utils/validator.js.map +1 -0
- package/package.json +70 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JustGet 默认配置
|
|
3
|
+
* Default configuration for JustGet downloader
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Default download configuration
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_CONFIG = {
|
|
9
|
+
primaryWarmupTime: 5000, // 5 seconds
|
|
10
|
+
speedThreshold: 512000, // 500 KB/s (below this, consider mirrors)
|
|
11
|
+
fastPrimaryThreshold: 2048000, // 2 MB/s (above this, don't start mirrors)
|
|
12
|
+
sizeThreshold: 52428800, // 50 MB
|
|
13
|
+
minReplaceTime: 30000, // 30 seconds
|
|
14
|
+
replaceCheckInterval: 10000, // 10 seconds
|
|
15
|
+
chunks: 'auto',
|
|
16
|
+
chunkSize: 'auto',
|
|
17
|
+
minChunkSize: 1048576, // 1 MB
|
|
18
|
+
retries: 3,
|
|
19
|
+
retryDelay: 2000,
|
|
20
|
+
timeout: 300000, // 5 minutes
|
|
21
|
+
connectTimeout: 10000, // 10 seconds
|
|
22
|
+
checksumAlgorithm: 'sha256',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for speed calculation
|
|
26
|
+
*/
|
|
27
|
+
export const SPEED_CONFIG = {
|
|
28
|
+
ewmaAlpha: 0.3, // EWMA smoothing factor
|
|
29
|
+
sampleInterval: 1000, // Sample every 1 second
|
|
30
|
+
windowSize: 10, // Keep last 10 samples
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for chunk strategy
|
|
34
|
+
*/
|
|
35
|
+
export const CHUNK_STRATEGY_CONFIG = {
|
|
36
|
+
minPrimaryReserve: 0.1, // Minimum 10% reserved for primary
|
|
37
|
+
maxPrimaryReserve: 0.5, // Maximum 50% reserved for primary
|
|
38
|
+
basePrimaryReserve: 0.2, // Base reserve ratio
|
|
39
|
+
sizeFactorMax: 0.1, // Additional from file size
|
|
40
|
+
speedFactorMax: 0.15, // Additional from speed
|
|
41
|
+
progressFactorMax: 0.05, // Additional from progress
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for source replacement
|
|
45
|
+
*/
|
|
46
|
+
export const REPLACEMENT_CONFIG = {
|
|
47
|
+
minTimeBeforeReplace: 30000, // 30 seconds minimum
|
|
48
|
+
checkInterval: 10000, // Check every 10 seconds
|
|
49
|
+
slowThresholdRatio: 0.33, // Slow is < 33% of fast
|
|
50
|
+
maxSlowChecks: 3, // Max consecutive slow checks
|
|
51
|
+
bufferSize: 1048576, // 1 MB buffer before switch
|
|
52
|
+
immediateFailureCodes: [
|
|
53
|
+
'ECONNREFUSED',
|
|
54
|
+
'ENETUNREACH',
|
|
55
|
+
'EHOSTUNREACH',
|
|
56
|
+
'ETIMEDOUT',
|
|
57
|
+
'ENOTFOUND',
|
|
58
|
+
'EAI_AGAIN',
|
|
59
|
+
],
|
|
60
|
+
immediateFailureHttp: [
|
|
61
|
+
404, 401, 403, 410, 500, 502, 503, 504,
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for temporary files
|
|
66
|
+
*/
|
|
67
|
+
export const TEMP_FILE_CONFIG = {
|
|
68
|
+
prefix: '.justget-',
|
|
69
|
+
hashLength: 5,
|
|
70
|
+
maxAgeHours: 1, // Clean files older than 1 hour
|
|
71
|
+
resumeThreshold: 0.9, // Resume if >= 90% complete
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Check if an error indicates immediate failure (not just slow)
|
|
75
|
+
*
|
|
76
|
+
* Immediate failures should trigger mirror start immediately,
|
|
77
|
+
* not wait for warmup timeout.
|
|
78
|
+
*/
|
|
79
|
+
export function isImmediateFailure(error, httpStatus) {
|
|
80
|
+
// Check HTTP status codes
|
|
81
|
+
if (httpStatus !== undefined) {
|
|
82
|
+
if (REPLACEMENT_CONFIG.immediateFailureHttp.includes(httpStatus)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Check error codes
|
|
87
|
+
const code = error.code;
|
|
88
|
+
if (code && REPLACEMENT_CONFIG.immediateFailureCodes.includes(code)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
// Check error message for common failure patterns
|
|
92
|
+
const message = error.message.toLowerCase();
|
|
93
|
+
return (message.includes('connection refused') ||
|
|
94
|
+
message.includes('network unreachable') ||
|
|
95
|
+
message.includes('host unreachable') ||
|
|
96
|
+
message.includes('aborted') ||
|
|
97
|
+
message.includes('cancelled') ||
|
|
98
|
+
(message.includes('timeout') && !message.includes('download timeout')));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Merge user config with defaults
|
|
102
|
+
*/
|
|
103
|
+
export function mergeConfig(userConfig) {
|
|
104
|
+
if (!userConfig) {
|
|
105
|
+
return { ...DEFAULT_CONFIG };
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...DEFAULT_CONFIG,
|
|
109
|
+
...userConfig,
|
|
110
|
+
// Handle nested merges if needed
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validate configuration
|
|
115
|
+
*/
|
|
116
|
+
export function validateConfig(config) {
|
|
117
|
+
if (config.primaryWarmupTime !== undefined && config.primaryWarmupTime < 0) {
|
|
118
|
+
throw new Error('primaryWarmupTime must be non-negative');
|
|
119
|
+
}
|
|
120
|
+
if (config.speedThreshold !== undefined && config.speedThreshold < 0) {
|
|
121
|
+
throw new Error('speedThreshold must be non-negative');
|
|
122
|
+
}
|
|
123
|
+
if (config.fastPrimaryThreshold !== undefined && config.fastPrimaryThreshold < 0) {
|
|
124
|
+
throw new Error('fastPrimaryThreshold must be non-negative');
|
|
125
|
+
}
|
|
126
|
+
if (config.sizeThreshold !== undefined && config.sizeThreshold < 0) {
|
|
127
|
+
throw new Error('sizeThreshold must be non-negative');
|
|
128
|
+
}
|
|
129
|
+
if (config.minReplaceTime !== undefined && config.minReplaceTime < 0) {
|
|
130
|
+
throw new Error('minReplaceTime must be non-negative');
|
|
131
|
+
}
|
|
132
|
+
if (config.replaceCheckInterval !== undefined && config.replaceCheckInterval < 0) {
|
|
133
|
+
throw new Error('replaceCheckInterval must be non-negative');
|
|
134
|
+
}
|
|
135
|
+
if (config.connectTimeout !== undefined && config.connectTimeout < 0) {
|
|
136
|
+
throw new Error('connectTimeout must be non-negative');
|
|
137
|
+
}
|
|
138
|
+
if (config.chunks !== undefined && typeof config.chunks === 'number' && config.chunks < 1) {
|
|
139
|
+
throw new Error('chunks must be at least 1');
|
|
140
|
+
}
|
|
141
|
+
if (config.chunkSize !== undefined && typeof config.chunkSize === 'number' && config.chunkSize < 1) {
|
|
142
|
+
throw new Error('chunkSize must be at least 1');
|
|
143
|
+
}
|
|
144
|
+
if (config.minChunkSize !== undefined && config.minChunkSize < 1) {
|
|
145
|
+
throw new Error('minChunkSize must be at least 1');
|
|
146
|
+
}
|
|
147
|
+
if (config.retries !== undefined && config.retries < 0) {
|
|
148
|
+
throw new Error('retries must be non-negative');
|
|
149
|
+
}
|
|
150
|
+
if (config.timeout !== undefined && config.timeout < 0) {
|
|
151
|
+
throw new Error('timeout must be non-negative');
|
|
152
|
+
}
|
|
153
|
+
if (config.checksumAlgorithm !== undefined &&
|
|
154
|
+
!['md5', 'sha1', 'sha256', 'sha512'].includes(config.checksumAlgorithm)) {
|
|
155
|
+
throw new Error(`Unsupported checksumAlgorithm: ${config.checksumAlgorithm}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,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,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 核心下载器:多源竞速分块下载
|
|
3
|
+
* Core downloader: multi-source racing chunked download
|
|
4
|
+
*
|
|
5
|
+
* 流程 / Flow:
|
|
6
|
+
* 探测(probe) → 分块(chunks) → 主源预热(warmup) → 决策(decide mirrors)
|
|
7
|
+
* → 竞速(race) → 慢源替换(replace) → 合并(merge) → 校验(verify) → 提交(commit)
|
|
8
|
+
*/
|
|
9
|
+
import type { DownloadOptions, DownloadResult } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* 多源竞速分块下载
|
|
12
|
+
* Multi-source racing chunked download
|
|
13
|
+
*/
|
|
14
|
+
export declare function download(options: DownloadOptions): Promise<DownloadResult>;
|
|
15
|
+
/** 下载器类(download() 的面向对象封装)/ OO wrapper over download() */
|
|
16
|
+
export declare class Downloader {
|
|
17
|
+
private options;
|
|
18
|
+
constructor(options: DownloadOptions);
|
|
19
|
+
/** 开始下载 / start download */
|
|
20
|
+
start(): Promise<DownloadResult>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=downloader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloader.d.ts","sourceRoot":"","sources":["../../src/core/downloader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA4BH,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EAKf,MAAM,aAAa,CAAC;AAgDrB;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAahF;AAsfD,2DAA2D;AAC3D,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAkB;gBAErB,OAAO,EAAE,eAAe;IAIpC,4BAA4B;IAC5B,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC;CAGjC"}
|