torrent-online 1.4.9 → 1.4.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/wtui.js +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "torrent-online",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "type": "module",
5
5
  "description": "Stream .torrent / magnet to VLC or browser — torrent streaming for macOS/Linux without a torrent client. Стрим торрентов в VLC или браузер.",
6
6
  "keywords": [
package/wtui.js CHANGED
@@ -194,6 +194,15 @@ function contentTypeByExt(ext) {
194
194
 
195
195
  function makeServer(torrent, base) {
196
196
  return http.createServer((req, res) => {
197
+ try {
198
+ handleReq(req, res, torrent, base);
199
+ } catch (e) {
200
+ if (!res.headersSent) { res.statusCode = 500; res.end('stream error'); }
201
+ console.error('server:', e?.stack || e);
202
+ }
203
+ });
204
+ }
205
+ function handleReq(req, res, torrent, base) {
197
206
  const u = new URL(req.url, 'http://127.0.0.1');
198
207
  let p = u.pathname;
199
208
  if (base) {
@@ -253,7 +262,6 @@ function makeServer(torrent, base) {
253
262
  res.setHeader('Content-Length', total);
254
263
  file.createReadStream().pipe(res);
255
264
  }
256
- });
257
265
  }
258
266
 
259
267
  // ---- Поиск индексаторов ----
@@ -468,7 +476,7 @@ async function addTorrent(client, source, cacheDir) {
468
476
  client.add(source, { path: cacheDir }, t => {
469
477
  if (t.ready) { clearTimeout(to); return resolve(t); }
470
478
  const spin = setInterval(() => {
471
- process.stdout.write(`\r⏳ Метаданные: пиры ${t.peers.length}, получено ${fmtBytes(t.received)} `);
479
+ process.stdout.write(`\r⏳ Метаданные: пиры ${(t.peers?.length ?? 0)}, получено ${fmtBytes(t.received)} `);
472
480
  }, 1000);
473
481
  t.once('ready', () => { clearInterval(spin); process.stdout.write('\x1b[K'); clearTimeout(to); resolve(t); });
474
482
  });
@@ -479,7 +487,7 @@ async function addTorrent(client, source, cacheDir) {
479
487
  function startProgress(torrent) {
480
488
  const t = setInterval(() => {
481
489
  process.stdout.write(
482
- `\r⏬ ${(torrent.progress * 100).toFixed(1)}% · ${fmtBytes(torrent.downloadSpeed)}/s · пиры: ${torrent.peers.length} `
490
+ `\r⏬ ${(torrent.progress * 100).toFixed(1)}% · ${fmtBytes(torrent.downloadSpeed)}/s · пиры: ${(torrent._peers?.size ?? 0)} `
483
491
  );
484
492
  }, 1000);
485
493
  return () => { clearInterval(t); process.stdout.write('\x1b[K\n'); };
@@ -622,6 +630,7 @@ async function main() {
622
630
  const msg = (e && (e.message || e)) + '';
623
631
  if (NET_NOISE.test(msg)) return;
624
632
  console.error('uncaughtException:', msg);
633
+ console.error((e && e.stack || '').split('\n').slice(0, 8).join('\n'));
625
634
  shutdown('uncaught', 1);
626
635
  });
627
636
  if (vlc) vlc.on('exit', () => shutdown('VLC exit'));