incyclist-services 1.9.24 → 1.9.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/api/rest/RestApiClient.js +5 -2
- package/lib/cjs/api/rest/api.js +25 -4
- package/lib/cjs/apps/base/api/base.js +2 -2
- package/lib/cjs/apps/base/api/strava/api.js +81 -3
- package/lib/cjs/apps/base/api/strava/consts.js +35 -0
- package/lib/cjs/apps/base/api/types.js +2 -0
- package/lib/cjs/apps/base/app/index.js +3 -0
- package/lib/cjs/apps/strava/StravaAppConnection.js +2 -2
- package/lib/cjs/ride/route/RLVDisplayService.js +2 -2
- package/lib/cjs/routes/base/parsers/gpx.js +5 -0
- package/lib/cjs/routes/list/service.js +1 -1
- package/lib/cjs/routes/sync/base/provider.js +217 -0
- package/lib/cjs/routes/sync/index.js +1 -0
- package/lib/cjs/routes/sync/komoot/provider.js +143 -335
- package/lib/cjs/routes/sync/strava/provider.js +128 -0
- package/lib/esm/api/rest/RestApiClient.js +5 -2
- package/lib/esm/api/rest/api.js +25 -4
- package/lib/esm/apps/base/api/base.js +2 -2
- package/lib/esm/apps/base/api/strava/api.js +81 -3
- package/lib/esm/apps/base/api/strava/consts.js +32 -0
- package/lib/esm/apps/base/api/types.js +1 -0
- package/lib/esm/apps/base/app/index.js +3 -0
- package/lib/esm/apps/strava/StravaAppConnection.js +2 -2
- package/lib/esm/ride/route/RLVDisplayService.js +2 -2
- package/lib/esm/routes/base/parsers/gpx.js +5 -0
- package/lib/esm/routes/list/service.js +1 -1
- package/lib/esm/routes/sync/base/provider.js +214 -0
- package/lib/esm/routes/sync/index.js +1 -0
- package/lib/esm/routes/sync/komoot/provider.js +143 -336
- package/lib/esm/routes/sync/strava/provider.js +124 -0
- package/lib/types/api/rest/RestApiClient.d.ts +1 -1
- package/lib/types/api/rest/api.d.ts +5 -0
- package/lib/types/apps/base/api/base.d.ts +1 -1
- package/lib/types/apps/base/api/intervals/api.d.ts +2 -1
- package/lib/types/apps/base/api/komoot/api.d.ts +2 -1
- package/lib/types/apps/base/api/strava/api.d.ts +15 -8
- package/lib/types/apps/base/api/strava/consts.d.ts +5 -0
- package/lib/types/apps/base/api/strava/types.d.ts +101 -0
- package/lib/types/apps/base/api/types.d.ts +3 -0
- package/lib/types/apps/base/app/index.d.ts +1 -0
- package/lib/types/apps/base/types.d.ts +1 -0
- package/lib/types/apps/types.d.ts +1 -0
- package/lib/types/routes/base/parsers/gpx.d.ts +1 -0
- package/lib/types/routes/sync/base/provider.d.ts +48 -0
- package/lib/types/routes/sync/index.d.ts +1 -0
- package/lib/types/routes/sync/komoot/provider.d.ts +11 -37
- package/lib/types/routes/sync/strava/provider.d.ts +20 -0
- package/lib/types/routes/sync/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,50 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
-
var useValue = arguments.length > 2;
|
|
4
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
-
}
|
|
7
|
-
return useValue ? value : void 0;
|
|
8
|
-
};
|
|
9
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
-
var _, done = false;
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
-
var context = {};
|
|
17
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
-
if (kind === "accessor") {
|
|
22
|
-
if (result === void 0) continue;
|
|
23
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
-
}
|
|
28
|
-
else if (_ = accept(result)) {
|
|
29
|
-
if (kind === "field") initializers.unshift(_);
|
|
30
|
-
else descriptor[key] = _;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
-
done = true;
|
|
35
|
-
};
|
|
36
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
3
|
exports.KomootSyncProvider = void 0;
|
|
38
|
-
const apps_1 = require("../../../apps");
|
|
39
4
|
const komoot_1 = require("../../../apps/komoot");
|
|
40
|
-
const decorators_1 = require("../../../base/decorators");
|
|
41
|
-
const service_1 = require("../../../base/service");
|
|
42
|
-
const types_1 = require("../../../base/types");
|
|
43
|
-
const settings_1 = require("../../../settings");
|
|
44
|
-
const utils_1 = require("../../../utils");
|
|
45
5
|
const geo_1 = require("../../../utils/geo");
|
|
46
6
|
const sleep_1 = require("../../../utils/sleep");
|
|
47
|
-
const
|
|
7
|
+
const provider_1 = require("../base/provider");
|
|
48
8
|
const factory_1 = require("../factory");
|
|
49
9
|
const PAGE_LIMIT = 50;
|
|
50
10
|
const SPORTS_FILTER = 'racebike';
|
|
@@ -55,315 +15,163 @@ const sportsOptions = {
|
|
|
55
15
|
mtb_easy: 'Gravel riding',
|
|
56
16
|
mtb_advancde: 'Enduro mountain biking'
|
|
57
17
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_getRouteListService_decorators = [decorators_1.Injectable];
|
|
72
|
-
_getRouteSyncFactory_decorators = [decorators_1.Injectable];
|
|
73
|
-
_getKomootApi_decorators = [decorators_1.Injectable];
|
|
74
|
-
_getKomootAppConnection_decorators = [decorators_1.Injectable];
|
|
75
|
-
_getAppsService_decorators = [decorators_1.Injectable];
|
|
76
|
-
__esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
77
|
-
__esDecorate(this, null, _getRouteListService_decorators, { kind: "method", name: "getRouteListService", static: false, private: false, access: { has: obj => "getRouteListService" in obj, get: obj => obj.getRouteListService }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
78
|
-
__esDecorate(this, null, _getRouteSyncFactory_decorators, { kind: "method", name: "getRouteSyncFactory", static: false, private: false, access: { has: obj => "getRouteSyncFactory" in obj, get: obj => obj.getRouteSyncFactory }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
79
|
-
__esDecorate(this, null, _getKomootApi_decorators, { kind: "method", name: "getKomootApi", static: false, private: false, access: { has: obj => "getKomootApi" in obj, get: obj => obj.getKomootApi }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
80
|
-
__esDecorate(this, null, _getKomootAppConnection_decorators, { kind: "method", name: "getKomootAppConnection", static: false, private: false, access: { has: obj => "getKomootAppConnection" in obj, get: obj => obj.getKomootAppConnection }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
81
|
-
__esDecorate(this, null, _getAppsService_decorators, { kind: "method", name: "getAppsService", static: false, private: false, access: { has: obj => "getAppsService" in obj, get: obj => obj.getAppsService }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
82
|
-
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
83
|
-
}
|
|
84
|
-
lastSyncTS = __runInitializers(this, _instanceExtraInitializers);
|
|
85
|
-
observer;
|
|
86
|
-
stopRequested;
|
|
87
|
-
constructor() {
|
|
88
|
-
super('KomootSync');
|
|
89
|
-
}
|
|
90
|
-
sync() {
|
|
91
|
-
if (this.observer)
|
|
92
|
-
return this.observer;
|
|
93
|
-
this.observer = new types_1.Observer();
|
|
94
|
-
this.observer.once('done', () => {
|
|
95
|
-
(0, utils_1.waitNextTick)().then(() => {
|
|
96
|
-
this.stopRequested = false;
|
|
97
|
-
delete this.observer;
|
|
98
|
-
}).catch(err => { this.logError(err, 'sync'); });
|
|
99
|
-
});
|
|
100
|
-
this.observer.once('stop', () => { this.stopSync(); });
|
|
101
|
-
this.loadTours().catch(err => { this.logError(err, 'sync'); });
|
|
102
|
-
return this.observer;
|
|
18
|
+
class KomootSyncProvider extends provider_1.BaseSyncProvider {
|
|
19
|
+
constructor() {
|
|
20
|
+
super('KomootSync');
|
|
21
|
+
}
|
|
22
|
+
async loadDetails(route) {
|
|
23
|
+
try {
|
|
24
|
+
this.logEvent({ message: 'load route details', id: route?.description?.id, title: route?.description?.title });
|
|
25
|
+
const id = this.getOriginalId(route);
|
|
26
|
+
if (!id)
|
|
27
|
+
return;
|
|
28
|
+
const coordinates = await this.getApi().getTourCoordinates(Number(id));
|
|
29
|
+
await this.adddRouteDetails(route, coordinates);
|
|
30
|
+
return route;
|
|
103
31
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const connected = this.getKomootAppConnection().isConnected();
|
|
109
|
-
return connected;
|
|
32
|
+
catch (err) {
|
|
33
|
+
this.logError(err, 'loadDetails', { id: route?.description?.id, title: route?.description?.title });
|
|
110
34
|
}
|
|
111
|
-
|
|
35
|
+
}
|
|
36
|
+
async loadRoutesFromApi() {
|
|
37
|
+
const api = this.getApi();
|
|
38
|
+
let page = 0;
|
|
39
|
+
let done = false;
|
|
40
|
+
let error = false;
|
|
41
|
+
const routes = [];
|
|
42
|
+
while (!done && !this.stopRequested) {
|
|
112
43
|
try {
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
44
|
+
const filters = { sport: this.getSportFilter(), after: this.getCreatedFilter() };
|
|
45
|
+
const pageTours = await api.getTours({ type: 'tour_planned', page, limit: PAGE_LIMIT }, filters);
|
|
46
|
+
if (pageTours.length > 0) {
|
|
47
|
+
routes.push(...pageTours);
|
|
48
|
+
page++;
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
done = true;
|
|
52
|
+
await (0, sleep_1.sleep)(100);
|
|
120
53
|
}
|
|
121
54
|
catch (err) {
|
|
122
|
-
this.
|
|
55
|
+
this.logEvent({ message: 'could not load routes', reason: err.message });
|
|
56
|
+
done = true;
|
|
57
|
+
error = true;
|
|
123
58
|
}
|
|
124
59
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
let page = 0;
|
|
169
|
-
let done = false;
|
|
170
|
-
const tours = [];
|
|
171
|
-
while (!done && !this.stopRequested) {
|
|
172
|
-
try {
|
|
173
|
-
const filters = { sport: this.getSportFilter(), after: this.getCreatedFilter() };
|
|
174
|
-
const pageTours = await api.getTours({ type: 'tour_planned', page, limit: PAGE_LIMIT }, filters);
|
|
175
|
-
if (pageTours.length > 0) {
|
|
176
|
-
tours.push(...pageTours);
|
|
177
|
-
page++;
|
|
178
|
-
}
|
|
179
|
-
else
|
|
180
|
-
done = true;
|
|
181
|
-
await (0, sleep_1.sleep)(100);
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
184
|
-
this.logEvent({ message: 'could not load tours', reason: err.message });
|
|
185
|
-
done = true;
|
|
186
|
-
}
|
|
60
|
+
return { routes, done, error };
|
|
61
|
+
}
|
|
62
|
+
buildRouteInfo(tour) {
|
|
63
|
+
const info = {
|
|
64
|
+
hasGpx: true,
|
|
65
|
+
hasVideo: false,
|
|
66
|
+
id: 'komoot:' + tour.id,
|
|
67
|
+
title: tour.name,
|
|
68
|
+
elevation: tour.elevation_up,
|
|
69
|
+
distance: tour.distance,
|
|
70
|
+
category: 'external',
|
|
71
|
+
source: 'komoot',
|
|
72
|
+
previewUrl: tour.vector_map_image_preview?.src,
|
|
73
|
+
tsLastChange: (new Date(tour.changed_at)).valueOf()
|
|
74
|
+
};
|
|
75
|
+
return info;
|
|
76
|
+
}
|
|
77
|
+
async adddRouteDetails(route, coordinates) {
|
|
78
|
+
const points = this.buildRoutePoints(coordinates, []);
|
|
79
|
+
const last = points.at(-1);
|
|
80
|
+
const first = points[0];
|
|
81
|
+
const totalDistance = last.routeDistance;
|
|
82
|
+
const totalElevation = last.elevationGain;
|
|
83
|
+
const descr = route.description;
|
|
84
|
+
if (descr.distance !== totalDistance)
|
|
85
|
+
descr.distance = totalDistance;
|
|
86
|
+
if (descr.elevation !== totalElevation)
|
|
87
|
+
descr.elevation = totalElevation;
|
|
88
|
+
descr.isLoop = ((0, geo_1.calculateDistance)(first.lat, first.lng, last.lat, last.lng) < 50);
|
|
89
|
+
route.addDetails({
|
|
90
|
+
id: descr.id,
|
|
91
|
+
title: descr.title,
|
|
92
|
+
points,
|
|
93
|
+
country: descr.country,
|
|
94
|
+
distance: descr.distance,
|
|
95
|
+
elevation: descr.elevation,
|
|
96
|
+
category: descr.category,
|
|
97
|
+
});
|
|
98
|
+
if (!descr.country && route.points?.length > 0) {
|
|
99
|
+
this.logEvent({ message: 'route update required (country)', route: route.title });
|
|
100
|
+
const updated = await route.updateCountryFromPoints();
|
|
101
|
+
if (updated) {
|
|
102
|
+
this.logEvent({ message: 'route updated (country)', route: route.title, country: route.description?.country });
|
|
187
103
|
}
|
|
188
|
-
return { tours, done };
|
|
189
104
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const tourTS = (new Date(tour.changed_at)).valueOf();
|
|
212
|
-
if (tourTS > routeTS) {
|
|
213
|
-
const description = this.buildRouteInfo(tour);
|
|
214
|
-
updated.push(new route_1.Route(description));
|
|
215
|
-
}
|
|
105
|
+
descr.points = points;
|
|
106
|
+
}
|
|
107
|
+
buildRoutePoints(coordinates, points) {
|
|
108
|
+
const num = coordinates?.length;
|
|
109
|
+
if (!num)
|
|
110
|
+
return;
|
|
111
|
+
let routeDistance = 0;
|
|
112
|
+
let elevationGain = 0;
|
|
113
|
+
let prevPoint;
|
|
114
|
+
let cnt = 0;
|
|
115
|
+
try {
|
|
116
|
+
for (let i = 0; i < num; i++) {
|
|
117
|
+
const p = coordinates[i];
|
|
118
|
+
const prev = i > 0 ? coordinates[i - 1] : undefined;
|
|
119
|
+
let distance = 0, gain = 0;
|
|
120
|
+
if (i > 0) {
|
|
121
|
+
distance = (0, geo_1.calculateDistance)(p.lat, p.lng, prev.lat, prev.lng);
|
|
122
|
+
gain = p.alt - prev.alt;
|
|
123
|
+
routeDistance = routeDistance + distance;
|
|
124
|
+
if (gain > 0)
|
|
125
|
+
elevationGain += gain;
|
|
216
126
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const deleted = unmatched.map(r => r.id);
|
|
220
|
-
this.emitUpdates(added, updated, deleted);
|
|
221
|
-
return { added, updated, deleted };
|
|
222
|
-
}
|
|
223
|
-
buildRouteInfo(tour) {
|
|
224
|
-
const info = {
|
|
225
|
-
hasGpx: true,
|
|
226
|
-
hasVideo: false,
|
|
227
|
-
id: 'komoot:' + tour.id,
|
|
228
|
-
title: tour.name,
|
|
229
|
-
elevation: tour.elevation_up,
|
|
230
|
-
distance: tour.distance,
|
|
231
|
-
category: 'external',
|
|
232
|
-
source: 'komoot',
|
|
233
|
-
previewUrl: tour.vector_map_image_preview?.src,
|
|
234
|
-
tsLastChange: (new Date(tour.changed_at)).valueOf()
|
|
235
|
-
};
|
|
236
|
-
return info;
|
|
237
|
-
}
|
|
238
|
-
async adddRouteDetails(route, coordinates) {
|
|
239
|
-
const points = this.buildRoutePoints(coordinates, []);
|
|
240
|
-
const last = points.at(-1);
|
|
241
|
-
const first = points[0];
|
|
242
|
-
const totalDistance = last.routeDistance;
|
|
243
|
-
const totalElevation = last.elevationGain;
|
|
244
|
-
const descr = route.description;
|
|
245
|
-
if (descr.distance !== totalDistance)
|
|
246
|
-
descr.distance = totalDistance;
|
|
247
|
-
if (descr.elevation !== totalElevation)
|
|
248
|
-
descr.elevation = totalElevation;
|
|
249
|
-
descr.isLoop = ((0, geo_1.calculateDistance)(first.lat, first.lng, last.lat, last.lng) < 50);
|
|
250
|
-
route.addDetails({
|
|
251
|
-
id: descr.id,
|
|
252
|
-
title: descr.title,
|
|
253
|
-
points,
|
|
254
|
-
country: descr.country,
|
|
255
|
-
distance: descr.distance,
|
|
256
|
-
elevation: descr.elevation,
|
|
257
|
-
category: descr.category,
|
|
258
|
-
});
|
|
259
|
-
if (!descr.country) {
|
|
260
|
-
this.logEvent({ message: 'route update required (country)', route: route.title });
|
|
261
|
-
const updated = await route.updateCountryFromPoints();
|
|
262
|
-
if (updated) {
|
|
263
|
-
this.logEvent({ message: 'route updated (country)', route: route.title, country: route.description?.country });
|
|
127
|
+
if (distance == 0 && i > 0) {
|
|
128
|
+
continue;
|
|
264
129
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
for (let i = 0; i < num; i++) {
|
|
278
|
-
const p = coordinates[i];
|
|
279
|
-
const prev = i > 0 ? coordinates[i - 1] : undefined;
|
|
280
|
-
let distance = 0, gain = 0;
|
|
281
|
-
if (i > 0) {
|
|
282
|
-
distance = (0, geo_1.calculateDistance)(p.lat, p.lng, prev.lat, prev.lng);
|
|
283
|
-
gain = p.alt - prev.alt;
|
|
284
|
-
routeDistance = routeDistance + distance;
|
|
285
|
-
if (gain > 0)
|
|
286
|
-
elevationGain += gain;
|
|
287
|
-
}
|
|
288
|
-
if (distance == 0 && i > 0) {
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
const point = {
|
|
292
|
-
lat: p.lat,
|
|
293
|
-
lng: p.lng,
|
|
294
|
-
slope: 0,
|
|
295
|
-
elevation: p.alt,
|
|
296
|
-
elevationGain,
|
|
297
|
-
distance,
|
|
298
|
-
routeDistance,
|
|
299
|
-
cnt
|
|
300
|
-
};
|
|
301
|
-
if (i > 0) {
|
|
302
|
-
prevPoint.slope = gain / distance * 100;
|
|
303
|
-
}
|
|
304
|
-
points.push(point);
|
|
305
|
-
prevPoint = point;
|
|
306
|
-
cnt++;
|
|
130
|
+
const point = {
|
|
131
|
+
lat: p.lat,
|
|
132
|
+
lng: p.lng,
|
|
133
|
+
slope: 0,
|
|
134
|
+
elevation: p.alt,
|
|
135
|
+
elevationGain,
|
|
136
|
+
distance,
|
|
137
|
+
routeDistance,
|
|
138
|
+
cnt
|
|
139
|
+
};
|
|
140
|
+
if (i > 0) {
|
|
141
|
+
prevPoint.slope = gain / distance * 100;
|
|
307
142
|
}
|
|
143
|
+
points.push(point);
|
|
144
|
+
prevPoint = point;
|
|
145
|
+
cnt++;
|
|
308
146
|
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
this.logError(err, 'buildRoutePoints');
|
|
311
|
-
}
|
|
312
|
-
return points;
|
|
313
|
-
}
|
|
314
|
-
emitAdded(tours) {
|
|
315
|
-
this.observer.emit('added', tours.map(tour => this.buildRouteInfo(tour)));
|
|
316
|
-
}
|
|
317
|
-
emitUpdated(routes) {
|
|
318
|
-
this.observer.emit('updated', routes);
|
|
319
|
-
}
|
|
320
|
-
emitDeleted(routes) {
|
|
321
|
-
this.observer.emit('deleted', routes);
|
|
322
|
-
}
|
|
323
|
-
getLastSyncTime() {
|
|
324
|
-
const lastSyncTS = this.lastSyncTS ?? 0;
|
|
325
|
-
this.lastSyncTS = Math.max(lastSyncTS, this.getUserSettings().get('apps.komoot.lastSync', lastSyncTS));
|
|
326
|
-
return this.lastSyncTS > 0 ? new Date(this.lastSyncTS) : undefined;
|
|
327
|
-
}
|
|
328
|
-
getSportFilter() {
|
|
329
|
-
return SPORTS_FILTER;
|
|
330
|
-
}
|
|
331
|
-
getAvailableSports() {
|
|
332
|
-
const keys = Object.keys(sportsOptions);
|
|
333
|
-
return keys.map(sport => sportsOptions[sport]);
|
|
334
147
|
}
|
|
335
|
-
|
|
336
|
-
|
|
148
|
+
catch (err) {
|
|
149
|
+
this.logError(err, 'buildRoutePoints');
|
|
337
150
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
getAppsService() {
|
|
363
|
-
return (0, apps_1.useAppsService)();
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
})();
|
|
151
|
+
return points;
|
|
152
|
+
}
|
|
153
|
+
getAppId;
|
|
154
|
+
getSportFilter() {
|
|
155
|
+
return SPORTS_FILTER;
|
|
156
|
+
}
|
|
157
|
+
getAvailableSports() {
|
|
158
|
+
const keys = Object.keys(sportsOptions);
|
|
159
|
+
return keys.map(sport => sportsOptions[sport]);
|
|
160
|
+
}
|
|
161
|
+
getRouteSyncSummary(route) {
|
|
162
|
+
return {
|
|
163
|
+
id: route.id.toString(),
|
|
164
|
+
lastUpdate: route.changed_at,
|
|
165
|
+
creation: route.date
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
getApi() {
|
|
169
|
+
return this.getConnection().getApi();
|
|
170
|
+
}
|
|
171
|
+
getConnection() {
|
|
172
|
+
return new komoot_1.KomootAppConnection();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
367
175
|
exports.KomootSyncProvider = KomootSyncProvider;
|
|
368
176
|
const factory = new factory_1.RouteSyncFactory();
|
|
369
177
|
factory.add('komoot', new KomootSyncProvider());
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StravaSyncProvider = void 0;
|
|
4
|
+
const apps_1 = require("../../../apps");
|
|
5
|
+
const provider_1 = require("../base/provider");
|
|
6
|
+
const gpx_1 = require("../../base/parsers/gpx");
|
|
7
|
+
const geo_1 = require("../../../utils/geo");
|
|
8
|
+
const factory_1 = require("../factory");
|
|
9
|
+
const sleep_1 = require("../../../utils/sleep");
|
|
10
|
+
const PAGE_LIMIT = 50;
|
|
11
|
+
const SPORTS_FILTER = 'ride';
|
|
12
|
+
class StravaSyncProvider extends provider_1.BaseSyncProvider {
|
|
13
|
+
constructor() {
|
|
14
|
+
super('StravaSync');
|
|
15
|
+
}
|
|
16
|
+
async loadDetails(route) {
|
|
17
|
+
try {
|
|
18
|
+
this.logEvent({ message: 'load route details', id: route?.description?.id, title: route?.description?.title });
|
|
19
|
+
const id = this.getOriginalId(route);
|
|
20
|
+
if (!id)
|
|
21
|
+
return;
|
|
22
|
+
const gpxContent = await this.getApi().getRouteAsGPX(id);
|
|
23
|
+
if (typeof gpxContent == 'string') {
|
|
24
|
+
await this.addRouteDetails(route, gpxContent);
|
|
25
|
+
return route;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const error = gpxContent.error;
|
|
29
|
+
throw new Error(error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
this.logError(err, 'loadDetails', { id: route?.description?.id, title: route?.description?.title });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async loadRoutesFromApi() {
|
|
37
|
+
const api = this.getApi();
|
|
38
|
+
let page = 1;
|
|
39
|
+
let done = false;
|
|
40
|
+
let error = false;
|
|
41
|
+
const routes = [];
|
|
42
|
+
while (!done && !this.stopRequested) {
|
|
43
|
+
try {
|
|
44
|
+
const filters = { sport: this.getSportFilter() };
|
|
45
|
+
const pageRoutes = await api.getLoggedInAthleteRoutes({ page, per_page: PAGE_LIMIT }, filters);
|
|
46
|
+
if (Array.isArray(pageRoutes) && pageRoutes.length > 0) {
|
|
47
|
+
routes.push(...pageRoutes);
|
|
48
|
+
page++;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
done = true;
|
|
52
|
+
}
|
|
53
|
+
await (0, sleep_1.sleep)(100);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
this.logEvent({ message: 'could not load tours', reason: err.message });
|
|
57
|
+
done = true;
|
|
58
|
+
error = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { routes, done, error };
|
|
62
|
+
}
|
|
63
|
+
async addRouteDetails(route, gpx) {
|
|
64
|
+
const parser = new gpx_1.GPXParser();
|
|
65
|
+
const parsed = await parser.parseFromString(gpx);
|
|
66
|
+
const points = parsed.details.points;
|
|
67
|
+
const last = points.at(-1);
|
|
68
|
+
const first = points[0];
|
|
69
|
+
const totalDistance = last.routeDistance;
|
|
70
|
+
const totalElevation = last.elevationGain;
|
|
71
|
+
const descr = route.description;
|
|
72
|
+
if (descr.distance !== totalDistance)
|
|
73
|
+
descr.distance = totalDistance;
|
|
74
|
+
if (descr.elevation !== totalElevation)
|
|
75
|
+
descr.elevation = totalElevation;
|
|
76
|
+
descr.isLoop = ((0, geo_1.calculateDistance)(first.lat, first.lng, last.lat, last.lng) < 50);
|
|
77
|
+
route.addDetails({
|
|
78
|
+
id: descr.id,
|
|
79
|
+
title: descr.title,
|
|
80
|
+
points,
|
|
81
|
+
country: descr.country,
|
|
82
|
+
distance: descr.distance,
|
|
83
|
+
elevation: descr.elevation,
|
|
84
|
+
category: descr.category,
|
|
85
|
+
});
|
|
86
|
+
if (!descr.country && route.points?.length > 0) {
|
|
87
|
+
this.logEvent({ message: 'route update required (country)', route: route.title });
|
|
88
|
+
const updated = await route.updateCountryFromPoints();
|
|
89
|
+
if (updated) {
|
|
90
|
+
this.logEvent({ message: 'route updated (country)', route: route.title, country: route.description?.country });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
descr.points = points;
|
|
94
|
+
}
|
|
95
|
+
getSportFilter() {
|
|
96
|
+
return SPORTS_FILTER;
|
|
97
|
+
}
|
|
98
|
+
getRouteSyncSummary(route) {
|
|
99
|
+
return {
|
|
100
|
+
id: route.id_str ?? route.id?.toString(),
|
|
101
|
+
lastUpdate: route.updated_at,
|
|
102
|
+
creation: route.created_at
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
buildRouteInfo(route) {
|
|
106
|
+
const info = {
|
|
107
|
+
hasGpx: true,
|
|
108
|
+
hasVideo: false,
|
|
109
|
+
id: 'strava:' + (route.id_str ?? route.id?.toString()),
|
|
110
|
+
title: route.name,
|
|
111
|
+
elevation: route.elevation_gain,
|
|
112
|
+
distance: route.distance,
|
|
113
|
+
category: 'external',
|
|
114
|
+
source: 'strava',
|
|
115
|
+
tsLastChange: (new Date(route.updated_at)).valueOf()
|
|
116
|
+
};
|
|
117
|
+
return info;
|
|
118
|
+
}
|
|
119
|
+
getApi() {
|
|
120
|
+
return this.getConnection().getApi();
|
|
121
|
+
}
|
|
122
|
+
getConnection() {
|
|
123
|
+
return new apps_1.StravaAppConnection();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.StravaSyncProvider = StravaSyncProvider;
|
|
127
|
+
const factory = new factory_1.RouteSyncFactory();
|
|
128
|
+
factory.add('strava', new StravaSyncProvider());
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ApiClient } from './api';
|
|
2
2
|
export class RestApiClient {
|
|
3
3
|
static _api;
|
|
4
|
-
static getClient() {
|
|
5
|
-
|
|
4
|
+
static getClient(enableLogging) {
|
|
5
|
+
const api = this.api();
|
|
6
|
+
if (enableLogging)
|
|
7
|
+
api.enableLogging();
|
|
8
|
+
return api.client();
|
|
6
9
|
}
|
|
7
10
|
static api() {
|
|
8
11
|
if (!this._api)
|