Docker
This commit is contained in:
@@ -7,6 +7,7 @@ import { StravaRateLimitError } from './strava-rate-limit.error';
|
||||
import {
|
||||
StravaActivityPayload,
|
||||
StravaStreamPayload,
|
||||
StravaStreamsResponse,
|
||||
StravaTokenPayload,
|
||||
} from './strava.types';
|
||||
|
||||
@@ -84,15 +85,17 @@ export class StravaClientService {
|
||||
accessToken: string,
|
||||
stravaActivityId: string,
|
||||
): Promise<StravaStreamPayload[]> {
|
||||
return this.request<StravaStreamPayload[]>({
|
||||
const streams = await this.request<StravaStreamsResponse>({
|
||||
method: 'GET',
|
||||
url: `https://www.strava.com/api/v3/activities/${stravaActivityId}/streams`,
|
||||
headers: this.authHeaders(accessToken),
|
||||
params: {
|
||||
keys: 'time,distance,latlng,altitude,velocity_smooth,heartrate,cadence,watts,temp,moving,grade_smooth',
|
||||
key_by_type: false,
|
||||
key_by_type: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.normalizeStreamsResponse(streams);
|
||||
}
|
||||
|
||||
private async postToken(
|
||||
@@ -149,6 +152,22 @@ export class StravaClientService {
|
||||
return { Authorization: `Bearer ${accessToken}` };
|
||||
}
|
||||
|
||||
private normalizeStreamsResponse(
|
||||
streams: StravaStreamsResponse,
|
||||
): StravaStreamPayload[] {
|
||||
if (Array.isArray(streams)) {
|
||||
return streams;
|
||||
}
|
||||
|
||||
return Object.entries(streams).map(([type, stream]) => ({
|
||||
type: stream.type ?? type,
|
||||
data: Array.isArray(stream.data) ? stream.data : [],
|
||||
series_type: stream.series_type,
|
||||
original_size: stream.original_size,
|
||||
resolution: stream.resolution,
|
||||
}));
|
||||
}
|
||||
|
||||
private required(configService: ConfigService, key: string): string {
|
||||
const value = configService.get<string>(key);
|
||||
if (!value) {
|
||||
|
||||
Reference in New Issue
Block a user