incyclist-services 1.9.22 → 1.9.23
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/activities/base/repo/db.js +1 -1
- package/lib/cjs/activities/base/utils/helpers.js +26 -11
- package/lib/cjs/activities/upload/index.js +1 -0
- package/lib/cjs/activities/upload/komoot.js +166 -0
- package/lib/cjs/apps/base/api/komoot/api.js +35 -0
- package/lib/cjs/apps/komoot/KomootAppConnection.js +6 -4
- package/lib/cjs/apps/service.js +1 -1
- package/lib/esm/activities/base/repo/db.js +1 -1
- package/lib/esm/activities/base/utils/helpers.js +24 -10
- package/lib/esm/activities/upload/index.js +1 -0
- package/lib/esm/activities/upload/komoot.js +163 -0
- package/lib/esm/apps/base/api/komoot/api.js +35 -0
- package/lib/esm/apps/komoot/KomootAppConnection.js +6 -4
- package/lib/esm/apps/service.js +1 -1
- package/lib/types/activities/base/model/index.d.ts +1 -5
- package/lib/types/activities/base/repo/db.d.ts +1 -1
- package/lib/types/activities/base/utils/helpers.d.ts +2 -1
- package/lib/types/activities/upload/index.d.ts +1 -0
- package/lib/types/activities/upload/komoot.d.ts +20 -0
- package/lib/types/apps/base/api/komoot/api.d.ts +2 -1
- package/lib/types/apps/base/api/komoot/types.d.ts +1 -0
- package/lib/types/apps/komoot/KomootAppConnection.d.ts +1 -1
- package/package.json +1 -1
|
@@ -45,7 +45,7 @@ const routes_1 = require("../../../routes");
|
|
|
45
45
|
const factory_1 = require("./migration/factory");
|
|
46
46
|
const Injection_1 = require("../../../base/decorators/Injection");
|
|
47
47
|
const i18n_1 = require("../../../i18n");
|
|
48
|
-
exports.DB_VERSION = '
|
|
48
|
+
exports.DB_VERSION = '6';
|
|
49
49
|
exports.DB_NAME = 'db';
|
|
50
50
|
const SHORT_RIDE_FILTER_CUTOFF = new Date('2026-08-28').getTime();
|
|
51
51
|
let ActivitiesRepository = (() => {
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getActivityTotalElevation = exports.buildSummary = void 0;
|
|
17
|
+
exports.getActivityTotalElevation = exports.buildUploadStatus = exports.buildSummary = void 0;
|
|
18
18
|
__exportStar(require("./activity"), exports);
|
|
19
19
|
const model_1 = require("../model");
|
|
20
20
|
const buildSummary = (activity, proposedName) => {
|
|
@@ -34,24 +34,39 @@ const buildSummary = (activity, proposedName) => {
|
|
|
34
34
|
else if (activity.route)
|
|
35
35
|
title = activity.route.name ?? title;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
const parts = fileName.split(/[/\\]/);
|
|
39
|
-
const last = parts.at(-1);
|
|
40
|
-
if (last?.endsWith('.json'))
|
|
41
|
-
name = last.slice(0, -5);
|
|
42
|
-
}
|
|
37
|
+
name = verifyName(name, fileName);
|
|
43
38
|
let startTime;
|
|
44
39
|
if (startTimeUTC)
|
|
45
40
|
startTime = (new Date(startTimeUTC)).getTime();
|
|
46
|
-
const uploadStatus =
|
|
47
|
-
if (links?.strava) {
|
|
48
|
-
uploadStatus.push({ service: 'strava', status: 'success' });
|
|
49
|
-
}
|
|
41
|
+
const uploadStatus = (0, exports.buildUploadStatus)(links);
|
|
50
42
|
return {
|
|
51
43
|
id, title, name, routeId, routeHash, previewImage, startTime, rideTime, distance, totalElevation, startPos, endPos, realityFactor, smoothingLevel, uploadStatus, laps
|
|
52
44
|
};
|
|
53
45
|
};
|
|
54
46
|
exports.buildSummary = buildSummary;
|
|
47
|
+
const buildUploadStatus = (links) => {
|
|
48
|
+
const uploadStatus = [];
|
|
49
|
+
if (links) {
|
|
50
|
+
const services = Object.keys(links);
|
|
51
|
+
for (const service of services) {
|
|
52
|
+
if (links[service]) {
|
|
53
|
+
const status = links[service];
|
|
54
|
+
uploadStatus.push({ service, status: status.error ? 'failed' : 'success' });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return uploadStatus;
|
|
59
|
+
};
|
|
60
|
+
exports.buildUploadStatus = buildUploadStatus;
|
|
61
|
+
const verifyName = (name, fileName) => {
|
|
62
|
+
if (name === undefined && fileName !== undefined) {
|
|
63
|
+
const parts = fileName.split(/[/\\]/);
|
|
64
|
+
const last = parts.at(-1);
|
|
65
|
+
if (last?.endsWith('.json'))
|
|
66
|
+
name = last.slice(0, -5);
|
|
67
|
+
}
|
|
68
|
+
return name;
|
|
69
|
+
};
|
|
55
70
|
const getActivityTotalElevation = (activity) => {
|
|
56
71
|
const { logs = [] } = activity;
|
|
57
72
|
let elevation = 0;
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./strava"), exports);
|
|
18
18
|
__exportStar(require("./intervals"), exports);
|
|
19
|
+
__exportStar(require("./komoot"), exports);
|
|
19
20
|
__exportStar(require("./types"), exports);
|
|
20
21
|
__exportStar(require("./factory"), exports);
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.KomootUpload = void 0;
|
|
38
|
+
const service_1 = require("../../base/service");
|
|
39
|
+
const types_1 = require("../../base/types");
|
|
40
|
+
const Injection_1 = require("../../base/decorators/Injection");
|
|
41
|
+
const factory_1 = require("./factory");
|
|
42
|
+
const komoot_1 = require("../../apps/komoot");
|
|
43
|
+
const api_1 = require("../../api");
|
|
44
|
+
let KomootUpload = (() => {
|
|
45
|
+
let _classDecorators = [types_1.Singleton];
|
|
46
|
+
let _classDescriptor;
|
|
47
|
+
let _classExtraInitializers = [];
|
|
48
|
+
let _classThis;
|
|
49
|
+
let _classSuper = service_1.IncyclistService;
|
|
50
|
+
let _instanceExtraInitializers = [];
|
|
51
|
+
let _getKomootAppConnection_decorators;
|
|
52
|
+
var KomootUpload = class extends _classSuper {
|
|
53
|
+
static { _classThis = this; }
|
|
54
|
+
static {
|
|
55
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
56
|
+
_getKomootAppConnection_decorators = [Injection_1.Injectable];
|
|
57
|
+
__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);
|
|
58
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
59
|
+
KomootUpload = _classThis = _classDescriptor.value;
|
|
60
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
61
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
62
|
+
}
|
|
63
|
+
isInitialized = __runInitializers(this, _instanceExtraInitializers);
|
|
64
|
+
connection = new komoot_1.KomootAppConnection();
|
|
65
|
+
constructor() {
|
|
66
|
+
super('KomootUpload');
|
|
67
|
+
this.isInitialized = false;
|
|
68
|
+
this.init();
|
|
69
|
+
}
|
|
70
|
+
init() {
|
|
71
|
+
if (this.isInitialized)
|
|
72
|
+
return true;
|
|
73
|
+
this.isInitialized = this.getKomootAppConnection().init();
|
|
74
|
+
return this.isInitialized;
|
|
75
|
+
}
|
|
76
|
+
isConnected() {
|
|
77
|
+
return this.getKomootAppConnection().isConnected();
|
|
78
|
+
}
|
|
79
|
+
async upload(activity, format = 'FIT') {
|
|
80
|
+
try {
|
|
81
|
+
const ok = this.ensureInitialized();
|
|
82
|
+
if (!ok) {
|
|
83
|
+
this.logEvent({ message: 'Komoot Upload skipped', reason: 'not initialized' });
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (!this.isConnected())
|
|
87
|
+
return false;
|
|
88
|
+
const lcFormat = format.toLowerCase();
|
|
89
|
+
const ucFormat = format.toUpperCase();
|
|
90
|
+
const uploadFormat = this.getKomootFormat(lcFormat);
|
|
91
|
+
const sport = 'racebike';
|
|
92
|
+
this.logEvent({ message: 'Komoot Upload', requestedFormat: ucFormat, uploadFormat });
|
|
93
|
+
if (!activity.links)
|
|
94
|
+
activity.links = {};
|
|
95
|
+
const fileName = activity[`${uploadFormat}FileName`];
|
|
96
|
+
if (!fileName) {
|
|
97
|
+
throw new Error(`data not exported to ${uploadFormat.toUpperCase()}`);
|
|
98
|
+
}
|
|
99
|
+
const data = await this.readFile(fileName);
|
|
100
|
+
if (!data) {
|
|
101
|
+
throw new Error(`file could not be read: ${fileName}`);
|
|
102
|
+
}
|
|
103
|
+
const res = await this.getApi().uploadTour(Buffer.from(data), uploadFormat, sport, activity.title);
|
|
104
|
+
this.logEvent({ message: 'Komoot Upload success', activityId: res.id });
|
|
105
|
+
activity.links.komoot = {
|
|
106
|
+
activity_id: res.id.toString(),
|
|
107
|
+
url: this.getUrl(res.id.toString())
|
|
108
|
+
};
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
this.logEvent({ message: 'Komoot Upload failure', error: err.message });
|
|
113
|
+
activity.links.komoot = {
|
|
114
|
+
error: err.message
|
|
115
|
+
};
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
getUrl(activityId) {
|
|
120
|
+
return `https://www.komoot.com/tour/${activityId}`;
|
|
121
|
+
}
|
|
122
|
+
getKomootFormat(format) {
|
|
123
|
+
switch (format.toLowerCase()) {
|
|
124
|
+
case 'tcx':
|
|
125
|
+
return 'fit';
|
|
126
|
+
case 'fit':
|
|
127
|
+
return 'fit';
|
|
128
|
+
case 'gpx':
|
|
129
|
+
return 'gpx';
|
|
130
|
+
default:
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
ensureInitialized() {
|
|
135
|
+
if (!this.isInitialized)
|
|
136
|
+
this.init();
|
|
137
|
+
return this.isInitialized;
|
|
138
|
+
}
|
|
139
|
+
async readFile(fileName) {
|
|
140
|
+
try {
|
|
141
|
+
const fs = this.getFS();
|
|
142
|
+
const exists = await fs.existsFile(fileName);
|
|
143
|
+
if (!exists)
|
|
144
|
+
return null;
|
|
145
|
+
const content = await fs.readFile(fileName);
|
|
146
|
+
return content || null;
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
this.logError(err, 'readFile');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
getKomootAppConnection() {
|
|
153
|
+
return this.connection;
|
|
154
|
+
}
|
|
155
|
+
getApi() {
|
|
156
|
+
return this.getKomootAppConnection().getApi();
|
|
157
|
+
}
|
|
158
|
+
getFS() {
|
|
159
|
+
return (0, api_1.getBindings)().fs;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return KomootUpload = _classThis;
|
|
163
|
+
})();
|
|
164
|
+
exports.KomootUpload = KomootUpload;
|
|
165
|
+
const factory = new factory_1.ActivityUploadFactory();
|
|
166
|
+
factory.add('komoot', new KomootUpload());
|
|
@@ -110,6 +110,41 @@ class KomootApi extends base_1.AppApiBase {
|
|
|
110
110
|
throw (err);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
+
async uploadTour(data, format, sport, name) {
|
|
114
|
+
const tsStart = Date.now();
|
|
115
|
+
try {
|
|
116
|
+
const auth = this.getBasicAuthCredentials();
|
|
117
|
+
if (!this.userid) {
|
|
118
|
+
this.logger.logEvent({ message: 'uploadTour failed', reason: 'invalid credentials' });
|
|
119
|
+
throw new Error('invalid credentials');
|
|
120
|
+
}
|
|
121
|
+
const contentType = format === 'gpx' ? 'application/gpx+xml' : 'application/octet-stream';
|
|
122
|
+
const params = new URLSearchParams({ data_type: format, sport, name });
|
|
123
|
+
const response = await this.getApi().request({
|
|
124
|
+
method: 'post',
|
|
125
|
+
url: `${this.getBaseUrl()}/tours/?${params.toString()}`,
|
|
126
|
+
auth,
|
|
127
|
+
headers: { 'Content-Type': contentType },
|
|
128
|
+
data,
|
|
129
|
+
validateStatus: () => true
|
|
130
|
+
});
|
|
131
|
+
if (response.status >= 400) {
|
|
132
|
+
this.logger.logEvent({
|
|
133
|
+
message: 'uploadTour failed',
|
|
134
|
+
status: response.status,
|
|
135
|
+
body: JSON.stringify(response.data),
|
|
136
|
+
duration: Date.now() - tsStart
|
|
137
|
+
});
|
|
138
|
+
throw new Error(`HTTP ${response.status}: ${JSON.stringify(response.data)}`);
|
|
139
|
+
}
|
|
140
|
+
this.logger.logEvent({ message: 'uploadTour success', id: response.data?.id, duration: Date.now() - tsStart });
|
|
141
|
+
return response.data;
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
this.logger.logEvent({ message: 'uploadTour failed', reason: err.message, duration: Date.now() - tsStart });
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
113
148
|
applyFilter(tours, filters) {
|
|
114
149
|
if (!filters)
|
|
115
150
|
return tours;
|
|
@@ -65,7 +65,6 @@ let KomootAppConnection = (() => {
|
|
|
65
65
|
constructor() {
|
|
66
66
|
super('KomootAppConnection', 'komoot');
|
|
67
67
|
this.api = new api_2.KomootApi();
|
|
68
|
-
this.iniAuth();
|
|
69
68
|
}
|
|
70
69
|
async connect(credentials) {
|
|
71
70
|
this.ensureInitialized();
|
|
@@ -110,9 +109,9 @@ let KomootAppConnection = (() => {
|
|
|
110
109
|
getApi() {
|
|
111
110
|
return this.api;
|
|
112
111
|
}
|
|
113
|
-
|
|
112
|
+
initAuth() {
|
|
114
113
|
const api = this.getApi();
|
|
115
|
-
if (this.credentials) {
|
|
114
|
+
if (this.credentials && api) {
|
|
116
115
|
api.setAuth(this.credentials);
|
|
117
116
|
return true;
|
|
118
117
|
}
|
|
@@ -142,7 +141,10 @@ let KomootAppConnection = (() => {
|
|
|
142
141
|
isInitialized = false;
|
|
143
142
|
}
|
|
144
143
|
this.setupEventListeners();
|
|
145
|
-
|
|
144
|
+
if (isInitialized) {
|
|
145
|
+
this.credentials = { ...credentials };
|
|
146
|
+
this.initAuth();
|
|
147
|
+
}
|
|
146
148
|
return isInitialized;
|
|
147
149
|
}
|
|
148
150
|
getAuthConfig() {
|
package/lib/cjs/apps/service.js
CHANGED
|
@@ -66,7 +66,7 @@ let AppsService = (() => {
|
|
|
66
66
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
67
67
|
}
|
|
68
68
|
services = (__runInitializers(this, _instanceExtraInitializers), {
|
|
69
|
-
ActivityUpload: ['strava', 'intervals'],
|
|
69
|
+
ActivityUpload: ['strava', 'intervals', 'komoot'],
|
|
70
70
|
WorkoutUpload: [],
|
|
71
71
|
WorkoutDownload: ['intervals'],
|
|
72
72
|
ActivityDownload: [],
|
|
@@ -42,7 +42,7 @@ import { useRouteList } from "../../../routes";
|
|
|
42
42
|
import { ActivitiesDBMigratorFactory } from "./migration/factory";
|
|
43
43
|
import { Injectable } from "../../../base/decorators/Injection";
|
|
44
44
|
import { useUnitConverter } from "../../../i18n";
|
|
45
|
-
export const DB_VERSION = '
|
|
45
|
+
export const DB_VERSION = '6';
|
|
46
46
|
export const DB_NAME = 'db';
|
|
47
47
|
const SHORT_RIDE_FILTER_CUTOFF = new Date('2026-08-28').getTime();
|
|
48
48
|
let ActivitiesRepository = (() => {
|
|
@@ -17,23 +17,37 @@ export const buildSummary = (activity, proposedName) => {
|
|
|
17
17
|
else if (activity.route)
|
|
18
18
|
title = activity.route.name ?? title;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
const parts = fileName.split(/[/\\]/);
|
|
22
|
-
const last = parts.at(-1);
|
|
23
|
-
if (last?.endsWith('.json'))
|
|
24
|
-
name = last.slice(0, -5);
|
|
25
|
-
}
|
|
20
|
+
name = verifyName(name, fileName);
|
|
26
21
|
let startTime;
|
|
27
22
|
if (startTimeUTC)
|
|
28
23
|
startTime = (new Date(startTimeUTC)).getTime();
|
|
29
|
-
const uploadStatus =
|
|
30
|
-
if (links?.strava) {
|
|
31
|
-
uploadStatus.push({ service: 'strava', status: 'success' });
|
|
32
|
-
}
|
|
24
|
+
const uploadStatus = buildUploadStatus(links);
|
|
33
25
|
return {
|
|
34
26
|
id, title, name, routeId, routeHash, previewImage, startTime, rideTime, distance, totalElevation, startPos, endPos, realityFactor, smoothingLevel, uploadStatus, laps
|
|
35
27
|
};
|
|
36
28
|
};
|
|
29
|
+
export const buildUploadStatus = (links) => {
|
|
30
|
+
const uploadStatus = [];
|
|
31
|
+
if (links) {
|
|
32
|
+
const services = Object.keys(links);
|
|
33
|
+
for (const service of services) {
|
|
34
|
+
if (links[service]) {
|
|
35
|
+
const status = links[service];
|
|
36
|
+
uploadStatus.push({ service, status: status.error ? 'failed' : 'success' });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return uploadStatus;
|
|
41
|
+
};
|
|
42
|
+
const verifyName = (name, fileName) => {
|
|
43
|
+
if (name === undefined && fileName !== undefined) {
|
|
44
|
+
const parts = fileName.split(/[/\\]/);
|
|
45
|
+
const last = parts.at(-1);
|
|
46
|
+
if (last?.endsWith('.json'))
|
|
47
|
+
name = last.slice(0, -5);
|
|
48
|
+
}
|
|
49
|
+
return name;
|
|
50
|
+
};
|
|
37
51
|
export const getActivityTotalElevation = (activity) => {
|
|
38
52
|
const { logs = [] } = activity;
|
|
39
53
|
let elevation = 0;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { IncyclistService } from "../../base/service";
|
|
36
|
+
import { Singleton } from "../../base/types";
|
|
37
|
+
import { Injectable } from "../../base/decorators/Injection";
|
|
38
|
+
import { ActivityUploadFactory } from "./factory";
|
|
39
|
+
import { KomootAppConnection } from "../../apps/komoot";
|
|
40
|
+
import { getBindings } from "../../api";
|
|
41
|
+
let KomootUpload = (() => {
|
|
42
|
+
let _classDecorators = [Singleton];
|
|
43
|
+
let _classDescriptor;
|
|
44
|
+
let _classExtraInitializers = [];
|
|
45
|
+
let _classThis;
|
|
46
|
+
let _classSuper = IncyclistService;
|
|
47
|
+
let _instanceExtraInitializers = [];
|
|
48
|
+
let _getKomootAppConnection_decorators;
|
|
49
|
+
var KomootUpload = class extends _classSuper {
|
|
50
|
+
static { _classThis = this; }
|
|
51
|
+
static {
|
|
52
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
53
|
+
_getKomootAppConnection_decorators = [Injectable];
|
|
54
|
+
__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);
|
|
55
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
56
|
+
KomootUpload = _classThis = _classDescriptor.value;
|
|
57
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
58
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
59
|
+
}
|
|
60
|
+
isInitialized = __runInitializers(this, _instanceExtraInitializers);
|
|
61
|
+
connection = new KomootAppConnection();
|
|
62
|
+
constructor() {
|
|
63
|
+
super('KomootUpload');
|
|
64
|
+
this.isInitialized = false;
|
|
65
|
+
this.init();
|
|
66
|
+
}
|
|
67
|
+
init() {
|
|
68
|
+
if (this.isInitialized)
|
|
69
|
+
return true;
|
|
70
|
+
this.isInitialized = this.getKomootAppConnection().init();
|
|
71
|
+
return this.isInitialized;
|
|
72
|
+
}
|
|
73
|
+
isConnected() {
|
|
74
|
+
return this.getKomootAppConnection().isConnected();
|
|
75
|
+
}
|
|
76
|
+
async upload(activity, format = 'FIT') {
|
|
77
|
+
try {
|
|
78
|
+
const ok = this.ensureInitialized();
|
|
79
|
+
if (!ok) {
|
|
80
|
+
this.logEvent({ message: 'Komoot Upload skipped', reason: 'not initialized' });
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!this.isConnected())
|
|
84
|
+
return false;
|
|
85
|
+
const lcFormat = format.toLowerCase();
|
|
86
|
+
const ucFormat = format.toUpperCase();
|
|
87
|
+
const uploadFormat = this.getKomootFormat(lcFormat);
|
|
88
|
+
const sport = 'racebike';
|
|
89
|
+
this.logEvent({ message: 'Komoot Upload', requestedFormat: ucFormat, uploadFormat });
|
|
90
|
+
if (!activity.links)
|
|
91
|
+
activity.links = {};
|
|
92
|
+
const fileName = activity[`${uploadFormat}FileName`];
|
|
93
|
+
if (!fileName) {
|
|
94
|
+
throw new Error(`data not exported to ${uploadFormat.toUpperCase()}`);
|
|
95
|
+
}
|
|
96
|
+
const data = await this.readFile(fileName);
|
|
97
|
+
if (!data) {
|
|
98
|
+
throw new Error(`file could not be read: ${fileName}`);
|
|
99
|
+
}
|
|
100
|
+
const res = await this.getApi().uploadTour(Buffer.from(data), uploadFormat, sport, activity.title);
|
|
101
|
+
this.logEvent({ message: 'Komoot Upload success', activityId: res.id });
|
|
102
|
+
activity.links.komoot = {
|
|
103
|
+
activity_id: res.id.toString(),
|
|
104
|
+
url: this.getUrl(res.id.toString())
|
|
105
|
+
};
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
this.logEvent({ message: 'Komoot Upload failure', error: err.message });
|
|
110
|
+
activity.links.komoot = {
|
|
111
|
+
error: err.message
|
|
112
|
+
};
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getUrl(activityId) {
|
|
117
|
+
return `https://www.komoot.com/tour/${activityId}`;
|
|
118
|
+
}
|
|
119
|
+
getKomootFormat(format) {
|
|
120
|
+
switch (format.toLowerCase()) {
|
|
121
|
+
case 'tcx':
|
|
122
|
+
return 'fit';
|
|
123
|
+
case 'fit':
|
|
124
|
+
return 'fit';
|
|
125
|
+
case 'gpx':
|
|
126
|
+
return 'gpx';
|
|
127
|
+
default:
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
ensureInitialized() {
|
|
132
|
+
if (!this.isInitialized)
|
|
133
|
+
this.init();
|
|
134
|
+
return this.isInitialized;
|
|
135
|
+
}
|
|
136
|
+
async readFile(fileName) {
|
|
137
|
+
try {
|
|
138
|
+
const fs = this.getFS();
|
|
139
|
+
const exists = await fs.existsFile(fileName);
|
|
140
|
+
if (!exists)
|
|
141
|
+
return null;
|
|
142
|
+
const content = await fs.readFile(fileName);
|
|
143
|
+
return content || null;
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
this.logError(err, 'readFile');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
getKomootAppConnection() {
|
|
150
|
+
return this.connection;
|
|
151
|
+
}
|
|
152
|
+
getApi() {
|
|
153
|
+
return this.getKomootAppConnection().getApi();
|
|
154
|
+
}
|
|
155
|
+
getFS() {
|
|
156
|
+
return getBindings().fs;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return KomootUpload = _classThis;
|
|
160
|
+
})();
|
|
161
|
+
export { KomootUpload };
|
|
162
|
+
const factory = new ActivityUploadFactory();
|
|
163
|
+
factory.add('komoot', new KomootUpload());
|
|
@@ -107,6 +107,41 @@ export class KomootApi extends AppApiBase {
|
|
|
107
107
|
throw (err);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
async uploadTour(data, format, sport, name) {
|
|
111
|
+
const tsStart = Date.now();
|
|
112
|
+
try {
|
|
113
|
+
const auth = this.getBasicAuthCredentials();
|
|
114
|
+
if (!this.userid) {
|
|
115
|
+
this.logger.logEvent({ message: 'uploadTour failed', reason: 'invalid credentials' });
|
|
116
|
+
throw new Error('invalid credentials');
|
|
117
|
+
}
|
|
118
|
+
const contentType = format === 'gpx' ? 'application/gpx+xml' : 'application/octet-stream';
|
|
119
|
+
const params = new URLSearchParams({ data_type: format, sport, name });
|
|
120
|
+
const response = await this.getApi().request({
|
|
121
|
+
method: 'post',
|
|
122
|
+
url: `${this.getBaseUrl()}/tours/?${params.toString()}`,
|
|
123
|
+
auth,
|
|
124
|
+
headers: { 'Content-Type': contentType },
|
|
125
|
+
data,
|
|
126
|
+
validateStatus: () => true
|
|
127
|
+
});
|
|
128
|
+
if (response.status >= 400) {
|
|
129
|
+
this.logger.logEvent({
|
|
130
|
+
message: 'uploadTour failed',
|
|
131
|
+
status: response.status,
|
|
132
|
+
body: JSON.stringify(response.data),
|
|
133
|
+
duration: Date.now() - tsStart
|
|
134
|
+
});
|
|
135
|
+
throw new Error(`HTTP ${response.status}: ${JSON.stringify(response.data)}`);
|
|
136
|
+
}
|
|
137
|
+
this.logger.logEvent({ message: 'uploadTour success', id: response.data?.id, duration: Date.now() - tsStart });
|
|
138
|
+
return response.data;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
this.logger.logEvent({ message: 'uploadTour failed', reason: err.message, duration: Date.now() - tsStart });
|
|
142
|
+
throw err;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
110
145
|
applyFilter(tours, filters) {
|
|
111
146
|
if (!filters)
|
|
112
147
|
return tours;
|
|
@@ -62,7 +62,6 @@ let KomootAppConnection = (() => {
|
|
|
62
62
|
constructor() {
|
|
63
63
|
super('KomootAppConnection', 'komoot');
|
|
64
64
|
this.api = new KomootApi();
|
|
65
|
-
this.iniAuth();
|
|
66
65
|
}
|
|
67
66
|
async connect(credentials) {
|
|
68
67
|
this.ensureInitialized();
|
|
@@ -107,9 +106,9 @@ let KomootAppConnection = (() => {
|
|
|
107
106
|
getApi() {
|
|
108
107
|
return this.api;
|
|
109
108
|
}
|
|
110
|
-
|
|
109
|
+
initAuth() {
|
|
111
110
|
const api = this.getApi();
|
|
112
|
-
if (this.credentials) {
|
|
111
|
+
if (this.credentials && api) {
|
|
113
112
|
api.setAuth(this.credentials);
|
|
114
113
|
return true;
|
|
115
114
|
}
|
|
@@ -139,7 +138,10 @@ let KomootAppConnection = (() => {
|
|
|
139
138
|
isInitialized = false;
|
|
140
139
|
}
|
|
141
140
|
this.setupEventListeners();
|
|
142
|
-
|
|
141
|
+
if (isInitialized) {
|
|
142
|
+
this.credentials = { ...credentials };
|
|
143
|
+
this.initAuth();
|
|
144
|
+
}
|
|
143
145
|
return isInitialized;
|
|
144
146
|
}
|
|
145
147
|
getAuthConfig() {
|
package/lib/esm/apps/service.js
CHANGED
|
@@ -63,7 +63,7 @@ let AppsService = (() => {
|
|
|
63
63
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
64
64
|
}
|
|
65
65
|
services = (__runInitializers(this, _instanceExtraInitializers), {
|
|
66
|
-
ActivityUpload: ['strava', 'intervals'],
|
|
66
|
+
ActivityUpload: ['strava', 'intervals', 'komoot'],
|
|
67
67
|
WorkoutUpload: [],
|
|
68
68
|
WorkoutDownload: ['intervals'],
|
|
69
69
|
ActivityDownload: [],
|
|
@@ -42,11 +42,7 @@ export interface ActivityAppLink {
|
|
|
42
42
|
activity_id?: string;
|
|
43
43
|
url?: string;
|
|
44
44
|
}
|
|
45
|
-
export type ActivityAppLinks =
|
|
46
|
-
strava?: ActivityAppLink;
|
|
47
|
-
velohero?: ActivityAppLink;
|
|
48
|
-
intervals?: ActivityAppLink;
|
|
49
|
-
};
|
|
45
|
+
export type ActivityAppLinks = Record<string, ActivityAppLink>;
|
|
50
46
|
export type ScreenShotInfo = {
|
|
51
47
|
fileName: string;
|
|
52
48
|
position?: RoutePoint;
|
|
@@ -3,7 +3,7 @@ import { JsonRepository } from "../../../api";
|
|
|
3
3
|
import { Observer, PromiseObserver } from "../../../base/types/observer";
|
|
4
4
|
import { ActivityDetails, ActivityInfo } from "../model";
|
|
5
5
|
import { ActivitySearchCriteria } from "./types";
|
|
6
|
-
export declare const DB_VERSION = "
|
|
6
|
+
export declare const DB_VERSION = "6";
|
|
7
7
|
export declare const DB_NAME = "db";
|
|
8
8
|
export declare class ActivitiesRepository {
|
|
9
9
|
protected repo: JsonRepository;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './activity';
|
|
2
|
-
import { ActivityDetails, ActivitySummary } from "../model";
|
|
2
|
+
import { ActivityAppLinks, ActivityDetails, ActivitySummary, UploadInfo } from "../model";
|
|
3
3
|
export declare const buildSummary: (activity: ActivityDetails, proposedName?: string) => ActivitySummary;
|
|
4
|
+
export declare const buildUploadStatus: (links?: ActivityAppLinks) => UploadInfo[];
|
|
4
5
|
export declare const getActivityTotalElevation: (activity: ActivityDetails) => number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IncyclistService } from "../../base/service";
|
|
2
|
+
import { ActivityDetails } from "../base";
|
|
3
|
+
import { IActivityUpload } from "./types";
|
|
4
|
+
import { KomootAppConnection } from "../../apps/komoot";
|
|
5
|
+
import { KomootUploadFormat } from "../../apps";
|
|
6
|
+
export declare class KomootUpload extends IncyclistService implements IActivityUpload {
|
|
7
|
+
protected isInitialized: any;
|
|
8
|
+
protected connection: KomootAppConnection;
|
|
9
|
+
constructor();
|
|
10
|
+
init(): boolean;
|
|
11
|
+
isConnected(): boolean;
|
|
12
|
+
upload(activity: ActivityDetails, format?: string): Promise<boolean>;
|
|
13
|
+
getUrl(activityId: string): string;
|
|
14
|
+
protected getKomootFormat(format: string): KomootUploadFormat;
|
|
15
|
+
protected ensureInitialized(): any;
|
|
16
|
+
protected readFile(fileName: string): Promise<string | Buffer<ArrayBufferLike>>;
|
|
17
|
+
protected getKomootAppConnection(): KomootAppConnection;
|
|
18
|
+
protected getApi(): import("../../apps").KomootApi;
|
|
19
|
+
protected getFS(): import("../../api").IFileSystem;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventLogger } from 'gd-eventlog';
|
|
2
2
|
import { AppApiBase } from '../base';
|
|
3
|
-
import { KomootAuthConfig, KomootCoordinate, KomootGetTourRequestFilters, KomootGetTourRequestParams, KomootLoginResponse, KomootTourSummary } from './types';
|
|
3
|
+
import { KomootAuthConfig, KomootCoordinate, KomootGetTourRequestFilters, KomootGetTourRequestParams, KomootLoginResponse, KomootSportType, KomootTourSummary, KomootUploadFormat } from './types';
|
|
4
4
|
export declare class KomootApi extends AppApiBase {
|
|
5
5
|
protected username: string;
|
|
6
6
|
protected password: string;
|
|
@@ -12,6 +12,7 @@ export declare class KomootApi extends AppApiBase {
|
|
|
12
12
|
isAuthenticated(): boolean;
|
|
13
13
|
getTours(params?: KomootGetTourRequestParams, filters?: KomootGetTourRequestFilters): Promise<Array<KomootTourSummary>>;
|
|
14
14
|
getTourCoordinates(id: number): Promise<Array<KomootCoordinate>>;
|
|
15
|
+
uploadTour(data: Buffer | ArrayBuffer | Uint8Array, format: KomootUploadFormat, sport: KomootSportType, name: string): Promise<KomootTourSummary>;
|
|
15
16
|
protected applyFilter(tours: Array<KomootTourSummary>, filters?: KomootGetTourRequestFilters): KomootTourSummary[];
|
|
16
17
|
protected getBasicAuthCredentials(): {
|
|
17
18
|
username: string;
|
|
@@ -92,3 +92,4 @@ export interface KomootCoordinate extends KomootPoint {
|
|
|
92
92
|
export type KomootTourType = 'tour_planned' | 'tour_recorded';
|
|
93
93
|
export type KomootSportType = 'hike' | 'touringbicycle' | 'mtb' | 'racebike' | 'jogging' | 'mtb_easy' | 'mtb_advancde' | 'mountaineering';
|
|
94
94
|
export type KomootSportTypeNames = 'Hiking' | 'Cycling' | 'Mountain biking' | 'Road cycling' | 'Running' | 'Gravel riding' | 'Enduro mountain biking' | 'Mountaineering';
|
|
95
|
+
export type KomootUploadFormat = 'fit' | 'gpx';
|
|
@@ -11,7 +11,7 @@ export declare class KomootAppConnection extends ConnectedAppService<KomootCrede
|
|
|
11
11
|
isConnected(): boolean;
|
|
12
12
|
getCredentials(): KomootCredentials;
|
|
13
13
|
getApi(): KomootApi;
|
|
14
|
-
protected
|
|
14
|
+
protected initAuth(): boolean;
|
|
15
15
|
protected checkAuth(): boolean;
|
|
16
16
|
protected getAuthConfig(): KomootAuth | KomootCredentials;
|
|
17
17
|
protected getUuid(): any;
|