feat: add configurable VLC port in UI
This commit is contained in:
@@ -125,6 +125,7 @@ app.get('/api/files', (req: Request, res: Response): void => {
|
|||||||
|
|
||||||
interface SendRequest {
|
interface SendRequest {
|
||||||
ip: string;
|
ip: string;
|
||||||
|
port?: number;
|
||||||
files: string[];
|
files: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +144,7 @@ function resolveFilePath(filePath: string): string | null {
|
|||||||
function sendFileToVLC(
|
function sendFileToVLC(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
vlcHost: string,
|
vlcHost: string,
|
||||||
|
vlcPort: number,
|
||||||
): Promise<{ file: string; success: boolean; error?: string }> {
|
): Promise<{ file: string; success: boolean; error?: string }> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const resolved = resolveFilePath(filePath);
|
const resolved = resolveFilePath(filePath);
|
||||||
@@ -168,7 +170,7 @@ function sendFileToVLC(
|
|||||||
|
|
||||||
const reqOptions: http.RequestOptions = {
|
const reqOptions: http.RequestOptions = {
|
||||||
hostname: vlcHost,
|
hostname: vlcHost,
|
||||||
port: 8888,
|
port: vlcPort,
|
||||||
path: '/upload.json',
|
path: '/upload.json',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: form.getHeaders(),
|
headers: form.getHeaders(),
|
||||||
@@ -201,7 +203,7 @@ function sendFileToVLC(
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.post('/api/send', (req: Request, res: Response): void => {
|
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) {
|
if (!ip || !files || !files.length) {
|
||||||
res.status(400).json({ error: 'ip and files are required' });
|
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 vlcHost = `${SUBNET_PREFIX}${ip}`;
|
||||||
|
const vlcPort = port && port > 0 && port <= 65535 ? port : 80;
|
||||||
|
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Type': 'text/event-stream',
|
'Content-Type': 'text/event-stream',
|
||||||
@@ -251,7 +254,7 @@ app.post('/api/send', (req: Request, res: Response): void => {
|
|||||||
size: fileSize,
|
size: fileSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await sendFileToVLC(file, vlcHost);
|
const result = await sendFileToVLC(file, vlcHost, vlcPort);
|
||||||
completed++;
|
completed++;
|
||||||
|
|
||||||
sendProgress({
|
sendProgress({
|
||||||
|
|||||||
@@ -168,6 +168,8 @@
|
|||||||
<div class="ip-group">
|
<div class="ip-group">
|
||||||
<span>192.168.1.</span>
|
<span>192.168.1.</span>
|
||||||
<input type="text" id="ipInput" placeholder="___" maxlength="3" inputmode="numeric">
|
<input type="text" id="ipInput" placeholder="___" maxlength="3" inputmode="numeric">
|
||||||
|
<span>:</span>
|
||||||
|
<input type="text" id="portInput" placeholder="80" maxlength="5" inputmode="numeric" style="width:45px">
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-send" id="sendBtn" disabled>Отправить</button>
|
<button class="btn btn-send" id="sendBtn" disabled>Отправить</button>
|
||||||
<button class="btn btn-select" id="selectAllBtn">Выбрать все</button>
|
<button class="btn btn-select" id="selectAllBtn">Выбрать все</button>
|
||||||
@@ -188,6 +190,7 @@
|
|||||||
const sendBtn = document.getElementById('sendBtn');
|
const sendBtn = document.getElementById('sendBtn');
|
||||||
const selectAllBtn = document.getElementById('selectAllBtn');
|
const selectAllBtn = document.getElementById('selectAllBtn');
|
||||||
const selectedCount = document.getElementById('selectedCount');
|
const selectedCount = document.getElementById('selectedCount');
|
||||||
|
const portInput = document.getElementById('portInput');
|
||||||
const progressPanel = document.getElementById('progressPanel');
|
const progressPanel = document.getElementById('progressPanel');
|
||||||
|
|
||||||
let currentPath = '';
|
let currentPath = '';
|
||||||
@@ -195,14 +198,19 @@
|
|||||||
let currentFiles = [];
|
let currentFiles = [];
|
||||||
let sending = false;
|
let sending = false;
|
||||||
|
|
||||||
// Restore last IP
|
// Restore last IP and port
|
||||||
const savedIp = localStorage.getItem('vlc-ip');
|
const savedIp = localStorage.getItem('vlc-ip');
|
||||||
if (savedIp) ipInput.value = savedIp;
|
if (savedIp) ipInput.value = savedIp;
|
||||||
|
const savedPort = localStorage.getItem('vlc-port');
|
||||||
|
if (savedPort) portInput.value = savedPort;
|
||||||
|
|
||||||
ipInput.addEventListener('input', () => {
|
ipInput.addEventListener('input', () => {
|
||||||
localStorage.setItem('vlc-ip', ipInput.value);
|
localStorage.setItem('vlc-ip', ipInput.value);
|
||||||
updateSendBtn();
|
updateSendBtn();
|
||||||
});
|
});
|
||||||
|
portInput.addEventListener('input', () => {
|
||||||
|
localStorage.setItem('vlc-port', portInput.value);
|
||||||
|
});
|
||||||
|
|
||||||
function formatSize(bytes) {
|
function formatSize(bytes) {
|
||||||
if (bytes === 0) return '0 B';
|
if (bytes === 0) return '0 B';
|
||||||
@@ -377,7 +385,8 @@
|
|||||||
'</div>';
|
'</div>';
|
||||||
}).join('');
|
}).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', {
|
fetch('/api/send', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
Reference in New Issue
Block a user