From b615f5f1002dcb1af3a6390e581e48e29374292c Mon Sep 17 00:00:00 2001 From: Vadim Sobinin Date: Fri, 6 Feb 2026 17:12:40 +0300 Subject: [PATCH] feat: add configurable VLC port in UI --- src/index.ts | 9 ++++++--- src/public/index.html | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 33b3c94..263fa08 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,6 +125,7 @@ app.get('/api/files', (req: Request, res: Response): void => { interface SendRequest { ip: string; + port?: number; files: string[]; } @@ -143,6 +144,7 @@ function resolveFilePath(filePath: string): string | null { function sendFileToVLC( filePath: string, vlcHost: string, + vlcPort: number, ): Promise<{ file: string; success: boolean; error?: string }> { return new Promise((resolve) => { const resolved = resolveFilePath(filePath); @@ -168,7 +170,7 @@ function sendFileToVLC( const reqOptions: http.RequestOptions = { hostname: vlcHost, - port: 8888, + port: vlcPort, path: '/upload.json', method: 'POST', headers: form.getHeaders(), @@ -201,7 +203,7 @@ function sendFileToVLC( } app.post('/api/send', (req: Request, res: Response): void => { - const { ip, files } = req.body as SendRequest; + const { ip, port, files } = req.body as SendRequest; if (!ip || !files || !files.length) { res.status(400).json({ error: 'ip and files are required' }); @@ -215,6 +217,7 @@ app.post('/api/send', (req: Request, res: Response): void => { } const vlcHost = `${SUBNET_PREFIX}${ip}`; + const vlcPort = port && port > 0 && port <= 65535 ? port : 80; res.writeHead(200, { 'Content-Type': 'text/event-stream', @@ -251,7 +254,7 @@ app.post('/api/send', (req: Request, res: Response): void => { size: fileSize, }); - const result = await sendFileToVLC(file, vlcHost); + const result = await sendFileToVLC(file, vlcHost, vlcPort); completed++; sendProgress({ diff --git a/src/public/index.html b/src/public/index.html index ab2018d..cfd08f2 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -168,6 +168,8 @@
192.168.1. + : +
@@ -188,6 +190,7 @@ const sendBtn = document.getElementById('sendBtn'); const selectAllBtn = document.getElementById('selectAllBtn'); const selectedCount = document.getElementById('selectedCount'); + const portInput = document.getElementById('portInput'); const progressPanel = document.getElementById('progressPanel'); let currentPath = ''; @@ -195,14 +198,19 @@ let currentFiles = []; let sending = false; - // Restore last IP + // Restore last IP and port const savedIp = localStorage.getItem('vlc-ip'); if (savedIp) ipInput.value = savedIp; + const savedPort = localStorage.getItem('vlc-port'); + if (savedPort) portInput.value = savedPort; ipInput.addEventListener('input', () => { localStorage.setItem('vlc-ip', ipInput.value); updateSendBtn(); }); + portInput.addEventListener('input', () => { + localStorage.setItem('vlc-port', portInput.value); + }); function formatSize(bytes) { if (bytes === 0) return '0 B'; @@ -377,7 +385,8 @@ ''; }).join(''); - const body = JSON.stringify({ ip, files }); + const port = parseInt(portInput.value.trim(), 10) || 80; + const body = JSON.stringify({ ip, port, files }); fetch('/api/send', { method: 'POST', headers: { 'Content-Type': 'application/json' },