added tracking feature(not tested)

This commit is contained in:
Vasilisk9812 2026-05-23 13:04:06 +09:00
parent 7a2278a42e
commit ea61e157ab
8 changed files with 309 additions and 25 deletions

View file

@ -1,4 +1,5 @@
export { api, ApiError, API_BASE_URL, setUnauthorizedHandler } from './client';
export { telemetryApi, buildWsUrl, type RawTelemetryPacket } from './telemetry';
export { pointsApi } from './points';
export { profilesApi } from './profiles';
export { scenariosApi } from './scenarios';

35
src/lib/api/telemetry.ts Normal file
View file

@ -0,0 +1,35 @@
import { api, API_BASE_URL } from './client';
export interface RawTelemetryPacket {
id: string;
timestamp: number; // unix seconds
lat: number;
lon: number;
alt: number;
payload: Record<string, unknown>;
raw_data: Record<string, unknown>;
}
/** Derives a WebSocket URL from the configured API base URL. */
export function buildWsUrl(satelliteId: string): string {
let base = API_BASE_URL;
if (!base.startsWith('http')) {
base = `${window.location.protocol}//${window.location.host}${base}`;
}
const url = new URL(base);
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
return `${url.origin}${url.pathname}/ws/satellite/${satelliteId}/telemetry/`;
}
export const telemetryApi = {
fetchHistory: async (
satelliteId: string,
params?: { from?: number; till?: number },
): Promise<RawTelemetryPacket[]> => {
const res = await api.get<RawTelemetryPacket[] | { results: RawTelemetryPacket[] }>(
`/${satelliteId}/telemetry/`,
{ query: params },
);
return Array.isArray(res) ? res : res.results;
},
};