1
0

Ooops forgot to commit

This commit is contained in:
2025-11-25 12:20:00 -05:00
parent 4964211254
commit 5209e8cf26
7 changed files with 407 additions and 67 deletions

View File

@@ -7,6 +7,10 @@ const app = express();
const PORT = process.env.PORT || 3000;
const WS4KP_PORT = process.env.WS4KP_PORT || 8080;
const MUSIC_PATH = process.env.MUSIC_PATH || '/music';
const DEFAULT_FPS = parseInt(process.env.DEFAULT_FPS || '30');
const SCREENSHOT_FORMAT = process.env.SCREENSHOT_FORMAT || 'jpeg';
const SCREENSHOT_QUALITY = parseInt(process.env.SCREENSHOT_QUALITY || '95');
const DEBUG_MODE = process.env.DEBUG_MODE === 'true';
/**
* Build WS4KP weather URL with given coordinates and settings
@@ -77,15 +81,19 @@ function buildWeatherUrl(latitude, longitude, settings) {
return `${ws4kpBaseUrl}/?${ws4kpParams.toString()}`;
}
// Basic stream endpoint (with optional music parameter)
// Basic stream endpoint (with optional music and scroll parameters)
app.get('/stream', (req, res) => {
const { music = 'false' } = req.query;
const { music = 'false', debug = DEBUG_MODE ? 'true' : 'false' } = req.query;
const useMusic = music === 'true';
const startTime = Date.now();
streamHandler(req, res, {
useMusic,
musicPath: MUSIC_PATH,
startTime
startTime,
defaultFps: DEFAULT_FPS,
screenshotFormat: SCREENSHOT_FORMAT,
screenshotQuality: SCREENSHOT_QUALITY,
debugMode: debug === 'true'
});
});
@@ -134,28 +142,18 @@ app.get('/weather', async (req, res) => {
};
let lateGeocodePromise = null;
let geocodeDataPromise = null;
let initialUrl = 'data:text/html,<html><body style="margin:0;padding:0;background:#000"></body></html>';
if (city && city !== 'Toronto, ON, CAN') {
// Start geocoding (only call once)
// Start geocoding in background - don't wait for it
const geocodePromise = geocodeCity(city);
geocodeDataPromise = geocodePromise; // Save for city name overlay
// Try to use quick result if available within 1 second
const quickResult = Promise.race([
geocodePromise,
new Promise((_, reject) => setTimeout(() => reject(new Error('Geocoding timeout')), 1000))
]).catch(() => null); // Timeout = null, will use late result
// Always start with black screen immediately
initialUrl = 'data:text/html,<html><body style="margin:0;padding:0;background:#000"></body></html>';
// Build URL from quick result if available
const urlPromise = quickResult.then(geoResult => {
if (geoResult) {
// Got quick result
return buildWeatherUrl(geoResult.lat, geoResult.lon, weatherSettings);
}
return null; // Will use initial black screen
});
// Late geocode promise (reuses the same geocode call)
// Late geocode promise will load the actual weather page
lateGeocodePromise = geocodePromise.then(geoResult => {
return buildWeatherUrl(geoResult.lat, geoResult.lon, weatherSettings);
}).catch(err => {
@@ -166,6 +164,8 @@ app.get('/weather', async (req, res) => {
} else {
// Toronto default
initialUrl = buildWeatherUrl(43.6532, -79.3832, weatherSettings);
// Create resolved promise with Toronto data
geocodeDataPromise = Promise.resolve({ cityName: 'Toronto' });
}
const startTime = Date.now();
@@ -178,11 +178,17 @@ app.get('/weather', async (req, res) => {
req.query.hideLogo = hideLogo;
// Call stream handler with music enabled
const { debug = DEBUG_MODE ? 'true' : 'false' } = req.query;
return streamHandler(req, res, {
useMusic: true,
musicPath: MUSIC_PATH,
lateGeocodePromise,
startTime
geocodeDataPromise,
startTime,
defaultFps: DEFAULT_FPS,
screenshotFormat: SCREENSHOT_FORMAT,
screenshotQuality: SCREENSHOT_QUALITY,
debugMode: debug === 'true'
});
});
@@ -197,7 +203,11 @@ app.listen(PORT, () => {
if (process.env.WS4KP_EXTERNAL_PORT) {
console.log(`WS4KP weather service on port ${process.env.WS4KP_EXTERNAL_PORT}`);
}
console.log(`Usage: http://localhost:${PORT}/stream?url=http://example.com`);
console.log(`\nConfiguration:`);
console.log(` Default FPS: ${DEFAULT_FPS}`);
console.log(` Screenshot Format: ${SCREENSHOT_FORMAT}`);
console.log(` Screenshot Quality: ${SCREENSHOT_QUALITY}${SCREENSHOT_FORMAT === 'jpeg' ? '%' : ' (ignored for PNG)'}`);
console.log(`\nUsage: http://localhost:${PORT}/stream?url=http://example.com`);
console.log(`Weather: http://localhost:${PORT}/weather?city=YourCity`);
// Pre-validate music files on startup to cache results