incyclist-services 1.8.0 → 1.8.2

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.
Files changed (48) hide show
  1. package/lib/cjs/activities/ride/service.js +17 -3
  2. package/lib/cjs/routes/base/api/index.js +6 -2
  3. package/lib/cjs/routes/download/service.js +8 -0
  4. package/lib/cjs/routes/index.js +2 -0
  5. package/lib/cjs/routes/library/errors.js +52 -0
  6. package/lib/cjs/routes/library/index.js +18 -0
  7. package/lib/cjs/routes/library/service.js +390 -191
  8. package/lib/cjs/routes/list/cards/RouteCard.js +19 -5
  9. package/lib/cjs/routes/list/detailsQueue.js +74 -0
  10. package/lib/cjs/routes/list/lists/selected.js +3 -2
  11. package/lib/cjs/routes/list/service.js +229 -61
  12. package/lib/cjs/routes/shapes/index.js +21 -0
  13. package/lib/cjs/routes/shapes/store.js +163 -0
  14. package/lib/cjs/routes/shapes/types.js +2 -0
  15. package/lib/cjs/routes/shapes/utils.js +89 -0
  16. package/lib/esm/activities/ride/service.js +17 -3
  17. package/lib/esm/routes/base/api/index.js +6 -2
  18. package/lib/esm/routes/download/service.js +8 -0
  19. package/lib/esm/routes/index.js +2 -0
  20. package/lib/esm/routes/library/errors.js +46 -0
  21. package/lib/esm/routes/library/index.js +2 -0
  22. package/lib/esm/routes/library/service.js +390 -191
  23. package/lib/esm/routes/list/cards/RouteCard.js +19 -5
  24. package/lib/esm/routes/list/detailsQueue.js +70 -0
  25. package/lib/esm/routes/list/lists/selected.js +1 -1
  26. package/lib/esm/routes/list/service.js +230 -62
  27. package/lib/esm/routes/shapes/index.js +2 -0
  28. package/lib/esm/routes/shapes/store.js +159 -0
  29. package/lib/esm/routes/shapes/types.js +1 -0
  30. package/lib/esm/routes/shapes/utils.js +82 -0
  31. package/lib/types/activities/ride/service.d.ts +2 -0
  32. package/lib/types/routes/download/service.d.ts +1 -0
  33. package/lib/types/routes/index.d.ts +2 -0
  34. package/lib/types/routes/library/errors.d.ts +12 -0
  35. package/lib/types/routes/library/index.d.ts +3 -0
  36. package/lib/types/routes/library/service.d.ts +32 -4
  37. package/lib/types/routes/library/types.d.ts +31 -1
  38. package/lib/types/routes/list/cards/RouteCard.d.ts +1 -0
  39. package/lib/types/routes/list/cards/types.d.ts +2 -0
  40. package/lib/types/routes/list/detailsQueue.d.ts +16 -0
  41. package/lib/types/routes/list/lists/selected.d.ts +2 -0
  42. package/lib/types/routes/list/service.d.ts +45 -7
  43. package/lib/types/routes/list/types.d.ts +1 -0
  44. package/lib/types/routes/shapes/index.d.ts +3 -0
  45. package/lib/types/routes/shapes/store.d.ts +22 -0
  46. package/lib/types/routes/shapes/types.d.ts +12 -0
  47. package/lib/types/routes/shapes/utils.d.ts +8 -0
  48. package/package.json +5 -5
