refactor: separate regional briefing and weather sources

This commit is contained in:
Sameh Khamis committed 2026-09-12 12:59:39 -07:00
1 parent 213edd80ce
commit 318d37ad8d
11 files changed
+475 -348

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { readResponseJsonCapped, readResponseTextCapped } from '../common/http.js';
const REGIONAL_MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
async function fetchRegionalJson(url, {
headers = {},
timeoutMs = 9000,
maxBytes = REGIONAL_MAX_RESPONSE_BYTES,
} = {}) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs);
try {
const response = await fetch(url, { signal: controller.signal, headers });
if (!response.ok) throw new Error(`Upstream returned ${response.status}`);
return readResponseJsonCapped(response, maxBytes);
} finally {
clearTimeout(timeout);
}
}
async function fetchRegionalText(url, {
headers = {},
timeoutMs = 9000,
maxBytes = REGIONAL_MAX_RESPONSE_BYTES,
} = {}) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs);
try {
const response = await fetch(url, { signal: controller.signal, headers });
if (!response.ok) throw new Error(`Upstream returned ${response.status}`);
return readResponseTextCapped(response, maxBytes);
} finally {
clearTimeout(timeout);
}
}
export { fetchRegionalJson, fetchRegionalText };