Good changes
This commit is contained in:
parent
d39d1b15fd
commit
1f68ca0512
23 changed files with 670 additions and 289 deletions
|
|
@ -3,8 +3,18 @@ import { ScreenshotCache } from './cache.js';
|
|||
import { takeScreenshot, checkWebGL, closeBrowser } from './screenshot.js';
|
||||
|
||||
const PORT = parseInt(process.env.PORT || '8002', 10);
|
||||
const APP_URL = process.env.APP_URL || 'http://localhost:8001';
|
||||
const CACHE_DIR = process.env.CACHE_DIR || '/cache';
|
||||
const APP_URL = process.env.APP_URL;
|
||||
const CACHE_DIR = process.env.CACHE_DIR;
|
||||
|
||||
if (!APP_URL) {
|
||||
console.error('Error: APP_URL environment variable is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!CACHE_DIR) {
|
||||
console.error('Error: CACHE_DIR environment variable is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const cache = new ScreenshotCache(CACHE_DIR);
|
||||
const app = express();
|
||||
|
|
@ -24,15 +34,26 @@ app.get('/debug', async (_req, res) => {
|
|||
|
||||
app.get('/screenshot', async (req, res) => {
|
||||
try {
|
||||
const params: Record<string, string> = {};
|
||||
for (const key of ['v', 'f', 'poi', 'tab', 'og']) {
|
||||
const qs = new URLSearchParams();
|
||||
for (const key of ['lat', 'lon', 'zoom', 'tab', 'og']) {
|
||||
const val = req.query[key];
|
||||
if (typeof val === 'string' && val) {
|
||||
params[key] = val;
|
||||
qs.set(key, val);
|
||||
}
|
||||
}
|
||||
// Repeated params: filter, poi
|
||||
for (const key of ['filter', 'poi']) {
|
||||
const val = req.query[key];
|
||||
if (typeof val === 'string' && val) {
|
||||
qs.append(key, val);
|
||||
} else if (Array.isArray(val)) {
|
||||
for (const v of val) {
|
||||
if (typeof v === 'string' && v) qs.append(key, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const cacheKey = cache.buildKey(params);
|
||||
const cacheKey = cache.buildKey(qs);
|
||||
|
||||
// Check cache first
|
||||
const cached = cache.get(cacheKey);
|
||||
|
|
@ -45,7 +66,6 @@ app.get('/screenshot', async (req, res) => {
|
|||
}
|
||||
|
||||
// Build the URL for the frontend in screenshot mode
|
||||
const qs = new URLSearchParams(params);
|
||||
qs.set('screenshot', '1');
|
||||
const url = `${APP_URL}/?${qs}`;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue