incyclist-services 1.1.87 → 1.1.89

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.
@@ -16,13 +16,14 @@ export interface RouteApiDescription extends RouteBase {
16
16
  points?: {
17
17
  id: string;
18
18
  };
19
- version?: string;
19
+ version?: number;
20
20
  category?: RouteCategory;
21
21
  provider?: RouteProvider;
22
22
  video?: VideoDescription;
23
23
  type?: RouteType;
24
24
  localizedTitle?: LocalizedText;
25
25
  previewUrl?: string;
26
+ isDeleted?: boolean;
26
27
  }
27
28
  export type LegacyRouteGpxRepoDescription = {
28
29
  id: string;
@@ -106,6 +106,7 @@ export interface RouteInfo extends RouteBase {
106
106
  isDownloaded?: boolean;
107
107
  isDeleted?: boolean;
108
108
  originalName?: string;
109
+ version?: number;
109
110
  }
110
111
  export type LocalizedText = {
111
112
  [index: string]: string;
@@ -12,8 +12,7 @@ const score = (r) => {
12
12
  val += 1;
13
13
  val += Math.log10(365 - tsAction);
14
14
  }
15
- if (val > 1)
16
- return val;
15
+ return val;
17
16
  };
18
17
  const sortFn = (a, b) => {
19
18
  const routeA = a.getRouteDescription();
@@ -1,3 +1,4 @@
1
+ import { EventLogger } from "gd-eventlog";
1
2
  import { JsonRepository } from "../../../api";
2
3
  import { Observer } from "../../../base/types/observer";
3
4
  import { Route } from "../../base/model/route";
@@ -7,8 +8,10 @@ export declare abstract class DBLoader<T> extends Loader<T> {
7
8
  protected routeDescriptions: Array<T>;
8
9
  protected videosRepo: JsonRepository;
9
10
  protected routesRepo: JsonRepository;
11
+ protected logger: EventLogger;
10
12
  protected abstract loadDescriptions(): Promise<Array<T>>;
11
13
  protected abstract buildRouteDBInfo(descr: RouteInfo): T;
14
+ constructor();
12
15
  load(): Observer;
13
16
  stopLoad(): void;
14
17
  protected _load(): Promise<void>;
@@ -10,11 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DBLoader = void 0;
13
+ const gd_eventlog_1 = require("gd-eventlog");
13
14
  const api_1 = require("../../../api");
14
15
  const observer_1 = require("../../../base/types/observer");
15
16
  const route_1 = require("../../base/model/route");
16
17
  const types_1 = require("./types");
17
18
  class DBLoader extends types_1.Loader {
19
+ constructor() {
20
+ super();
21
+ this.logger = new gd_eventlog_1.EventLogger('RoutesDB');
22
+ }
18
23
  load() {
19
24
  if (this.loadObserver)
20
25
  return this.loadObserver;
@@ -42,7 +42,10 @@ class RoutesApiLoader extends types_1.Loader {
42
42
  const descr = p.value[j];
43
43
  let description;
44
44
  const existing = this.getDescriptionFromDB(descr.routeId || descr.id);
45
- if (existing) {
45
+ const { isDeleted = false } = descr;
46
+ if (existing
47
+ && ((existing.version || 0) >= (descr.version || 0))
48
+ && (!isDeleted || (isDeleted && existing.isDownloaded))) {
46
49
  const details = yield this.getDetailsFromDB(existing.id);
47
50
  if (details) {
48
51
  continue;
@@ -52,13 +55,21 @@ class RoutesApiLoader extends types_1.Loader {
52
55
  else {
53
56
  description = this.buildRouteInfo(descr);
54
57
  }
58
+ if (!description) {
59
+ continue;
60
+ }
55
61
  const route = new route_1.Route(description);
56
62
  const isComplete = this.isCompleted(route);
57
63
  if (isComplete) {
58
64
  this.verifyRouteHash(route);
59
65
  this.emitRouteAdded(route);
60
66
  }
61
- items.push({ route, added: isComplete });
67
+ if (!existing) {
68
+ items.push({ route, added: isComplete });
69
+ }
70
+ else {
71
+ this.save(route, true);
72
+ }
62
73
  }
63
74
  }
64
75
  }
@@ -142,8 +153,8 @@ class RoutesApiLoader extends types_1.Loader {
142
153
  });
143
154
  }
144
155
  buildRouteInfo(descr, isLocal) {
145
- const { id, routeId, title, localizedTitle, country, distance, elevation, category, provider, video, points, previewUrl, routeHash } = descr;
146
- const data = { title, localizedTitle, country, distance, elevation, provider, category, previewUrl, routeHash };
156
+ const { id, routeId, title, localizedTitle, country, distance, elevation, category, provider, video, points, previewUrl, routeHash, version, isDeleted } = descr;
157
+ const data = { title, localizedTitle, country, distance, elevation, provider, category, previewUrl, routeHash, version, isDeleted };
147
158
  data.hasVideo = false;
148
159
  data.hasGpx = false;
149
160
  data.isLocal = isLocal || false;
@@ -29,6 +29,7 @@ export declare class RoutesDbLoader extends DBLoader<RouteInfoDBEntry> {
29
29
  protected buildRouteDBInfo(descr: RouteInfo): RouteInfoDBEntry;
30
30
  protected loadFromLegacy(): Promise<Array<RouteInfoDBEntry>>;
31
31
  protected loadDescriptions(): Promise<Array<RouteInfoDBEntry>>;
32
+ protected removeDuplicates(routes: Array<RouteInfoDBEntry>): any[];
32
33
  protected loadDetailRecord(target: Route | RouteInfo): Promise<RouteApiDetail>;
33
34
  protected loadDetails(route: Route, alreadyAdded?: boolean): Promise<void>;
34
35
  protected getVideoRepo(): JsonRepository;
@@ -128,7 +128,7 @@ let RoutesDbLoader = (() => {
128
128
  yield this.routesRepo.write('db', this.routeDescriptions.map(this.buildRouteDBInfo.bind(this)));
129
129
  }
130
130
  catch (err) {
131
- console.log(err);
131
+ this.logger.logEvent({ message: 'could not safe repo', error: err.message });
132
132
  }
133
133
  });
134
134
  this.saveObserver = new observer_1.PromiseObserver(save());
@@ -171,12 +171,26 @@ let RoutesDbLoader = (() => {
171
171
  return __awaiter(this, void 0, void 0, function* () {
172
172
  const descriptions = yield this.getRoutesRepo().read('db');
173
173
  if (descriptions) {
174
- return descriptions;
174
+ const routes = descriptions;
175
+ const cleaned = this.removeDuplicates(routes);
176
+ return cleaned;
175
177
  }
176
178
  const legacy = yield this.loadFromLegacy();
177
179
  return legacy;
178
180
  });
179
181
  }
182
+ removeDuplicates(routes) {
183
+ const ids = routes.map(r => r.legacyId || r.id);
184
+ const uniqueIds = ids.filter((d, pos) => ids.indexOf(d) === pos);
185
+ const cleaned = [];
186
+ uniqueIds.forEach(id => {
187
+ const routeWithLegacy = routes.find(r => r.legacyId === id);
188
+ const route = routeWithLegacy || routes.find(r => r.id === id);
189
+ if (route)
190
+ cleaned.push(route);
191
+ });
192
+ return cleaned;
193
+ }
180
194
  loadDetailRecord(target) {
181
195
  return __awaiter(this, void 0, void 0, function* () {
182
196
  const description = (target.description || target);
@@ -188,7 +202,7 @@ let RoutesDbLoader = (() => {
188
202
  description.originalName = details.title;
189
203
  }
190
204
  catch (err) {
191
- console.log(err);
205
+ this.logger.logEvent({ message: 'could not load route details', id: (description === null || description === void 0 ? void 0 : description.legacyId) || (description === null || description === void 0 ? void 0 : description.id), reason: err.message, stack: err.stack });
192
206
  }
193
207
  if (!details) {
194
208
  return;
@@ -344,6 +344,8 @@ let RouteListService = (() => {
344
344
  const importCards = [];
345
345
  if (!retry) {
346
346
  files.forEach((file) => {
347
+ if (!file)
348
+ return;
347
349
  const card = this.addImportCard(file);
348
350
  importCards.push(card);
349
351
  this.emitLists('updated');
@@ -353,6 +355,8 @@ let RouteListService = (() => {
353
355
  importCards.push(retry);
354
356
  }
355
357
  files.forEach((file, idx) => __awaiter(this, void 0, void 0, function* () {
358
+ if (!file)
359
+ return;
356
360
  const importCard = importCards[idx];
357
361
  try {
358
362
  const { data, details } = yield parsers_1.RouteParser.parse(file);
@@ -375,6 +379,7 @@ let RouteListService = (() => {
375
379
  }
376
380
  }
377
381
  else {
382
+ route.description.tsImported = Date.now();
378
383
  card = new RouteCard_1.RouteCard(route, { list: this.myRoutes });
379
384
  card.verify();
380
385
  card.save();
@@ -77,13 +77,13 @@ class UserSettingsService {
77
77
  const settings = this.settings;
78
78
  const keys = key.split('.');
79
79
  if (keys.length < 2)
80
- return settings[key] || defValue;
81
- const retVal = (value) => (0, valid_1.valid)(value) ? (0, clone_1.default)(value) : value;
80
+ return (0, valid_1.valid)(settings[key]) ? settings[key] : defValue;
81
+ const retVal = (value, defValue) => (0, valid_1.valid)(value) ? (0, clone_1.default)(value) : defValue;
82
82
  let child = {};
83
83
  for (let index = 0; index < keys.length; index++) {
84
84
  const k = keys[index];
85
85
  if (index === keys.length - 1)
86
- return retVal(child[k] || defValue);
86
+ return retVal(child[k], defValue);
87
87
  else {
88
88
  child = index === 0 ? settings[k] : child[k];
89
89
  if (child === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.1.87",
3
+ "version": "1.1.89",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },