magnetk 2.2.0 → 2.2.4

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.
Files changed (3) hide show
  1. package/README.md +27 -0
  2. package/client.js +25 -3
  3. 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 = [];
@@ -206,7 +209,9 @@ export class MagnetkClient extends EventEmitter {
206
209
  console.warn(`[Magnetk-JS] Failed to fetch relay identity: ${e.message}. Using default/configured address might fail if Peer ID is missing.`);
207
210
  }
208
211
 
209
- const binPath = this._resolveBinPath('seed.exe');
212
+ const isWin = process.platform === 'win32';
213
+ const binName = isWin ? 'seed.exe' : 'seed';
214
+ const binPath = this._resolveBinPath(binName);
210
215
  const configPath = this._resolveConfigPath();
211
216
 
212
217
  // Construct full multiaddr if we have the Peer ID
@@ -405,7 +410,19 @@ export class MagnetkClient extends EventEmitter {
405
410
  }
406
411
 
407
412
  _resolveBinPath(binName) {
408
- // Try to find bin in likely locations
413
+ const isWin = process.platform === 'win32';
414
+ const isSeeder = binName.includes('seed');
415
+
416
+ // 1. Check explicit config
417
+ if (isSeeder && this.config.seederPath) return this.config.seederPath;
418
+
419
+ // 2. Check environment variable
420
+ const envVar = isSeeder ? 'MAGNETK_SEEDER_PATH' : null;
421
+ if (envVar && process.env[envVar] && fs.existsSync(process.env[envVar])) {
422
+ return process.env[envVar];
423
+ }
424
+
425
+ // 3. Check local dev environment paths
409
426
  const paths = [
410
427
  path.join(process.cwd(), 'bin', binName),
411
428
  path.join(process.cwd(), '..', '..', '..', 'bin', binName),
@@ -415,10 +432,15 @@ export class MagnetkClient extends EventEmitter {
415
432
  for (const p of paths) {
416
433
  if (fs.existsSync(p)) return p;
417
434
  }
418
- return binName; // Fallback to PATH
435
+
436
+ return binName; // Fallback to PATH (e.g. "seed" or "seed.exe")
419
437
  }
420
438
 
421
439
  _resolveConfigPath() {
440
+ // 1. Check explicit config
441
+ if (this.config.configPath) return this.config.configPath;
442
+
443
+ // 2. Check local dev environment
422
444
  const paths = [
423
445
  path.join(process.cwd(), 'config', 'settings.conf'),
424
446
  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.0",
3
+ "version": "2.2.4",
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"