@@ -101,6 +101,7 @@ let ActivityRideService = (() => {
101
101
  isSaveDone;
102
102
  isDonateShown;
103
103
  isSummaryShown;
104
+ stopPromise;
104
105
  statsCalculator;
105
106
  durationCalculator;
106
107
  deviceDataHandler = this.onDeviceData.bind(this);
@@ -183,6 +184,17 @@ let ActivityRideService = (() => {
183
184
  }
184
185
  }
185
186
  async stop() {
187
+ if (this.stopPromise !== undefined)
188
+ return this.stopPromise;
189
+ this.stopPromise = this.doStop();
190
+ try {
191
+ await this.stopPromise;
192
+ }
193
+ finally {
194
+ delete this.stopPromise;
195
+ }
196
+ }
197
+ async doStop() {
186
198
  this.stopWorker();
187
199
  if (!this.observer || !this.activity)
188
200
  return;
@@ -206,7 +218,9 @@ let ActivityRideService = (() => {
206
218
  delete this.observer;
207
219
  }
208
220
  async cleanup() {
209
- if (this.state !== 'idle' && this.state !== 'completed')
221
+ if (this.stopPromise !== undefined)
222
+ await this.stopPromise;
223
+ else if (this.state !== 'idle' && this.state !== 'completed')
210
224
  await this.stop();
211
225
  delete this.activity;
212
226
  }
@@ -1161,7 +1175,7 @@ let ActivityRideService = (() => {
1161
1175
  getTotalDistance() {
1162
1176
  try {
1163
1177
  const route = this.current.route;
1164
- if (!route)
1178
+ if (!route || !this.activity)
1165
1179
  return 0;
1166
1180
  const isLoop = (0, route_1.checkIsLoop)(route);
1167
1181
  const totalRouteDistance = this.current?.endPos ?? route.distance ?? route.points?.at(-1)?.routeDistance;
@@ -1181,7 +1195,7 @@ let ActivityRideService = (() => {
1181
1195
  getTotalElevation() {
1182
1196
  try {
1183
1197
  const route = this.current.route;
1184
- if (!route)
1198
+ if (!route || !this.activity)
1185
1199
  return 0;
1186
1200
  const isLoop = (0, route_1.checkIsLoop)(route);
1187
1201
  const totalRouteDistance = this.current?.endPos ?? route.distance ?? route.points?.at(-1)?.routeDistance;
@@ -141,15 +141,19 @@ let IncyclistRoutesApi = (() => {
141
141
  try {
142
142
  const conf = {};
143
143
  conf.validateStatus = (status) => {
144
- return (status >= 200 && status < 300) || status == 404;
144
+ return (status >= 200 && status < 300) || status == 404 || status == 429;
145
145
  };
146
146
  const res = await this._get(url, conf);
147
147
  if (res.status === 404)
148
148
  return;
149
+ if (res.status === 429) {
150
+ this.logger.logEvent({ message: 'getCountry hit rate limit', query });
151
+ return;
152
+ }
149
153
  return res.data.country?.toUpperCase();
150
154
  }
151
155
  catch (err) {
152
- this.logError(err, 'reload');
156
+ this.logError(err, 'getCountry');
153
157
  }
154
158
  }
155
159
  async reload() {
@@ -87,6 +87,8 @@ let RouteDownloadService = (() => {
87
87
  const observer = new types_1.DownloadObserver(this._download(route));
88
88
  this.downloads.push({ route, observer });
89
89
  this.emit('download-started', route, observer);
90
+ observer.once('done', () => { this.removeDownload(route); });
91
+ observer.once('error', () => { this.removeDownload(route); });
90
92
  return observer;
91
93
  }
92
94
  stopDownload(route) {
@@ -97,6 +99,12 @@ let RouteDownloadService = (() => {
97
99
  info.observer.stop();
98
100
  this.downloads.splice(idx, 1);
99
101
  }
102
+ removeDownload(route) {
103
+ const idx = this.downloads.findIndex(d => d.route.description.id === route.description.id);
104
+ if (idx === -1)
105
+ return;
106
+ this.downloads.splice(idx, 1);
107
+ }
100
108
  async deleteIncompleteFile(route, videoDir) {
101
109
  const { file } = await this.getDownloadFileName(route, videoDir);
102
110
  if (file) {
@@ -20,3 +20,5 @@ __exportStar(require("./sync"), exports);
20
20
  __exportStar(require("./base/utils"), exports);
21
21
  __exportStar(require("./free-ride"), exports);
22
22
  __exportStar(require("./page"), exports);
23
+ __exportStar(require("./library"), exports);
24
+ __exportStar(require("./shapes"), exports);
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRouteImportError = exports.mapErrorToImportCode = exports.RouteImportError = void 0;
4
+ class RouteImportError extends Error {
5
+ code;
6
+ missingExt;
7
+ constructor(message, code, props) {
8
+ super(message);
9
+ this.name = 'RouteImportError';
10
+ this.code = code;
11
+ this.missingExt = props?.missingExt;
12
+ }
13
+ toFailure() {
14
+ const failure = { code: this.code, reason: this.message };
15
+ if (this.missingExt)
16
+ failure.missingExt = this.missingExt;
17
+ return failure;
18
+ }
19
+ }
20
+ exports.RouteImportError = RouteImportError;
21
+ const mapErrorToImportCode = (err, scope) => {
22
+ if (err instanceof RouteImportError)
23
+ return err.code;
24
+ switch (scope?.lastFailure?.reason) {
25
+ case 'offline':
26
+ return 'ICLOUD_OFFLINE';
27
+ case 'timeout':
28
+ case 'download-failed':
29
+ return 'ICLOUD_DOWNLOAD_FAILED';
30
+ case 'access-lost':
31
+ return 'READ_FAILED';
32
+ }
33
+ const message = errorText(err);
34
+ if (/AVI/i.test(message))
35
+ return 'AVI_NOT_SUPPORTED';
36
+ if (/no video|video file not found/i.test(message))
37
+ return 'NO_VIDEO';
38
+ if (/^Could not (open|read)/i.test(message))
39
+ return 'READ_FAILED';
40
+ if (/pars(e|ing)/i.test(message))
41
+ return 'PARSE_FAILED';
42
+ return 'UNSUPPORTED';
43
+ };
44
+ exports.mapErrorToImportCode = mapErrorToImportCode;
45
+ const errorText = (err) => err?.message ?? (typeof err === 'string' ? err : '');
46
+ const toRouteImportError = (err, scope, message) => {
47
+ if (err instanceof RouteImportError)
48
+ return err;
49
+ const text = message ?? errorText(err);
50
+ return new RouteImportError(text, (0, exports.mapErrorToImportCode)(err, scope));
51
+ };
52
+ exports.toRouteImportError = toRouteImportError;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./service"), exports);
18
+ __exportStar(require("./errors"), exports);