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 {
|
||||
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({
|
||||
|
||||
@@ -168,6 +168,8 @@
|
||||
<div class="ip-group">
|
||||
<span>192.168.1.</span>
|
||||
<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>
|
||||
<button class="btn btn-send" id="sendBtn" disabled>Отправить</button>
|
||||
<button class="btn btn-select" id="selectAllBtn">Выбрать все</button>
|
||||
@@ -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 @@
|
||||
'</div>';
|
||||
}).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' },
|
||||
|
||||
Reference in New Issue
Block a user