@@ -3,11 +3,14 @@ import config from "./config";
33import log from "./logger" ;
44import tleFetcher from "./tleFetcher" ;
55
6+ const SPECIAL_GROUPS = [ "gpz" , "gpz-plus" , "decaying" ] ;
7+
68async 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 ) ;
0 commit comments