From 8e4001d322d9b639a45709ff617a94c07e91f741 Mon Sep 17 00:00:00 2001 From: Vadim Sobinin Date: Fri, 6 Feb 2026 17:23:59 +0300 Subject: [PATCH] feat: use full IP address instead of subnet suffix --- docs/vlc-sender.md | 6 +++--- src/index.ts | 8 +++----- src/public/index.html | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/vlc-sender.md b/docs/vlc-sender.md index 2b92401..1719cda 100644 --- a/docs/vlc-sender.md +++ b/docs/vlc-sender.md @@ -17,13 +17,13 @@ ### POST /api/send ```json -{ "ip": "243", "files": ["Torrents/movie.mkv"] } +{ "ip": "192.168.50.206", "port": 80, "files": ["Torrents/movie.mkv"] } ``` -Путь файла: `{volume_label}/{subpath}`. Ответ — SSE stream с событиями: `start`, `done`, `error`, `complete`. +Путь файла: `{volume_label}/{subpath}`. `port` опционален (по умолчанию 80). Ответ — SSE stream с событиями: `start`, `done`, `error`, `complete`. ## VLC API -VLC принимает файлы через `POST http://192.168.1.{ip}:8888/upload.json` (multipart/form-data, поле `file`). Порт 8888 — стандартный для VLC iOS WiFi Upload. +VLC принимает файлы через `POST http://{ip}:{port}/upload.json` (multipart/form-data, поле `files[]`). IP и порт вводятся в UI целиком. ## Переменные окружения diff --git a/src/index.ts b/src/index.ts index 9c9937d..85a25a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import FormData from 'form-data'; const app = express(); const PORT = parseInt(process.env.PORT || '3000', 10); -const SUBNET_PREFIX = '192.168.1.'; // Parse volumes: "label1:/path1,label2:/path2" or just "/path1,/path2" interface Volume { @@ -210,13 +209,12 @@ app.post('/api/send', (req: Request, res: Response): void => { return; } - const ipNum = parseInt(ip, 10); - if (isNaN(ipNum) || ipNum < 1 || ipNum > 254) { - res.status(400).json({ error: 'Invalid IP suffix' }); + if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip)) { + res.status(400).json({ error: 'Invalid IP address' }); return; } - const vlcHost = `${SUBNET_PREFIX}${ip}`; + const vlcHost = ip; const vlcPort = port && port > 0 && port <= 65535 ? port : 80; res.writeHead(200, { diff --git a/src/public/index.html b/src/public/index.html index cfd08f2..bb3fa1c 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -166,8 +166,7 @@
- 192.168.1. - + :
@@ -233,8 +232,7 @@ function updateSendBtn() { const ip = ipInput.value.trim(); - const ipNum = parseInt(ip, 10); - const validIp = ip && !isNaN(ipNum) && ipNum >= 1 && ipNum <= 254; + const validIp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip); sendBtn.disabled = sending || selectedFiles.size === 0 || !validIp; } @@ -387,6 +385,7 @@ const port = parseInt(portInput.value.trim(), 10) || 80; const body = JSON.stringify({ ip, port, files }); + console.log('Sending to', ip + ':' + port, files); fetch('/api/send', { method: 'POST', headers: { 'Content-Type': 'application/json' },