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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speed monitoring for download sources
|
|
3
|
+
*/
|
|
4
|
+
import { EWMA, calculateInstantSpeed, getSpeedStats } from './ewma.js';
|
|
5
|
+
import { SPEED_CONFIG } from '../config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Monitor and calculate download speed
|
|
8
|
+
*/
|
|
9
|
+
export class SpeedMonitor {
|
|
10
|
+
samples = [];
|
|
11
|
+
ewma;
|
|
12
|
+
startTime;
|
|
13
|
+
options;
|
|
14
|
+
interval;
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.options = {
|
|
17
|
+
alpha: options.alpha ?? SPEED_CONFIG.ewmaAlpha,
|
|
18
|
+
sampleInterval: options.sampleInterval ?? SPEED_CONFIG.sampleInterval,
|
|
19
|
+
windowSize: options.windowSize ?? SPEED_CONFIG.windowSize,
|
|
20
|
+
};
|
|
21
|
+
this.ewma = new EWMA(this.options.alpha);
|
|
22
|
+
this.startTime = Date.now();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Record a speed sample
|
|
26
|
+
*/
|
|
27
|
+
record(bytes) {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const sample = { bytes, timestamp: now };
|
|
30
|
+
this.samples.push(sample);
|
|
31
|
+
// Keep only recent samples within window
|
|
32
|
+
while (this.samples.length > this.options.windowSize) {
|
|
33
|
+
this.samples.shift();
|
|
34
|
+
}
|
|
35
|
+
// Update EWMA
|
|
36
|
+
if (this.samples.length >= 2) {
|
|
37
|
+
const instantSpeed = calculateInstantSpeed(this.samples);
|
|
38
|
+
this.ewma.update(instantSpeed);
|
|
39
|
+
}
|
|
40
|
+
return getSpeedStats(this.samples, this.startTime, this.ewma);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get current speed statistics
|
|
44
|
+
*/
|
|
45
|
+
getStats() {
|
|
46
|
+
return getSpeedStats(this.samples, this.startTime, this.ewma);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get current speed (EWMA)
|
|
50
|
+
*/
|
|
51
|
+
getCurrentSpeed() {
|
|
52
|
+
return this.ewma.getValue();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if speed is below threshold
|
|
56
|
+
*/
|
|
57
|
+
isBelowThreshold(threshold) {
|
|
58
|
+
return this.getCurrentSpeed() < threshold;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Start automatic sampling
|
|
62
|
+
*/
|
|
63
|
+
startSampling(getBytes, callback) {
|
|
64
|
+
this.interval = setInterval(() => {
|
|
65
|
+
const bytes = getBytes();
|
|
66
|
+
const stats = this.record(bytes);
|
|
67
|
+
callback?.(stats);
|
|
68
|
+
}, this.options.sampleInterval);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stop automatic sampling
|
|
72
|
+
*/
|
|
73
|
+
stopSampling() {
|
|
74
|
+
if (this.interval) {
|
|
75
|
+
clearInterval(this.interval);
|
|
76
|
+
this.interval = undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reset monitor
|
|
81
|
+
*/
|
|
82
|
+
reset() {
|
|
83
|
+
this.samples = [];
|
|
84
|
+
this.ewma.reset();
|
|
85
|
+
this.startTime = Date.now();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get elapsed time in milliseconds
|
|
89
|
+
*/
|
|
90
|
+
getElapsedTime() {
|
|
91
|
+
return Date.now() - this.startTime;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=speed-monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speed-monitor.js","sourceRoot":"","sources":["../../src/speed/speed-monitor.ts"],"names":[],"mappings":"AAAA;;GAE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,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;IACrC,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core TypeScript type definitions for GetIt
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Download configuration options
|
|
6
|
+
*/
|
|
7
|
+
export interface DownloadOptions {
|
|
8
|
+
/** Primary URL to download from */
|
|
9
|
+
url: string;
|
|
10
|
+
/** Output file path */
|
|
11
|
+
output: string;
|
|
12
|
+
/** Mirror URL list for fallback */
|
|
13
|
+
mirrors?: string[];
|
|
14
|
+
/** Additional configuration */
|
|
15
|
+
options?: DownloadConfig;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fine-grained download configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface DownloadConfig {
|
|
21
|
+
/** Primary server warmup time in milliseconds (default: 5000) */
|
|
22
|
+
primaryWarmupTime?: number;
|
|
23
|
+
/** Speed threshold in bytes/s (default: 512000) */
|
|
24
|
+
speedThreshold?: number;
|
|
25
|
+
/** Fast primary threshold in bytes/s (default: 2048000) - above this, don't start mirrors */
|
|
26
|
+
fastPrimaryThreshold?: number;
|
|
27
|
+
/** File size threshold in bytes (default: 52428800) */
|
|
28
|
+
sizeThreshold?: number;
|
|
29
|
+
/** Minimum time before source replacement in ms (default: 30000) */
|
|
30
|
+
minReplaceTime?: number;
|
|
31
|
+
/** Source replacement check interval in ms (default: 10000) */
|
|
32
|
+
replaceCheckInterval?: number;
|
|
33
|
+
/** Number of chunks or 'auto' (default: 'auto') */
|
|
34
|
+
chunks?: number | 'auto';
|
|
35
|
+
/** Chunk size in bytes or 'auto' (default: 'auto') */
|
|
36
|
+
chunkSize?: number | 'auto';
|
|
37
|
+
/** Minimum chunk size in bytes (default: 1048576) */
|
|
38
|
+
minChunkSize?: number;
|
|
39
|
+
/** Retry count per source (default: 3) */
|
|
40
|
+
retries?: number;
|
|
41
|
+
/** Retry delay in milliseconds (default: 2000) */
|
|
42
|
+
retryDelay?: number;
|
|
43
|
+
/** Download timeout in milliseconds (default: 300000) */
|
|
44
|
+
timeout?: number;
|
|
45
|
+
/** Connection timeout in milliseconds (default: 10000) */
|
|
46
|
+
connectTimeout?: number;
|
|
47
|
+
/** Progress callback */
|
|
48
|
+
onProgress?: (progress: ProgressInfo) => void;
|
|
49
|
+
/** Completion callback */
|
|
50
|
+
onComplete?: (result: DownloadResult) => void;
|
|
51
|
+
/** Error callback */
|
|
52
|
+
onError?: (error: Error) => void;
|
|
53
|
+
/** Expected checksum for validation */
|
|
54
|
+
checksum?: string;
|
|
55
|
+
/** Checksum algorithm */
|
|
56
|
+
checksumAlgorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Progress information during download
|
|
60
|
+
*/
|
|
61
|
+
export interface ProgressInfo {
|
|
62
|
+
/** Number of bytes downloaded */
|
|
63
|
+
downloadedBytes: number;
|
|
64
|
+
/** Total number of bytes */
|
|
65
|
+
totalBytes: number;
|
|
66
|
+
/** Completion percentage (0-100) */
|
|
67
|
+
percentage: number;
|
|
68
|
+
/** Current download speed in bytes/s */
|
|
69
|
+
speed: number;
|
|
70
|
+
/** Estimated time remaining in milliseconds */
|
|
71
|
+
eta: number;
|
|
72
|
+
/** Progress for each source */
|
|
73
|
+
sources: SourceProgress[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Progress for a single source
|
|
77
|
+
*/
|
|
78
|
+
export interface SourceProgress {
|
|
79
|
+
/** Source identifier */
|
|
80
|
+
id: string;
|
|
81
|
+
/** Source URL */
|
|
82
|
+
url: string;
|
|
83
|
+
/** Bytes downloaded from this source */
|
|
84
|
+
downloadedBytes: number;
|
|
85
|
+
/** Current speed in bytes/s */
|
|
86
|
+
speed: number;
|
|
87
|
+
/** Source status */
|
|
88
|
+
status: SourceStatus;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Source status
|
|
92
|
+
*/
|
|
93
|
+
export type SourceStatus = 'active' | 'waiting' | 'completed' | 'failed';
|
|
94
|
+
/**
|
|
95
|
+
* Download result
|
|
96
|
+
*/
|
|
97
|
+
export interface DownloadResult {
|
|
98
|
+
/** Output file path */
|
|
99
|
+
path: string;
|
|
100
|
+
/** Total bytes downloaded */
|
|
101
|
+
bytes: number;
|
|
102
|
+
/** Total download time in milliseconds */
|
|
103
|
+
duration: number;
|
|
104
|
+
/** Average speed in bytes/s */
|
|
105
|
+
averageSpeed: number;
|
|
106
|
+
/** Sources used */
|
|
107
|
+
sources: SourceResult[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Result for a single source
|
|
111
|
+
*/
|
|
112
|
+
export interface SourceResult {
|
|
113
|
+
/** Source identifier */
|
|
114
|
+
id: string;
|
|
115
|
+
/** Source URL */
|
|
116
|
+
url: string;
|
|
117
|
+
/** Bytes downloaded from this source */
|
|
118
|
+
bytes: number;
|
|
119
|
+
/** Time taken in milliseconds */
|
|
120
|
+
duration: number;
|
|
121
|
+
/** Average speed in bytes/s */
|
|
122
|
+
averageSpeed: number;
|
|
123
|
+
/** Source status */
|
|
124
|
+
status: SourceStatus;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Download chunk information
|
|
128
|
+
*/
|
|
129
|
+
export interface DownloadChunk {
|
|
130
|
+
/** Chunk index */
|
|
131
|
+
index: number;
|
|
132
|
+
/** Start byte position */
|
|
133
|
+
start: number;
|
|
134
|
+
/** End byte position */
|
|
135
|
+
end: number;
|
|
136
|
+
/** Size in bytes */
|
|
137
|
+
size: number;
|
|
138
|
+
/** Current download progress */
|
|
139
|
+
progress: number;
|
|
140
|
+
/** Source assigned to this chunk */
|
|
141
|
+
sourceId?: string;
|
|
142
|
+
/** Temporary file path */
|
|
143
|
+
tempPath: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Download source information
|
|
147
|
+
*/
|
|
148
|
+
export interface Source {
|
|
149
|
+
/** Source identifier */
|
|
150
|
+
id: string;
|
|
151
|
+
/** Source URL */
|
|
152
|
+
url: string;
|
|
153
|
+
/** Whether this is the primary source */
|
|
154
|
+
isPrimary: boolean;
|
|
155
|
+
/** Whether range requests are supported */
|
|
156
|
+
supportsRange: boolean;
|
|
157
|
+
/** Current status */
|
|
158
|
+
status: SourceStatus;
|
|
159
|
+
/** Bytes downloaded */
|
|
160
|
+
downloadedBytes: number;
|
|
161
|
+
/** Current speed in bytes/s */
|
|
162
|
+
speed: number;
|
|
163
|
+
/** Number of consecutive slow checks */
|
|
164
|
+
slowChecks: number;
|
|
165
|
+
/** Start timestamp */
|
|
166
|
+
startTime: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Chunk strategy calculation result
|
|
170
|
+
*/
|
|
171
|
+
export interface ChunkStrategy {
|
|
172
|
+
/** Primary reserve ratio (0-1) */
|
|
173
|
+
primaryReserve: number;
|
|
174
|
+
/** Mirror start ratio (0-1) */
|
|
175
|
+
mirrorStart: number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Slow source replacement decision
|
|
179
|
+
*/
|
|
180
|
+
export interface ReplaceDecision {
|
|
181
|
+
/** Whether to replace */
|
|
182
|
+
shouldReplace: boolean;
|
|
183
|
+
/** Slow source to replace */
|
|
184
|
+
slowSource?: Source;
|
|
185
|
+
/** Fast source to switch to */
|
|
186
|
+
fastSource?: Source;
|
|
187
|
+
/** Byte position to switch at */
|
|
188
|
+
switchPoint?: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Range support check result
|
|
192
|
+
*/
|
|
193
|
+
export interface RangeCheckResult {
|
|
194
|
+
/** Whether range requests are supported */
|
|
195
|
+
supportsRange: boolean;
|
|
196
|
+
/** Content length (bytes) */
|
|
197
|
+
contentLength?: number;
|
|
198
|
+
/** Accept-Ranges header value */
|
|
199
|
+
acceptRanges?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Speed sample for EWMA calculation
|
|
203
|
+
*/
|
|
204
|
+
export interface SpeedSample {
|
|
205
|
+
/** Bytes */
|
|
206
|
+
bytes: number;
|
|
207
|
+
/** Timestamp */
|
|
208
|
+
timestamp: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Speed statistics
|
|
212
|
+
*/
|
|
213
|
+
export interface SpeedStats {
|
|
214
|
+
/** Current speed in bytes/s */
|
|
215
|
+
current: number;
|
|
216
|
+
/** EWMA speed in bytes/s */
|
|
217
|
+
ewma: number;
|
|
218
|
+
/** Peak speed in bytes/s */
|
|
219
|
+
peak: number;
|
|
220
|
+
/** Average speed in bytes/s */
|
|
221
|
+
average: number;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* File validation result
|
|
225
|
+
*/
|
|
226
|
+
export interface ValidationResult {
|
|
227
|
+
/** Whether file is valid */
|
|
228
|
+
valid: boolean;
|
|
229
|
+
/** Actual checksum */
|
|
230
|
+
actual?: string;
|
|
231
|
+
/** Expected checksum */
|
|
232
|
+
expected?: string;
|
|
233
|
+
/** Error message */
|
|
234
|
+
error?: string;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IA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WAAW;IAC1B,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temporary file naming and management utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate a short hash for a string
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateShortHash(input: string, length?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Get temporary file name for a chunk
|
|
10
|
+
*
|
|
11
|
+
* Format: .justget-{basename}-{hash}-{source}-{chunk}.{ext}
|
|
12
|
+
*/
|
|
13
|
+
export declare function getTempFileName(originalName: string, sourceId: string, chunkIndex: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get merged temporary file name
|
|
16
|
+
*
|
|
17
|
+
* Format: .justget-{basename}-{hash}.merged{ext}
|
|
18
|
+
*/
|
|
19
|
+
export declare function getMergedTempFileName(originalName: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get the directory for temporary files
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTempDir(targetPath: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a path is a JustGet temporary file
|
|
26
|
+
*/
|
|
27
|
+
export declare function isTempFile(filePath: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Get base original filename from temp filename
|
|
30
|
+
* 支持分块与 merged 两种格式 / supports both chunk and merged formats
|
|
31
|
+
*/
|
|
32
|
+
export declare function getOriginalFromTemp(tempPath: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Extract hash from temp filename
|
|
35
|
+
* 支持分块与 merged 两种格式 / supports both chunk and merged formats
|
|
36
|
+
*/
|
|
37
|
+
export declare function getHashFromTemp(tempPath: string): string | null;
|
|
38
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAoC,GAAG,MAAM,CAGrG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOlE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGpD;AAcD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO5D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO/D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temporary file naming and management utilities
|
|
3
|
+
*/
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import * as crypto from 'node:crypto';
|
|
6
|
+
import { TEMP_FILE_CONFIG } from '../config.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generate a short hash for a string
|
|
9
|
+
*/
|
|
10
|
+
export function generateShortHash(input, length = TEMP_FILE_CONFIG.hashLength) {
|
|
11
|
+
const hash = crypto.createHash('sha256').update(input).digest('hex');
|
|
12
|
+
return hash.slice(0, length);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get temporary file name for a chunk
|
|
16
|
+
*
|
|
17
|
+
* Format: .justget-{basename}-{hash}-{source}-{chunk}.{ext}
|
|
18
|
+
*/
|
|
19
|
+
export function getTempFileName(originalName, sourceId, chunkIndex) {
|
|
20
|
+
const basename = path.basename(originalName);
|
|
21
|
+
const ext = path.extname(originalName);
|
|
22
|
+
const nameWithoutExt = ext ? basename.slice(0, -ext.length) : basename;
|
|
23
|
+
const hash = generateShortHash(originalName);
|
|
24
|
+
return `${TEMP_FILE_CONFIG.prefix}${nameWithoutExt}-${hash}-${sourceId}-${chunkIndex}${ext}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get merged temporary file name
|
|
28
|
+
*
|
|
29
|
+
* Format: .justget-{basename}-{hash}.merged{ext}
|
|
30
|
+
*/
|
|
31
|
+
export function getMergedTempFileName(originalName) {
|
|
32
|
+
const basename = path.basename(originalName);
|
|
33
|
+
const ext = path.extname(originalName);
|
|
34
|
+
const nameWithoutExt = ext ? basename.slice(0, -ext.length) : basename;
|
|
35
|
+
const hash = generateShortHash(originalName);
|
|
36
|
+
return `${TEMP_FILE_CONFIG.prefix}${nameWithoutExt}-${hash}.merged${ext}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the directory for temporary files
|
|
40
|
+
*/
|
|
41
|
+
export function getTempDir(targetPath) {
|
|
42
|
+
return path.dirname(path.resolve(targetPath));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a path is a JustGet temporary file
|
|
46
|
+
*/
|
|
47
|
+
export function isTempFile(filePath) {
|
|
48
|
+
const basename = path.basename(filePath);
|
|
49
|
+
return basename.startsWith(TEMP_FILE_CONFIG.prefix);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 分块临时文件:.justget-{name}-{hash}-{source}-{index}{ext}
|
|
53
|
+
* Chunk temp file pattern
|
|
54
|
+
*/
|
|
55
|
+
const CHUNK_TEMP_RE = /^\.justget-(.+)-([0-9a-f]{5,})-([^-]+)-(\d+)(\.[^.]*)?$/;
|
|
56
|
+
/**
|
|
57
|
+
* merged 临时文件:.justget-{name}-{hash}.merged{ext}
|
|
58
|
+
* Merged temp file pattern
|
|
59
|
+
*/
|
|
60
|
+
const MERGED_TEMP_RE = /^\.justget-(.+)-([0-9a-f]{5,})\.merged(\.[^.]*)?$/;
|
|
61
|
+
/**
|
|
62
|
+
* Get base original filename from temp filename
|
|
63
|
+
* 支持分块与 merged 两种格式 / supports both chunk and merged formats
|
|
64
|
+
*/
|
|
65
|
+
export function getOriginalFromTemp(tempPath) {
|
|
66
|
+
const basename = path.basename(tempPath);
|
|
67
|
+
const chunkMatch = CHUNK_TEMP_RE.exec(basename);
|
|
68
|
+
if (chunkMatch)
|
|
69
|
+
return chunkMatch[1] + (chunkMatch[5] ?? '');
|
|
70
|
+
const mergedMatch = MERGED_TEMP_RE.exec(basename);
|
|
71
|
+
if (mergedMatch)
|
|
72
|
+
return mergedMatch[1] + (mergedMatch[3] ?? '');
|
|
73
|
+
return basename;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Extract hash from temp filename
|
|
77
|
+
* 支持分块与 merged 两种格式 / supports both chunk and merged formats
|
|
78
|
+
*/
|
|
79
|
+
export function getHashFromTemp(tempPath) {
|
|
80
|
+
const basename = path.basename(tempPath);
|
|
81
|
+
const chunkMatch = CHUNK_TEMP_RE.exec(basename);
|
|
82
|
+
if (chunkMatch)
|
|
83
|
+
return chunkMatch[2];
|
|
84
|
+
const mergedMatch = MERGED_TEMP_RE.exec(basename);
|
|
85
|
+
if (mergedMatch)
|
|
86
|
+
return mergedMatch[2];
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,SAAiB,gBAAgB,CAAC,UAAU;IAC3F,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,YAAoB,EACpB,QAAgB,EAChB,UAAkB;IAElB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,MAAM,cAAc,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACvE,MAAM,IAAI,GAAG,iBAAiB,CAAC,YAAY,CA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CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File validation utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { ValidationResult } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Calculate file checksum
|
|
7
|
+
*/
|
|
8
|
+
export declare function calculateChecksum(filePath: string, algorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512'): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Validate file against expected checksum
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateFile(filePath: string, expectedChecksum: string, algorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512'): Promise<ValidationResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Get file size
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFileSize(filePath: string): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if file exists
|
|
19
|
+
*/
|
|
20
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
21
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/utils/validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAmB,GACzD,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,SAAS,GAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAmB,GACzD,OAAO,CAAC,gBAAgB,CAAC,CA4B3B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGnE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File validation utilities
|
|
3
|
+
*/
|
|
4
|
+
import * as crypto from 'node:crypto';
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import { access, stat } from 'node:fs/promises';
|
|
7
|
+
/**
|
|
8
|
+
* Calculate file checksum
|
|
9
|
+
*/
|
|
10
|
+
export async function calculateChecksum(filePath, algorithm = 'sha256') {
|
|
11
|
+
const hash = crypto.createHash(algorithm);
|
|
12
|
+
const stream = fs.createReadStream(filePath);
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
stream.on('data', (chunk) => {
|
|
15
|
+
hash.update(chunk);
|
|
16
|
+
});
|
|
17
|
+
stream.on('end', () => resolve(hash.digest('hex')));
|
|
18
|
+
stream.on('error', reject);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate file against expected checksum
|
|
23
|
+
*/
|
|
24
|
+
export async function validateFile(filePath, expectedChecksum, algorithm = 'sha256') {
|
|
25
|
+
try {
|
|
26
|
+
// Check if file exists
|
|
27
|
+
try {
|
|
28
|
+
await access(filePath);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {
|
|
32
|
+
valid: false,
|
|
33
|
+
expected: expectedChecksum,
|
|
34
|
+
error: 'File does not exist',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const actual = await calculateChecksum(filePath, algorithm);
|
|
38
|
+
const valid = actual.toLowerCase() === expectedChecksum.toLowerCase();
|
|
39
|
+
return {
|
|
40
|
+
valid,
|
|
41
|
+
actual,
|
|
42
|
+
expected: expectedChecksum,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return {
|
|
47
|
+
valid: false,
|
|
48
|
+
expected: expectedChecksum,
|
|
49
|
+
error: error instanceof Error ? error.message : String(error),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get file size
|
|
55
|
+
*/
|
|
56
|
+
export async function getFileSize(filePath) {
|
|
57
|
+
const stats = await stat(filePath);
|
|
58
|
+
return stats.size;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if file exists
|
|
62
|
+
*/
|
|
63
|
+
export async function fileExists(filePath) {
|
|
64
|
+
try {
|
|
65
|
+
await access(filePath);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
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BAAgB;gBAC1B,KAAK,EAAE,qBAAqB;aAC7B,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,KAAK,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAEtE,OAAO;YACL,KAAK;YACL,MAAM;YACN,QAAQ,EAAE,gBAAgB;SAC3B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,gBAAgB;YAC1B,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAgB;IAChD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "justget",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Multi-source racing chunked downloader with intelligent scheduling / 多源竞速分块下载器",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"justget": "dist/cli.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"dev": "tsc --watch",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"test:coverage": "vitest --coverage",
|
|
27
|
+
"lint": "eslint src --ext .ts",
|
|
28
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"download",
|
|
33
|
+
"downloader",
|
|
34
|
+
"multi-source",
|
|
35
|
+
"chunked",
|
|
36
|
+
"parallel",
|
|
37
|
+
"mirror",
|
|
38
|
+
"http",
|
|
39
|
+
"file"
|
|
40
|
+
],
|
|
41
|
+
"author": "Wind Li",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/justdb/justget.git"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/justdb/justget/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/justdb/justget#readme",
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"commander": "^11.1.0",
|
|
56
|
+
"node-fetch": "^3.3.2",
|
|
57
|
+
"progress": "^2.0.3"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^20.10.6",
|
|
61
|
+
"@types/progress": "^2.0.7",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
63
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
64
|
+
"@vitest/coverage-v8": "^1.1.0",
|
|
65
|
+
"eslint": "^8.56.0",
|
|
66
|
+
"prettier": "^3.1.1",
|
|
67
|
+
"typescript": "^5.3.3",
|
|
68
|
+
"vitest": "^1.1.0"
|
|
69
|
+
}
|
|
70
|
+
}
|