Skip to content

Commit b0a2645

Browse files
committed
Allow enabling special groups
1 parent 0068d36 commit b0a2645

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/utils/groupHandler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import config from "./config";
33
import log from "./logger";
44
import tleFetcher from "./tleFetcher";
55

6+
const SPECIAL_GROUPS = ["gpz", "gpz-plus", "decaying"];
7+
68
async function handleGroupRequest(group: string, lastFetchedHeader: number, format: "tle" | "json" | "csv") {
79
if (config.allowedGroups.includes(group) === false) {
810
return new Response(`Group "${group}" is not allowed.`, { status: 403 });
911
}
1012

13+
const queryType = SPECIAL_GROUPS.includes(group) ? "SPECIAL" : "GROUP";
1114
let timestamp = await kv.get(`${group}_timestamp_${format}`);
1215
const now = Date.now();
1316
const staleDuration = group === "active" ? config.cacheActiveDuration : config.cacheDuration;
@@ -22,13 +25,13 @@ async function handleGroupRequest(group: string, lastFetchedHeader: number, form
2225

2326
if (!tle) {
2427
log.debug(`No cached GP data for group "${group}", format "${format}". Fetching from Celestrak...`);
25-
tle = await tleFetcher(group, format);
28+
tle = await tleFetcher(group, format, queryType);
2629
timestamp = now;
2730
await kv.set(`${group}_${format}`, tle);
2831
await kv.set(`${group}_timestamp_${format}`, timestamp);
2932
} else if (isStale) {
3033
log.debug(`GP data for group "${group}", format "${format}" are stale. Fetching fresh TLEs...`);
31-
tle = await tleFetcher(group, format);
34+
tle = await tleFetcher(group, format, queryType);
3235
timestamp = now;
3336
await kv.set(`${group}_${format}`, tle);
3437
await kv.set(`${group}_timestamp_${format}`, timestamp);

src/utils/tleFetcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import kv from "./kv";
33

44
import { version } from "../../package.json";
55

6-
async function fetchTle(group: string, format: "tle" | "json" | "csv" = "tle"): Promise<string> {
7-
const url = `https://celestrak.org/NORAD/elements/gp.php?GROUP=${group}&FORMAT=${format}`;
6+
async function fetchTle(group: string, format: "tle" | "json" | "csv" = "tle", queryType: string = "GROUP"): Promise<string> {
7+
const url = `https://celestrak.org/NORAD/elements/gp.php?${queryType}=${group}&FORMAT=${format}`;
88
log.debug(`Fetching TLEs for group "${group}", format "${format}" from Celestrak...`);
99
try {
1010
const lastFetch = await kv.get(`${group}_timestamp_${format}`);

0 commit comments

Comments
 (0)