Merge pull request #51 from accius/Modular-Staging

Update server.js
pull/65/head
accius 2 days ago committed by GitHub
commit 121f32416a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4178,6 +4178,18 @@ app.post('/api/wsjtx/relay', (req, res) => {
res.json({ ok: true, processed, timestamp: Date.now() }); res.json({ ok: true, processed, timestamp: Date.now() });
}); });
// API endpoint: serve raw relay.js (used by Windows .bat launcher)
app.get('/api/wsjtx/relay/agent.js', (req, res) => {
const relayJsPath = path.join(__dirname, 'wsjtx-relay', 'relay.js');
try {
const content = fs.readFileSync(relayJsPath, 'utf8');
res.setHeader('Content-Type', 'application/javascript');
res.send(content);
} catch (e) {
res.status(500).json({ error: 'relay.js not found on server' });
}
});
// API endpoint: download pre-configured relay agent script // API endpoint: download pre-configured relay agent script
// Embeds relay.js + server URL + relay key into a one-file launcher // Embeds relay.js + server URL + relay key into a one-file launcher
app.get('/api/wsjtx/relay/download/:platform', (req, res) => { app.get('/api/wsjtx/relay/download/:platform', (req, res) => {
@ -4251,54 +4263,65 @@ app.get('/api/wsjtx/relay/download/:platform', (req, res) => {
return res.send(script); return res.send(script);
} else if (platform === 'windows') { } else if (platform === 'windows') {
// Build PowerShell script with relay.js embedded // Simple .bat that downloads relay.js then runs with node
const escapedJs = relayJs.replace(/'/g, "''"); // No PowerShell, no execution policy issues
const batLines = [
const lines = [ '@echo off',
'# OpenHamClock WSJT-X Relay - Auto-configured', 'title OpenHamClock WSJT-X Relay',
'# Generated by ' + serverURL, 'echo.',
'# Right-click > "Run with PowerShell" or run from terminal', 'echo =========================================',
'# Requires: Node.js 14+ (https://nodejs.org)', 'echo OpenHamClock WSJT-X Relay Agent v1.0',
'#', 'echo =========================================',
'# In WSJT-X: Settings > Reporting > UDP Server', 'echo.',
'# Address: 127.0.0.1 Port: 2237',
'', '',
'# Check for Node.js', ':: Check for Node.js',
'try {', 'where node >nul 2>nul',
' $nv = (node -v 2>$null)', 'if errorlevel 1 (',
' if (-not $nv) { throw "missing" }', ' echo Node.js is not installed!',
' Write-Host "Found Node.js $nv" -ForegroundColor Green', ' echo.',
'} catch {', ' echo Download it from: https://nodejs.org',
' Write-Host "Node.js is not installed." -ForegroundColor Red', ' echo Install the LTS version, then run this script again.',
' Write-Host "Download from https://nodejs.org (LTS version)" -ForegroundColor Yellow', ' echo.',
' Read-Host "Press Enter to exit"', ' pause',
' exit 1', ' exit /b 1',
'}', ')',
'', '',
'# Write relay agent to temp file', 'for /f "tokens=*" %%i in (\'node -v\') do echo Found Node.js %%i',
'$relayFile = Join-Path $env:TEMP "ohc-relay.js"', 'echo Server: ' + serverURL,
'echo.',
'', '',
"$relayCode = @'", ':: Download relay agent',
escapedJs, 'echo Downloading relay agent...',
"'@", 'powershell -Command "Invoke-WebRequest -Uri \'' + serverURL + '/api/wsjtx/relay/agent.js\' -OutFile \'%TEMP%\\ohc-relay.js\'"',
'if errorlevel 1 (',
' echo Failed to download relay agent!',
' echo Check your internet connection and try again.',
' echo.',
' pause',
' exit /b 1',
')',
'', '',
'$relayCode | Out-File -FilePath $relayFile -Encoding UTF8', 'echo Relay agent ready.',
'echo.',
'echo In WSJT-X: Settings ^> Reporting ^> UDP Server',
'echo Address: 127.0.0.1 Port: 2237',
'echo.',
'echo Press Ctrl+C to stop',
'echo.',
'', '',
'Write-Host "Starting WSJT-X relay agent..." -ForegroundColor Cyan', ':: Run relay',
'Write-Host "Press Ctrl+C to stop" -ForegroundColor DarkGray', 'node "%TEMP%\\ohc-relay.js" --url "' + serverURL + '" --key "' + WSJTX_RELAY_KEY + '"',
'Write-Host ""',
'', '',
'# Run relay', 'echo.',
'try {', 'echo Relay stopped.',
' node $relayFile --url "' + serverURL + '" --key "' + WSJTX_RELAY_KEY + '"', 'del "%TEMP%\\ohc-relay.js" >nul 2>nul',
'} finally {', 'echo.',
' Remove-Item $relayFile -ErrorAction SilentlyContinue', 'pause',
'}',
]; ];
const script = lines.join('\r\n') + '\r\n'; const script = batLines.join('\r\n') + '\r\n';
res.setHeader('Content-Type', 'application/x-powershell'); res.setHeader('Content-Type', 'application/x-msdos-program');
res.setHeader('Content-Disposition', 'attachment; filename="start-relay.ps1"'); res.setHeader('Content-Disposition', 'attachment; filename="start-relay.bat"');
return res.send(script); return res.send(script);
} else { } else {

Loading…
Cancel
Save

Powered by TurnKey Linux.