refactor: dedupe query string array parsing (#1592)

This commit is contained in:
Elie Habib
2026-03-14 20:48:34 +04:00
committed by GitHub
parent 047ab0dfa1
commit 1eb8fab7cf
3 changed files with 11 additions and 25 deletions

View 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 [];
}

View File

@@ -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(),
};
}

View File

@@ -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 }> {