magnetk 2.2.0 → 2.2.3
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 +27 -0
- package/client.js +15 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -99,6 +99,33 @@ magnetk download "magnetk:?..." --output ./file.zip
|
|
|
99
99
|
- `connection-type`: `{ type }` (DIRECT, RELAYED, LOCAL)
|
|
100
100
|
- `error`: `{ code, message }`
|
|
101
101
|
|
|
102
|
+
## Prerequisites
|
|
103
|
+
|
|
104
|
+
The JavaScript SDK is a lightweight wrapper around the high-performance **Magnetk Go Binaries**. You must have these binaries on your system to use seeding or relay features.
|
|
105
|
+
|
|
106
|
+
1. **Download** the latest binaries for your platform (Windows/Linux/macOS).
|
|
107
|
+
2. **Ensure** they are in your system `PATH` OR provide the path manually in the SDK config.
|
|
108
|
+
|
|
109
|
+
### Manual Configuration
|
|
110
|
+
```javascript
|
|
111
|
+
const client = new MagnetkClient({
|
|
112
|
+
seederPath: 'C:\\path\\to\\seed.exe', // Explicit path
|
|
113
|
+
relayUrl: '69.169.109.243'
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Environment Variables
|
|
118
|
+
You can also set the binary path globally:
|
|
119
|
+
- `MAGNETK_SEEDER_PATH`: Path to the `seed.exe` binary.
|
|
120
|
+
|
|
121
|
+
## Troubleshooting
|
|
122
|
+
|
|
123
|
+
### "spawn seed.exe ENOENT" Error
|
|
124
|
+
This means the SDK cannot find the Go seeder binary.
|
|
125
|
+
1. Check if `seed.exe` is in your system `PATH`.
|
|
126
|
+
2. Or provide `seederPath` in the `MagnetkClient` constructor.
|
|
127
|
+
3. Or set the `MAGNETK_SEEDER_PATH` environment variable.
|
|
128
|
+
|
|
102
129
|
## License
|
|
103
130
|
MIT
|
|
104
131
|
|
package/client.js
CHANGED
|
@@ -12,6 +12,7 @@ import crypto from 'crypto';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { spawn } from 'child_process';
|
|
14
14
|
import { EventEmitter } from 'events';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
15
16
|
import { MagnetkLink } from './magnetk.js';
|
|
16
17
|
|
|
17
18
|
const MSG_TYPE = {
|
|
@@ -41,6 +42,8 @@ export class MagnetkClient extends EventEmitter {
|
|
|
41
42
|
relayPort: 4003,
|
|
42
43
|
seedPort: 4002,
|
|
43
44
|
enableSTUN: true,
|
|
45
|
+
seederPath: null,
|
|
46
|
+
configPath: null,
|
|
44
47
|
...config
|
|
45
48
|
};
|
|
46
49
|
this.processes = [];
|
|
@@ -405,7 +408,14 @@ export class MagnetkClient extends EventEmitter {
|
|
|
405
408
|
}
|
|
406
409
|
|
|
407
410
|
_resolveBinPath(binName) {
|
|
408
|
-
//
|
|
411
|
+
// 1. Check explicit config
|
|
412
|
+
if (this.config.seederPath && binName === 'seed.exe') return this.config.seederPath;
|
|
413
|
+
|
|
414
|
+
// 2. Check environment variable
|
|
415
|
+
const envPath = binName === 'seed.exe' ? process.env.MAGNETK_SEEDER_PATH : null;
|
|
416
|
+
if (envPath && fs.existsSync(envPath)) return envPath;
|
|
417
|
+
|
|
418
|
+
// 3. Check local dev environment paths
|
|
409
419
|
const paths = [
|
|
410
420
|
path.join(process.cwd(), 'bin', binName),
|
|
411
421
|
path.join(process.cwd(), '..', '..', '..', 'bin', binName),
|
|
@@ -419,6 +429,10 @@ export class MagnetkClient extends EventEmitter {
|
|
|
419
429
|
}
|
|
420
430
|
|
|
421
431
|
_resolveConfigPath() {
|
|
432
|
+
// 1. Check explicit config
|
|
433
|
+
if (this.config.configPath) return this.config.configPath;
|
|
434
|
+
|
|
435
|
+
// 2. Check local dev environment
|
|
422
436
|
const paths = [
|
|
423
437
|
path.join(process.cwd(), 'config', 'settings.conf'),
|
|
424
438
|
path.join(process.cwd(), '..', '..', '..', 'config', 'settings.conf'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magnetk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "JavaScript SDK for Magnetk P2P File Transfer System",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"utils.js",
|
|
15
15
|
"README.md",
|
|
16
16
|
"LICENSE",
|
|
17
|
-
"package.json"
|
|
17
|
+
"package.json",
|
|
18
|
+
"share.js",
|
|
19
|
+
"download.js"
|
|
18
20
|
],
|
|
19
21
|
"scripts": {
|
|
20
22
|
"test": "node test.js"
|