Files
TREK/client/src/api/journeyRecordings.ts
T
Maurice ede109dce8 feat(journey): complete sharing, photo drafts and Studio maps
Connect the Journey backend to the web and mobile UI, including public access and subscriptions, day recordings, photo drafts and per-map framing. Preserve legacy recording responses and cover the new behavior in every locale.
2026-11-30 16:56:18 +01:00

61 lines
2.9 KiB
TypeScript

import type {
JourneyDayImportRequest,
JourneyDayImportResult,
JourneyDayStays,
JourneyGpxImportOptions,
JourneyGpxImportResult,
JourneyRecordedDaysResponse,
JourneyRecordingPrep,
JourneyRecordingPreview,
JourneyRecordingPreviewRequest,
JourneyRecordingSaveRequest,
JourneyRecordingSaveResult,
JourneyRecordingSource,
} from '@trek/shared';
import apiClient, { postMultipart } from './client';
import { DAWARICH_UPSTREAM_TIMEOUT_MS } from './dawarich';
const base = (journeyId: number) => `/journeys/${journeyId}/recordings`;
/** The preview and the save ask Dawarich first, so they get its longer wait. */
const upstream = { timeout: DAWARICH_UPSTREAM_TIMEOUT_MS };
/**
* JRN-01: the recorded days a journey keeps, previewing one, keeping it and dropping it.
* JRN-02: the stays of a day reviewed and taken over as drafts.
* JRN-03: how the journey prepares its days for the caller.
* #3085: the days read from a GPX file, and dropping a day of one source.
*/
export const journeyRecordingsApi = {
list: (journeyId: number, signal?: AbortSignal): Promise<JourneyRecordedDaysResponse> =>
apiClient.get(base(journeyId), { signal, params: { includeGpx: true } }).then((r) => r.data),
prep: (journeyId: number, signal?: AbortSignal): Promise<JourneyRecordingPrep> =>
apiClient.get(`${base(journeyId)}/prep`, { signal }).then((r) => r.data),
preview: (
journeyId: number,
body: JourneyRecordingPreviewRequest,
signal?: AbortSignal
): Promise<JourneyRecordingPreview> =>
apiClient.post(`${base(journeyId)}/preview`, body, { ...upstream, signal }).then((r) => r.data),
save: (journeyId: number, date: string, body: JourneyRecordingSaveRequest): Promise<JourneyRecordingSaveResult> =>
apiClient.put(`${base(journeyId)}/${date}`, body, upstream).then((r) => r.data),
/** Without a source the Dawarich day goes, as it always did. */
remove: (journeyId: number, date: string, source?: JourneyRecordingSource): Promise<void> =>
apiClient.delete(`${base(journeyId)}/${date}`, source ? { params: { source } } : undefined).then(() => undefined),
importGpx: (
journeyId: number,
file: Blob,
options: JourneyGpxImportOptions = {}
): Promise<JourneyGpxImportResult> => {
const fd = new FormData();
fd.append('file', file);
if (options.date) fd.append('date', options.date);
if (options.utcOffsetMinutes !== undefined) fd.append('utcOffsetMinutes', String(options.utcOffsetMinutes));
return postMultipart(`${base(journeyId)}/import-gpx`, fd);
},
reviewDay: (journeyId: number, date: string, signal?: AbortSignal): Promise<JourneyDayStays> =>
apiClient.post(`${base(journeyId)}/${date}/stays/review`, {}, { ...upstream, signal }).then((r) => r.data),
takeOverDay: (journeyId: number, date: string, body: JourneyDayImportRequest): Promise<JourneyDayImportResult> =>
apiClient.post(`${base(journeyId)}/${date}/stays/import`, body).then((r) => r.data),
};