mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-06 03:14:00 +00:00
refactor: separate regional briefing and weather sources
This commit is contained in:
1 parent
213edd80ce
commit
318d37ad8d
11 files changed
+475
-348
No files matched your search
@@ -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 };
|
||||
Reference in new issue
Block a user