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 @@