incyclist-services 1.9.6 → 1.9.8
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/api.js +7 -3
- package/lib/cjs/api/rest/external.js +26 -0
- package/lib/cjs/apps/googleMaps/service.js +2 -0
- package/lib/cjs/apps/service.js +4 -1
- package/lib/cjs/devices/pairing/service.js +0 -1
- package/lib/cjs/i18n/countries/service.js +2 -2
- package/lib/cjs/routes/base/api/api.js +196 -0
- package/lib/cjs/routes/base/api/factory.js +93 -0
- package/lib/cjs/routes/base/api/index.js +14 -184
- package/lib/cjs/routes/base/parsers/tacx/TacxParser.js +1 -1
- package/lib/cjs/routes/free-ride/service.js +41 -0
- package/lib/cjs/routes/list/loaders/DBLoader.js +0 -1
- package/lib/cjs/routes/list/loaders/api.js +270 -176
- package/lib/cjs/routes/list/service.js +401 -357
- package/lib/cjs/settings/display/ride/service.js +18 -2
- package/lib/cjs/ui/service.js +1 -2
- package/lib/cjs/utils/string.js +21 -1
- package/lib/esm/api/rest/api.js +7 -3
- package/lib/esm/api/rest/external.js +22 -0
- package/lib/esm/api/rest/incyclist copy.js +33 -0
- package/lib/esm/apps/googleMaps/service.js +2 -0
- package/lib/esm/apps/service.js +4 -1
- package/lib/esm/devices/configuration/model/add/index.js +1 -0
- package/lib/esm/devices/configuration/model/exclusion/index.js +1 -0
- package/lib/esm/devices/pairing/capability.js +1 -0
- package/lib/esm/devices/pairing/service.js +0 -1
- package/lib/esm/i18n/countries/service.js +2 -2
- package/lib/esm/routes/base/api/api.js +194 -0
- package/lib/esm/routes/base/api/factory.js +86 -0
- package/lib/esm/routes/base/api/index.js +2 -186
- package/lib/esm/routes/base/parsers/tacx/TacxParser.js +1 -1
- package/lib/esm/routes/free-ride/service.js +41 -0
- package/lib/esm/routes/list/loaders/DBLoader.js +0 -1
- package/lib/esm/routes/list/loaders/api.js +272 -174
- package/lib/esm/routes/list/service.js +401 -357
- package/lib/esm/settings/display/ride/service.js +18 -2
- package/lib/esm/ui/service.js +2 -3
- package/lib/esm/utils/string.js +18 -0
- package/lib/types/api/rest/api.d.ts +2 -2
- package/lib/types/api/rest/external.d.ts +7 -0
- package/lib/types/api/rest/incyclist copy.d.ts +7 -0
- package/lib/types/api/rest/types.d.ts +5 -3
- package/lib/types/apps/service.d.ts +1 -0
- package/lib/types/devices/configuration/model/add/index.d.ts +10 -0
- package/lib/types/devices/configuration/model/exclusion/index.d.ts +19 -0
- package/lib/types/devices/pairing/capability.d.ts +10 -0
- package/lib/types/routes/base/api/api.d.ts +23 -0
- package/lib/types/routes/base/api/factory.d.ts +7 -0
- package/lib/types/routes/base/api/index.d.ts +2 -26
- package/lib/types/routes/base/api/types.d.ts +10 -0
- package/lib/types/routes/base/parsers/tacx/TacxParser.d.ts +1 -1
- package/lib/types/routes/base/types/index.d.ts +1 -0
- package/lib/types/routes/free-ride/service.d.ts +6 -0
- package/lib/types/routes/list/loaders/api.d.ts +6 -3
- package/lib/types/routes/list/service.d.ts +37 -29
- package/lib/types/settings/display/ride/service.d.ts +8 -2
- package/lib/types/settings/display/ride/types.d.ts +5 -0
- package/lib/types/utils/string.d.ts +2 -0
- package/package.json +1 -1
|
@@ -48,6 +48,8 @@ const settings_1 = require("../../settings");
|
|
|
48
48
|
const geo_1 = require("../../utils/geo");
|
|
49
49
|
const utils_2 = require("../../utils");
|
|
50
50
|
const clone_1 = __importDefault(require("../../utils/clone"));
|
|
51
|
+
const INIT_RETRY = 15 * 1000;
|
|
52
|
+
const MAX_RETRIES = 1;
|
|
51
53
|
let FreeRideService = (() => {
|
|
52
54
|
let _classDecorators = [types_1.Singleton];
|
|
53
55
|
let _classDescriptor;
|
|
@@ -76,13 +78,43 @@ let FreeRideService = (() => {
|
|
|
76
78
|
options;
|
|
77
79
|
currentSegment;
|
|
78
80
|
lastOptionsQueryValid = true;
|
|
81
|
+
initialized = false;
|
|
82
|
+
ivInit;
|
|
83
|
+
cntInitRetry = 0;
|
|
79
84
|
constructor() {
|
|
80
85
|
super('FreeRide');
|
|
81
86
|
this.options = [];
|
|
82
87
|
}
|
|
88
|
+
init() {
|
|
89
|
+
this.logEvent({ message: 'init free ride service' });
|
|
90
|
+
this.selectStartPosition()
|
|
91
|
+
.catch(err => {
|
|
92
|
+
this.logError(err, 'init');
|
|
93
|
+
})
|
|
94
|
+
.finally(() => {
|
|
95
|
+
this.logEvent({ message: 'init free ride service result', success: this.initialized });
|
|
96
|
+
this.ivInit = setInterval(() => {
|
|
97
|
+
if (this.cntInitRetry < MAX_RETRIES) {
|
|
98
|
+
this.cntInitRetry++;
|
|
99
|
+
this.logEvent({ message: 'init free ride service retry' });
|
|
100
|
+
this.selectStartPosition().catch(err => { this.logError(err, 'init'); });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
clearInterval(this.ivInit);
|
|
104
|
+
delete this.ivInit;
|
|
105
|
+
}
|
|
106
|
+
}, INIT_RETRY);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
isInitialized() {
|
|
110
|
+
return this.initialized;
|
|
111
|
+
}
|
|
83
112
|
async selectStartPosition(position) {
|
|
84
113
|
this.setStartPosition(position);
|
|
85
114
|
const map = await this.getMapArea().load(this.startPosition);
|
|
115
|
+
if (!this.initialized && map) {
|
|
116
|
+
this.setInitialized();
|
|
117
|
+
}
|
|
86
118
|
await this.getStartOptions(map);
|
|
87
119
|
return this.getRouteDefinitionDisplayProps();
|
|
88
120
|
}
|
|
@@ -133,6 +165,15 @@ let FreeRideService = (() => {
|
|
|
133
165
|
this.emit('segment-update', segment);
|
|
134
166
|
this.logEvent({ message: 'current segment changed', segment: this.buildId(this.selectedOption) });
|
|
135
167
|
}
|
|
168
|
+
setInitialized() {
|
|
169
|
+
this.initialized = true;
|
|
170
|
+
if (this.ivInit) {
|
|
171
|
+
clearInterval(this.ivInit);
|
|
172
|
+
delete this.ivInit;
|
|
173
|
+
this.logEvent({ message: 'init free ride service success' });
|
|
174
|
+
}
|
|
175
|
+
this.emit('initialized');
|
|
176
|
+
}
|
|
136
177
|
getOption(option) {
|
|
137
178
|
return (this.options ?? []).find(o => o.ui?.id === option.id);
|
|
138
179
|
}
|
|
@@ -6,7 +6,6 @@ const api_1 = require("../../../api");
|
|
|
6
6
|
const observer_1 = require("../../../base/types/observer");
|
|
7
7
|
const route_1 = require("../../base/model/route");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
|
-
const DETAILS_PRELOAD_CNT = 20;
|
|
10
9
|
class DBLoader extends types_1.Loader {
|
|
11
10
|
routeDescriptions;
|
|
12
11
|
videosRepo;
|
|
@@ -1,18 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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;
|
|
4
35
|
};
|
|
5
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
37
|
exports.RoutesApiLoader = void 0;
|
|
7
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
8
39
|
const observer_1 = require("../../../base/types/observer");
|
|
9
|
-
const api_1 = __importDefault(require("../../base/api"));
|
|
10
40
|
const route_1 = require("../../base/model/route");
|
|
11
41
|
const route_2 = require("../../base/utils/route");
|
|
12
42
|
const db_1 = require("./db");
|
|
13
43
|
const types_1 = require("./types");
|
|
14
44
|
const sleep_1 = require("../../../utils/sleep");
|
|
15
45
|
const settleWithLimit_1 = require("../../../utils/settleWithLimit");
|
|
46
|
+
const decorators_1 = require("../../../base/decorators");
|
|
47
|
+
const factory_1 = require("../../base/api/factory");
|
|
48
|
+
const settings_1 = require("../../../settings");
|
|
49
|
+
const utils_1 = require("../../../utils");
|
|
16
50
|
const ROUTE_DETAILS_CONCURRENCY = 4;
|
|
17
51
|
const valid = (v) => (v !== undefined && v !== null);
|
|
18
52
|
class ApiError extends Error {
|
|
@@ -34,192 +68,252 @@ const ExistingAndNotUpdated = (existing, descr) => {
|
|
|
34
68
|
return ((existing.version || 0) >= (descr.version || 0))
|
|
35
69
|
&& (!isDeleted || (isDeleted && existing.isDownloaded));
|
|
36
70
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
let RoutesApiLoader = (() => {
|
|
72
|
+
let _classSuper = types_1.Loader;
|
|
73
|
+
let _instanceExtraInitializers = [];
|
|
74
|
+
let _getIncyclistRoutesApi_decorators;
|
|
75
|
+
let _getUserSettings_decorators;
|
|
76
|
+
return class RoutesApiLoader extends _classSuper {
|
|
77
|
+
static {
|
|
78
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
79
|
+
_getIncyclistRoutesApi_decorators = [decorators_1.Injectable];
|
|
80
|
+
_getUserSettings_decorators = [decorators_1.Injectable];
|
|
81
|
+
__esDecorate(this, null, _getIncyclistRoutesApi_decorators, { kind: "method", name: "getIncyclistRoutesApi", static: false, private: false, access: { has: obj => "getIncyclistRoutesApi" in obj, get: obj => obj.getIncyclistRoutesApi }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
82
|
+
__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);
|
|
83
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
84
|
+
}
|
|
85
|
+
api = __runInitializers(this, _instanceExtraInitializers);
|
|
86
|
+
saveObserver;
|
|
87
|
+
logger;
|
|
88
|
+
processed = [];
|
|
89
|
+
constructor() {
|
|
90
|
+
super();
|
|
91
|
+
this.api = this.getIncyclistRoutesApi().create();
|
|
92
|
+
this.logger = new gd_eventlog_1.EventLogger('RoutesApi');
|
|
93
|
+
}
|
|
94
|
+
load() {
|
|
95
|
+
this.processed = [];
|
|
96
|
+
if (this.loadObserver)
|
|
97
|
+
return this.loadObserver;
|
|
98
|
+
const enrichApi = (v, type) => ({ type, ...v });
|
|
99
|
+
const api = [
|
|
100
|
+
this.api.getRouteDescriptions({ type: 'gpx' }, true).then(v => v.map(e => enrichApi(e, 'gpx'))).catch(error => { throw new ApiError(error, 'gpx'); }),
|
|
101
|
+
this.api.getRouteDescriptions({ type: 'video' }, true).then(v => v.map(e => enrichApi(e, 'video'))).catch(error => { throw new ApiError(error, 'video'); }),
|
|
102
|
+
];
|
|
103
|
+
this.loadObserver = new observer_1.Observer();
|
|
104
|
+
Promise.allSettled(api).then(async (res) => {
|
|
105
|
+
await this.onLoadDone(api, res);
|
|
106
|
+
}).catch(err => { this.logger.logEvent({ message: 'could not process route list load', error: err.message }); });
|
|
107
|
+
const external = this.getExternalRouteServers();
|
|
108
|
+
const promises = [];
|
|
109
|
+
if (external.length) {
|
|
110
|
+
for (const externalApi of external) {
|
|
111
|
+
promises.push(externalApi.getRouteDescriptions({ type: 'video' }, true).then(v => v.map(e => enrichApi(e, 'video'))).catch(error => { throw new ApiError(error, 'video'); }));
|
|
112
|
+
}
|
|
113
|
+
Promise.allSettled(promises).then(async (res) => {
|
|
114
|
+
await this.onLoadDone(api, res, true);
|
|
115
|
+
}).catch(err => { this.logger.logEvent({ message: 'could not process route list load', error: err.message }); });
|
|
116
|
+
}
|
|
48
117
|
return this.loadObserver;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
async processRouteFromApi(descr, items) {
|
|
82
|
-
let description;
|
|
83
|
-
const existing = this.getDescriptionFromDB(descr.routeId ?? descr.id);
|
|
84
|
-
if (ExistingAndNotUpdated(existing, descr)) {
|
|
85
|
-
const details = await this.getDetailsFromDB(existing.id);
|
|
86
|
-
if (details) {
|
|
87
|
-
return;
|
|
118
|
+
}
|
|
119
|
+
getExternalRouteServers() {
|
|
120
|
+
const externalConfig = this.getUserSettings().getValue('routes.servers', null);
|
|
121
|
+
const apis = [];
|
|
122
|
+
if (!externalConfig)
|
|
123
|
+
return apis;
|
|
124
|
+
Object.keys(externalConfig).forEach(key => {
|
|
125
|
+
const baseUrl = externalConfig[key];
|
|
126
|
+
this.logger.logEvent({ message: 'adding external route server', key, url: baseUrl });
|
|
127
|
+
const api = this.getIncyclistRoutesApi().create(key);
|
|
128
|
+
apis.push(api);
|
|
129
|
+
});
|
|
130
|
+
return apis;
|
|
131
|
+
}
|
|
132
|
+
async onLoadDone(api, res, isExternal = false) {
|
|
133
|
+
const loadDetailRequired = [];
|
|
134
|
+
for (let i = 0; i < res.length; i++) {
|
|
135
|
+
const p = res[i];
|
|
136
|
+
if (p.status !== 'fulfilled') {
|
|
137
|
+
this.logger.logEvent({ message: 'could not load route list', reason: p.reason?.message, type: p.reason?.type });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
for (let j = 0; j < p.value.length; j++) {
|
|
141
|
+
if (isExternal && this.processed.includes(p.value[j].id))
|
|
142
|
+
continue;
|
|
143
|
+
await this.processRouteFromApi(p.value[j], loadDetailRequired);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.loadObserver.emit('loaded');
|
|
147
|
+
if (loadDetailRequired.length > 0) {
|
|
148
|
+
await this.loadDetails(loadDetailRequired, true);
|
|
88
149
|
}
|
|
89
|
-
|
|
90
|
-
|
|
150
|
+
this.loadObserver.emit('done');
|
|
151
|
+
await (0, sleep_1.sleep)(1);
|
|
152
|
+
this.loadObserver.stop();
|
|
153
|
+
delete this.loadObserver;
|
|
91
154
|
}
|
|
92
|
-
|
|
93
|
-
description
|
|
94
|
-
|
|
95
|
-
|
|
155
|
+
async processRouteFromApi(descr, items) {
|
|
156
|
+
let description;
|
|
157
|
+
const existing = this.getDescriptionFromDB(descr.routeId ?? descr.id);
|
|
158
|
+
const alreadyProcessed = this.processed.includes(descr.routeId ?? descr.id);
|
|
159
|
+
if (alreadyProcessed)
|
|
96
160
|
return;
|
|
161
|
+
if (ExistingAndNotUpdated(existing, descr)) {
|
|
162
|
+
this.processed.push(existing.id);
|
|
163
|
+
const details = await this.getDetailsFromDB(existing.id);
|
|
164
|
+
if (details) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
description = existing;
|
|
168
|
+
this.logger.logEvent({ message: 'route details missing', id: description.id, title: description.title });
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
description = this.buildRouteInfo(descr);
|
|
172
|
+
if (!description) {
|
|
173
|
+
this.logger.logEvent({ message: 'invalid route', descr });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
this.processed.push(descr.id);
|
|
177
|
+
if (!existing) {
|
|
178
|
+
this.logger.logEvent({ message: 'route added', id: description.id, title: description.title, ts: description.tsImported });
|
|
179
|
+
description.tsImported = Date.now();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
description.tsImported = existing.tsImported;
|
|
183
|
+
items.push({ route: new route_1.Route(description), added: false });
|
|
184
|
+
this.logger.logEvent({ message: 'route updated', id: description.id, title: description.title, from: existing.version, to: description.version, ts: Date.now(), tsImported: description.tsImported });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.emitAndPrepareLoadDetails(description, items, existing);
|
|
188
|
+
}
|
|
189
|
+
emitAndPrepareLoadDetails(description, items, existing) {
|
|
190
|
+
const route = new route_1.Route(description);
|
|
191
|
+
const isComplete = this.isCompleted(route);
|
|
192
|
+
if (isComplete) {
|
|
193
|
+
this.verifyRouteHash(route);
|
|
97
194
|
}
|
|
98
195
|
if (!existing) {
|
|
99
|
-
this.
|
|
100
|
-
|
|
196
|
+
this.emitRouteAdded(route);
|
|
197
|
+
items.push({ route, added: true });
|
|
198
|
+
if (isComplete) {
|
|
199
|
+
this.save(route, false).catch(err => { this.logger.logEvent({ message: 'could not save route', id: route.description.id, error: err.message }); });
|
|
200
|
+
}
|
|
101
201
|
}
|
|
102
202
|
else {
|
|
103
|
-
description.
|
|
104
|
-
|
|
105
|
-
|
|
203
|
+
this.save(route, true).catch(err => { this.logger.logEvent({ message: 'could not save route', id: route.description.id, error: err.message }); });
|
|
204
|
+
if (!isComplete)
|
|
205
|
+
items.push({ route, added: false });
|
|
106
206
|
}
|
|
107
207
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
208
|
+
stopLoad() {
|
|
209
|
+
this.loadObserver?.stop();
|
|
210
|
+
delete this.loadObserver;
|
|
211
|
+
}
|
|
212
|
+
getDescriptionFromDB(id) {
|
|
213
|
+
const db = new db_1.RoutesDbLoader();
|
|
214
|
+
return db.getDescription(id);
|
|
215
|
+
}
|
|
216
|
+
async getDetailsFromDB(id) {
|
|
217
|
+
const db = new db_1.RoutesDbLoader();
|
|
218
|
+
return await db.getDetails(id);
|
|
219
|
+
}
|
|
220
|
+
async save(route, enforcedWriteDetails = false) {
|
|
221
|
+
const db = new db_1.RoutesDbLoader();
|
|
222
|
+
await db.save(route, enforcedWriteDetails);
|
|
223
|
+
}
|
|
224
|
+
isCompleted(route) {
|
|
225
|
+
const descr = route.description;
|
|
226
|
+
if (descr.hasVideo) {
|
|
227
|
+
return valid(descr.points) && (valid(descr.videoUrl) || (descr.requiresDownload && valid(descr.downloadUrl)));
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return valid(descr.points);
|
|
121
231
|
}
|
|
122
232
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
items.push({ route, added: false });
|
|
233
|
+
isPreviewMissing(route) {
|
|
234
|
+
const descr = route.description;
|
|
235
|
+
return descr?.hasVideo && !descr?.previewUrl;
|
|
127
236
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
getDescriptionFromDB(id) {
|
|
134
|
-
const db = new db_1.RoutesDbLoader();
|
|
135
|
-
return db.getDescription(id);
|
|
136
|
-
}
|
|
137
|
-
async getDetailsFromDB(id) {
|
|
138
|
-
const db = new db_1.RoutesDbLoader();
|
|
139
|
-
return await db.getDetails(id);
|
|
140
|
-
}
|
|
141
|
-
async save(route, enforcedWriteDetails = false) {
|
|
142
|
-
const db = new db_1.RoutesDbLoader();
|
|
143
|
-
await db.save(route, enforcedWriteDetails);
|
|
144
|
-
}
|
|
145
|
-
isCompleted(route) {
|
|
146
|
-
const descr = route.description;
|
|
147
|
-
if (descr.hasVideo) {
|
|
148
|
-
return valid(descr.points) && (valid(descr.videoUrl) || (descr.requiresDownload && valid(descr.downloadUrl)));
|
|
237
|
+
async loadDetailsFromRepo(items) {
|
|
238
|
+
const promises = items.map(i => this.getDetailsFromDB(i.route.description.id).then(details => { (0, route_2.addDetails)(i.route, details); }));
|
|
239
|
+
const res = await Promise.allSettled(promises);
|
|
240
|
+
const { failed } = await this.processLoadDetailsResult(res, items, false);
|
|
241
|
+
return failed;
|
|
149
242
|
}
|
|
150
|
-
|
|
151
|
-
|
|
243
|
+
async loadDetails(items, enforced = false) {
|
|
244
|
+
try {
|
|
245
|
+
const isUnique = (v, i, a) => {
|
|
246
|
+
return a.findIndex(item => item.route.description.id === v.route.description.id) === i;
|
|
247
|
+
};
|
|
248
|
+
items = items.filter((v, i, a) => isUnique(v, i, a));
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
this.logger.logEvent({ message: 'error', fn: 'loadDetails#unique', error: err.message, stack: err.stack });
|
|
252
|
+
}
|
|
253
|
+
const failed = enforced ? items : await this.loadDetailsFromRepo(items);
|
|
254
|
+
const res = await (0, settleWithLimit_1.settleWithLimit)(failed, ROUTE_DETAILS_CONCURRENCY, i => this.getDetails(i.route));
|
|
255
|
+
await this.processLoadDetailsResult(res, items, true);
|
|
152
256
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (video) {
|
|
216
|
-
data.hasVideo = true;
|
|
217
|
-
if (video.format)
|
|
218
|
-
data.videoFormat = video.format;
|
|
219
|
-
if (video.url && !data.videoUrl)
|
|
220
|
-
data.videoUrl = video.url;
|
|
221
|
-
}
|
|
222
|
-
return data;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
257
|
+
async processLoadDetailsResult(res, items, save) {
|
|
258
|
+
const success = [];
|
|
259
|
+
const failed = [];
|
|
260
|
+
res.forEach((pr, idx) => {
|
|
261
|
+
if (pr.status === 'fulfilled')
|
|
262
|
+
success.push(items[idx]);
|
|
263
|
+
else
|
|
264
|
+
failed.push(items[idx]);
|
|
265
|
+
});
|
|
266
|
+
for (const element of success) {
|
|
267
|
+
const item = element;
|
|
268
|
+
this.emitRouteEvents(true, item.route);
|
|
269
|
+
await this.verifyCountry(item.route);
|
|
270
|
+
this.verifyRouteHash(item.route);
|
|
271
|
+
if (save)
|
|
272
|
+
this.save(item.route, true).catch(err => { this.logger.logEvent({ message: 'could not save route', id: item.route?.description?.id, error: err.message }); });
|
|
273
|
+
}
|
|
274
|
+
return { success, failed };
|
|
275
|
+
}
|
|
276
|
+
async getDetails(route) {
|
|
277
|
+
let api = this.api;
|
|
278
|
+
if (route.description.apiServer) {
|
|
279
|
+
api = this.getIncyclistRoutesApi().create(route.description.apiServer);
|
|
280
|
+
}
|
|
281
|
+
const details = await api.getRouteDetails(route.description.legacyId || route.description.id);
|
|
282
|
+
(0, route_2.addDetails)(route, details);
|
|
283
|
+
}
|
|
284
|
+
buildRouteInfo(descr, isLocal) {
|
|
285
|
+
const { id, routeId, title, localizedTitle, country, distance, elevation, category, provider, video, requiresDownload, points, previewUrl, downloadUrl, routeHash, version, isDeleted, apiServer } = descr;
|
|
286
|
+
const data = { title, localizedTitle, country, distance, elevation, provider, category, previewUrl, requiresDownload, downloadUrl, routeHash, version, isDeleted };
|
|
287
|
+
data.hasVideo = false;
|
|
288
|
+
data.hasGpx = false;
|
|
289
|
+
data.isLocal = isLocal || false;
|
|
290
|
+
data.id = routeId || id;
|
|
291
|
+
data.legacyId = routeId ? id : undefined;
|
|
292
|
+
this.updateRouteCountry(data, { descr });
|
|
293
|
+
this.updateRouteTitle(data, { descr });
|
|
294
|
+
if (points)
|
|
295
|
+
data.hasGpx = true;
|
|
296
|
+
if (category?.toLowerCase() === 'demo')
|
|
297
|
+
data.isDemo = true;
|
|
298
|
+
if (video) {
|
|
299
|
+
data.hasVideo = true;
|
|
300
|
+
if (video.format)
|
|
301
|
+
data.videoFormat = video.format;
|
|
302
|
+
if (video.url && !data.videoUrl)
|
|
303
|
+
data.videoUrl = video.url;
|
|
304
|
+
}
|
|
305
|
+
if (apiServer) {
|
|
306
|
+
data.apiServer = apiServer;
|
|
307
|
+
data.source = (0, utils_1.pascalCase)(apiServer);
|
|
308
|
+
}
|
|
309
|
+
return data;
|
|
310
|
+
}
|
|
311
|
+
getIncyclistRoutesApi() {
|
|
312
|
+
return (0, factory_1.useIncyclistRoutesApi)();
|
|
313
|
+
}
|
|
314
|
+
getUserSettings() {
|
|
315
|
+
return (0, settings_1.useUserSettings)();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
})();
|
|
225
319
|
exports.RoutesApiLoader = RoutesApiLoader;
|