mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
refactor: dedupe query string array parsing (#1592)
This commit is contained in:
9
server/_shared/parse-string-array.ts
Normal file
9
server/_shared/parse-string-array.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Defensive parser for repeated-string query params.
|
||||
* Some codegen paths may pass comma-separated strings into string[] fields.
|
||||
*/
|
||||
export function parseStringArray(raw: unknown): string[] {
|
||||
if (Array.isArray(raw)) return raw.filter(Boolean);
|
||||
if (typeof raw === 'string' && raw.length > 0) return raw.split(',').filter(Boolean);
|
||||
return [];
|
||||
}
|
||||
@@ -14,18 +14,7 @@ import {
|
||||
} from '../../../../src/config/airports';
|
||||
import { CHROME_UA } from '../../../_shared/constants';
|
||||
import { cachedFetchJson, getCachedJson } from '../../../_shared/redis';
|
||||
|
||||
/**
|
||||
* Defensive parser for repeated-string query params.
|
||||
* The sebuf codegen assigns `params.get("airports")` (a string) to a field
|
||||
* typed as `string[]`. At runtime `req.airports` may therefore be a
|
||||
* comma-separated string rather than an actual array.
|
||||
*/
|
||||
export function parseStringArray(raw: unknown): string[] {
|
||||
if (Array.isArray(raw)) return raw.filter(Boolean);
|
||||
if (typeof raw === 'string' && raw.length > 0) return raw.split(',').filter(Boolean);
|
||||
return [];
|
||||
}
|
||||
export { parseStringArray } from '../../../_shared/parse-string-array';
|
||||
|
||||
// ---------- Constants ----------
|
||||
|
||||
@@ -601,4 +590,3 @@ export function mergeNotamWithExistingAlert(
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { CHROME_UA, yahooGate } from '../../../_shared/constants';
|
||||
import cryptoConfig from '../../../../shared/crypto.json';
|
||||
import stablecoinConfig from '../../../../shared/stablecoins.json';
|
||||
export { parseStringArray } from '../../../_shared/parse-string-array';
|
||||
|
||||
// ========================================================================
|
||||
// Relay helpers (Railway proxy for Yahoo when Vercel IPs are rate-limited)
|
||||
@@ -37,18 +38,6 @@ export function sanitizeSymbol(raw: string): string {
|
||||
return raw.trim().replace(/\s+/g, '').slice(0, 32).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defensive parser for repeated-string query params.
|
||||
* The sebuf codegen assigns `params.get("symbols")` (a string) to a field
|
||||
* typed as `string[]`. At runtime `req.symbols` may therefore be a
|
||||
* comma-separated string rather than an actual array.
|
||||
*/
|
||||
export function parseStringArray(raw: unknown): string[] {
|
||||
if (Array.isArray(raw)) return raw.filter(Boolean);
|
||||
if (typeof raw === 'string' && raw.length > 0) return raw.split(',').filter(Boolean);
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function fetchYahooQuotesBatch(
|
||||
symbols: string[],
|
||||
): Promise<{ results: Map<string, { price: number; change: number; sparkline: number[] }>; rateLimited: boolean }> {
|
||||
|
||||
Reference in New Issue
Block a user