incyclist-services 1.9.22 → 1.9.24
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/base/app/index.js +6 -0
- package/lib/cjs/apps/intervals/IntervalsAppConnection.js +6 -0
- package/lib/cjs/apps/komoot/KomootAppConnection.js +12 -4
- package/lib/cjs/apps/service.js +48 -16
- package/lib/cjs/apps/strava/StravaAppConnection.js +6 -0
- 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/base/app/index.js +6 -0
- package/lib/esm/apps/intervals/IntervalsAppConnection.js +6 -0
- package/lib/esm/apps/komoot/KomootAppConnection.js +12 -4
- package/lib/esm/apps/service.js +48 -16
- package/lib/esm/apps/strava/StravaAppConnection.js +6 -0
- 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/base/app/index.d.ts +3 -1
- package/lib/types/apps/intervals/IntervalsAppConnection.d.ts +3 -0
- package/lib/types/apps/komoot/KomootAppConnection.d.ts +4 -1
- package/lib/types/apps/service.d.ts +6 -2
- package/lib/types/apps/strava/StravaAppConnection.d.ts +3 -0
- package/lib/types/apps/types.d.ts +3 -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;
|
|
@@ -99,6 +99,12 @@ let ConnectedAppService = (() => {
|
|
|
99
99
|
this.init();
|
|
100
100
|
return this.isInitialized;
|
|
101
101
|
}
|
|
102
|
+
getSupportedOperations() {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
getDefaultOperations() {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
102
108
|
getUserSettings() {
|
|
103
109
|
return (0, settings_1.useUserSettings)();
|
|
104
110
|
}
|
|
@@ -121,6 +121,12 @@ let IntervalsAppConnection = (() => {
|
|
|
121
121
|
this.api = new api_2.IntervalsApi();
|
|
122
122
|
return this.api;
|
|
123
123
|
}
|
|
124
|
+
getSupportedOperations() {
|
|
125
|
+
return ['ActivityUpload', 'WorkoutDownload'];
|
|
126
|
+
}
|
|
127
|
+
getDefaultOperations() {
|
|
128
|
+
return ['ActivityUpload', 'WorkoutDownload'];
|
|
129
|
+
}
|
|
124
130
|
initAuth() {
|
|
125
131
|
let isInitialized;
|
|
126
132
|
try {
|
|
@@ -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,15 @@ let KomootAppConnection = (() => {
|
|
|
110
109
|
getApi() {
|
|
111
110
|
return this.api;
|
|
112
111
|
}
|
|
113
|
-
|
|
112
|
+
getSupportedOperations() {
|
|
113
|
+
return ['ActivityUpload', 'RouteDownload'];
|
|
114
|
+
}
|
|
115
|
+
getDefaultOperations() {
|
|
116
|
+
return ['RouteDownload'];
|
|
117
|
+
}
|
|
118
|
+
initAuth() {
|
|
114
119
|
const api = this.getApi();
|
|
115
|
-
if (this.credentials) {
|
|
120
|
+
if (this.credentials && api) {
|
|
116
121
|
api.setAuth(this.credentials);
|
|
117
122
|
return true;
|
|
118
123
|
}
|
|
@@ -142,7 +147,10 @@ let KomootAppConnection = (() => {
|
|
|
142
147
|
isInitialized = false;
|
|
143
148
|
}
|
|
144
149
|
this.setupEventListeners();
|
|
145
|
-
|
|
150
|
+
if (isInitialized) {
|
|
151
|
+
this.credentials = { ...credentials };
|
|
152
|
+
this.initAuth();
|
|
153
|
+
}
|
|
146
154
|
return isInitialized;
|
|
147
155
|
}
|
|
148
156
|
getAuthConfig() {
|
package/lib/cjs/apps/service.js
CHANGED
|
@@ -65,18 +65,11 @@ let AppsService = (() => {
|
|
|
65
65
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
66
66
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
ActivityUpload: ['strava', 'intervals'],
|
|
70
|
-
WorkoutUpload: [],
|
|
71
|
-
WorkoutDownload: ['intervals'],
|
|
72
|
-
ActivityDownload: [],
|
|
73
|
-
RouteDownload: ['komoot']
|
|
74
|
-
});
|
|
75
|
-
serviceMap = [
|
|
68
|
+
serviceMap = (__runInitializers(this, _instanceExtraInitializers), [
|
|
76
69
|
{ name: 'Strava', key: 'strava', iconUrl: 'https://static.cdnlogo.com/logos/s/42/strava-wordmark.svg', connection: new base_1.StravaAppConnection() },
|
|
77
70
|
{ name: 'Komoot', key: 'komoot', iconUrl: 'https://www.komoot.com/assets/4d8ae313eec53e6e.svg', connection: new komoot_1.KomootAppConnection() },
|
|
78
71
|
{ name: 'Intervals.icu', key: 'intervals', iconUrl: 'images/intervals.png', connection: new IntervalsAppConnection_1.IntervalsAppConnection() },
|
|
79
|
-
];
|
|
72
|
+
]);
|
|
80
73
|
constructor() {
|
|
81
74
|
super('AppsService');
|
|
82
75
|
}
|
|
@@ -100,6 +93,8 @@ let AppsService = (() => {
|
|
|
100
93
|
if (!entry?.connection)
|
|
101
94
|
return false;
|
|
102
95
|
const success = await entry.connection.connect(credentials);
|
|
96
|
+
if (!this.hasSettings(app))
|
|
97
|
+
this.storeInitialSettings(app);
|
|
103
98
|
this.emit('connected', app, success);
|
|
104
99
|
return success;
|
|
105
100
|
}
|
|
@@ -127,18 +122,22 @@ let AppsService = (() => {
|
|
|
127
122
|
isEnabled(app, operation) {
|
|
128
123
|
if (!this.isConnected(app))
|
|
129
124
|
return false;
|
|
125
|
+
if (!this.hasSettings(app))
|
|
126
|
+
this.storeInitialSettings(app);
|
|
130
127
|
const supported = this.getAppOperationSettings(app);
|
|
131
128
|
const config = supported.find(oc => oc.operation === operation);
|
|
132
129
|
return config?.enabled;
|
|
133
130
|
}
|
|
134
131
|
getAppOperationSettings(app) {
|
|
135
|
-
const
|
|
132
|
+
const connectedApp = this.getAppConnection(app);
|
|
133
|
+
if (!connectedApp)
|
|
134
|
+
return [];
|
|
135
|
+
const supported = connectedApp.getSupportedOperations();
|
|
136
|
+
const defaults = connectedApp.getDefaultOperations();
|
|
136
137
|
const operations = [];
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
operations.push({ operation, enabled });
|
|
141
|
-
}
|
|
138
|
+
supported.forEach(operation => {
|
|
139
|
+
const enabled = this.getSettings(`preferences.${app}.${operation}.enabled`, defaults.includes(operation));
|
|
140
|
+
operations.push({ operation, enabled });
|
|
142
141
|
});
|
|
143
142
|
return operations;
|
|
144
143
|
}
|
|
@@ -159,7 +158,14 @@ let AppsService = (() => {
|
|
|
159
158
|
return [];
|
|
160
159
|
}
|
|
161
160
|
getAvailableServices(operation) {
|
|
162
|
-
|
|
161
|
+
const serviceIds = this.getServiceIDs();
|
|
162
|
+
const supported = [];
|
|
163
|
+
serviceIds.forEach(serviceKey => {
|
|
164
|
+
if (this.getAppConnection(serviceKey)?.getSupportedOperations().includes(operation)) {
|
|
165
|
+
supported.push(serviceKey);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return supported;
|
|
163
169
|
}
|
|
164
170
|
getName(key) {
|
|
165
171
|
const found = this.serviceMap.find(r => r.key === key);
|
|
@@ -169,6 +175,32 @@ let AppsService = (() => {
|
|
|
169
175
|
const found = this.serviceMap.find(r => r.name === name);
|
|
170
176
|
return found ? found.key : name;
|
|
171
177
|
}
|
|
178
|
+
hasSettings(app) {
|
|
179
|
+
const settings = this.getUserSettings().getValue(`preferences.${app}`, null);
|
|
180
|
+
return settings !== null;
|
|
181
|
+
}
|
|
182
|
+
storeInitialSettings(app) {
|
|
183
|
+
if (this.hasSettings(app))
|
|
184
|
+
return;
|
|
185
|
+
const connection = this.getAppConnection(app);
|
|
186
|
+
if (!connection)
|
|
187
|
+
return;
|
|
188
|
+
const supported = connection.getSupportedOperations();
|
|
189
|
+
const defaults = connection.getDefaultOperations();
|
|
190
|
+
for (const operation of supported) {
|
|
191
|
+
const isDefault = defaults.includes(operation);
|
|
192
|
+
this.getUserSettings().set(`preferences.${app}.${operation}.enabled`, isDefault);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
getServiceIDs() {
|
|
196
|
+
return this.serviceMap.map(m => m.key);
|
|
197
|
+
}
|
|
198
|
+
getAppConnections() {
|
|
199
|
+
return this.serviceMap.map(m => m.connection);
|
|
200
|
+
}
|
|
201
|
+
getAppConnection(serviceKey) {
|
|
202
|
+
return this.serviceMap.find(m => serviceKey === m.key)?.connection;
|
|
203
|
+
}
|
|
172
204
|
getAppDisplayProps(key) {
|
|
173
205
|
const entry = this.serviceMap.find(e => e.key === key);
|
|
174
206
|
const { name, iconUrl } = entry;
|
|
@@ -119,6 +119,12 @@ let StravaAppConnection = (() => {
|
|
|
119
119
|
this.api = new api_2.StravaApi();
|
|
120
120
|
return this.api;
|
|
121
121
|
}
|
|
122
|
+
getSupportedOperations() {
|
|
123
|
+
return ['ActivityUpload'];
|
|
124
|
+
}
|
|
125
|
+
getDefaultOperations() {
|
|
126
|
+
return ['ActivityUpload'];
|
|
127
|
+
}
|
|
122
128
|
initAuth() {
|
|
123
129
|
let isInitialized;
|
|
124
130
|
try {
|
|
@@ -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;
|
|
@@ -118,6 +118,12 @@ let IntervalsAppConnection = (() => {
|
|
|
118
118
|
this.api = new IntervalsApi();
|
|
119
119
|
return this.api;
|
|
120
120
|
}
|
|
121
|
+
getSupportedOperations() {
|
|
122
|
+
return ['ActivityUpload', 'WorkoutDownload'];
|
|
123
|
+
}
|
|
124
|
+
getDefaultOperations() {
|
|
125
|
+
return ['ActivityUpload', 'WorkoutDownload'];
|
|
126
|
+
}
|
|
121
127
|
initAuth() {
|
|
122
128
|
let isInitialized;
|
|
123
129
|
try {
|
|
@@ -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,15 @@ let KomootAppConnection = (() => {
|
|
|
107
106
|
getApi() {
|
|
108
107
|
return this.api;
|
|
109
108
|
}
|
|
110
|
-
|
|
109
|
+
getSupportedOperations() {
|
|
110
|
+
return ['ActivityUpload', 'RouteDownload'];
|
|
111
|
+
}
|
|
112
|
+
getDefaultOperations() {
|
|
113
|
+
return ['RouteDownload'];
|
|
114
|
+
}
|
|
115
|
+
initAuth() {
|
|
111
116
|
const api = this.getApi();
|
|
112
|
-
if (this.credentials) {
|
|
117
|
+
if (this.credentials && api) {
|
|
113
118
|
api.setAuth(this.credentials);
|
|
114
119
|
return true;
|
|
115
120
|
}
|
|
@@ -139,7 +144,10 @@ let KomootAppConnection = (() => {
|
|
|
139
144
|
isInitialized = false;
|
|
140
145
|
}
|
|
141
146
|
this.setupEventListeners();
|
|
142
|
-
|
|
147
|
+
if (isInitialized) {
|
|
148
|
+
this.credentials = { ...credentials };
|
|
149
|
+
this.initAuth();
|
|
150
|
+
}
|
|
143
151
|
return isInitialized;
|
|
144
152
|
}
|
|
145
153
|
getAuthConfig() {
|
package/lib/esm/apps/service.js
CHANGED
|
@@ -62,18 +62,11 @@ let AppsService = (() => {
|
|
|
62
62
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
63
63
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
ActivityUpload: ['strava', 'intervals'],
|
|
67
|
-
WorkoutUpload: [],
|
|
68
|
-
WorkoutDownload: ['intervals'],
|
|
69
|
-
ActivityDownload: [],
|
|
70
|
-
RouteDownload: ['komoot']
|
|
71
|
-
});
|
|
72
|
-
serviceMap = [
|
|
65
|
+
serviceMap = (__runInitializers(this, _instanceExtraInitializers), [
|
|
73
66
|
{ name: 'Strava', key: 'strava', iconUrl: 'https://static.cdnlogo.com/logos/s/42/strava-wordmark.svg', connection: new StravaAppConnection() },
|
|
74
67
|
{ name: 'Komoot', key: 'komoot', iconUrl: 'https://www.komoot.com/assets/4d8ae313eec53e6e.svg', connection: new KomootAppConnection() },
|
|
75
68
|
{ name: 'Intervals.icu', key: 'intervals', iconUrl: 'images/intervals.png', connection: new IntervalsAppConnection() },
|
|
76
|
-
];
|
|
69
|
+
]);
|
|
77
70
|
constructor() {
|
|
78
71
|
super('AppsService');
|
|
79
72
|
}
|
|
@@ -97,6 +90,8 @@ let AppsService = (() => {
|
|
|
97
90
|
if (!entry?.connection)
|
|
98
91
|
return false;
|
|
99
92
|
const success = await entry.connection.connect(credentials);
|
|
93
|
+
if (!this.hasSettings(app))
|
|
94
|
+
this.storeInitialSettings(app);
|
|
100
95
|
this.emit('connected', app, success);
|
|
101
96
|
return success;
|
|
102
97
|
}
|
|
@@ -124,18 +119,22 @@ let AppsService = (() => {
|
|
|
124
119
|
isEnabled(app, operation) {
|
|
125
120
|
if (!this.isConnected(app))
|
|
126
121
|
return false;
|
|
122
|
+
if (!this.hasSettings(app))
|
|
123
|
+
this.storeInitialSettings(app);
|
|
127
124
|
const supported = this.getAppOperationSettings(app);
|
|
128
125
|
const config = supported.find(oc => oc.operation === operation);
|
|
129
126
|
return config?.enabled;
|
|
130
127
|
}
|
|
131
128
|
getAppOperationSettings(app) {
|
|
132
|
-
const
|
|
129
|
+
const connectedApp = this.getAppConnection(app);
|
|
130
|
+
if (!connectedApp)
|
|
131
|
+
return [];
|
|
132
|
+
const supported = connectedApp.getSupportedOperations();
|
|
133
|
+
const defaults = connectedApp.getDefaultOperations();
|
|
133
134
|
const operations = [];
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
operations.push({ operation, enabled });
|
|
138
|
-
}
|
|
135
|
+
supported.forEach(operation => {
|
|
136
|
+
const enabled = this.getSettings(`preferences.${app}.${operation}.enabled`, defaults.includes(operation));
|
|
137
|
+
operations.push({ operation, enabled });
|
|
139
138
|
});
|
|
140
139
|
return operations;
|
|
141
140
|
}
|
|
@@ -156,7 +155,14 @@ let AppsService = (() => {
|
|
|
156
155
|
return [];
|
|
157
156
|
}
|
|
158
157
|
getAvailableServices(operation) {
|
|
159
|
-
|
|
158
|
+
const serviceIds = this.getServiceIDs();
|
|
159
|
+
const supported = [];
|
|
160
|
+
serviceIds.forEach(serviceKey => {
|
|
161
|
+
if (this.getAppConnection(serviceKey)?.getSupportedOperations().includes(operation)) {
|
|
162
|
+
supported.push(serviceKey);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return supported;
|
|
160
166
|
}
|
|
161
167
|
getName(key) {
|
|
162
168
|
const found = this.serviceMap.find(r => r.key === key);
|
|
@@ -166,6 +172,32 @@ let AppsService = (() => {
|
|
|
166
172
|
const found = this.serviceMap.find(r => r.name === name);
|
|
167
173
|
return found ? found.key : name;
|
|
168
174
|
}
|
|
175
|
+
hasSettings(app) {
|
|
176
|
+
const settings = this.getUserSettings().getValue(`preferences.${app}`, null);
|
|
177
|
+
return settings !== null;
|
|
178
|
+
}
|
|
179
|
+
storeInitialSettings(app) {
|
|
180
|
+
if (this.hasSettings(app))
|
|
181
|
+
return;
|
|
182
|
+
const connection = this.getAppConnection(app);
|
|
183
|
+
if (!connection)
|
|
184
|
+
return;
|
|
185
|
+
const supported = connection.getSupportedOperations();
|
|
186
|
+
const defaults = connection.getDefaultOperations();
|
|
187
|
+
for (const operation of supported) {
|
|
188
|
+
const isDefault = defaults.includes(operation);
|
|
189
|
+
this.getUserSettings().set(`preferences.${app}.${operation}.enabled`, isDefault);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
getServiceIDs() {
|
|
193
|
+
return this.serviceMap.map(m => m.key);
|
|
194
|
+
}
|
|
195
|
+
getAppConnections() {
|
|
196
|
+
return this.serviceMap.map(m => m.connection);
|
|
197
|
+
}
|
|
198
|
+
getAppConnection(serviceKey) {
|
|
199
|
+
return this.serviceMap.find(m => serviceKey === m.key)?.connection;
|
|
200
|
+
}
|
|
169
201
|
getAppDisplayProps(key) {
|
|
170
202
|
const entry = this.serviceMap.find(e => e.key === key);
|
|
171
203
|
const { name, iconUrl } = entry;
|
|
@@ -116,6 +116,12 @@ let StravaAppConnection = (() => {
|
|
|
116
116
|
this.api = new StravaApi();
|
|
117
117
|
return this.api;
|
|
118
118
|
}
|
|
119
|
+
getSupportedOperations() {
|
|
120
|
+
return ['ActivityUpload'];
|
|
121
|
+
}
|
|
122
|
+
getDefaultOperations() {
|
|
123
|
+
return ['ActivityUpload'];
|
|
124
|
+
}
|
|
119
125
|
initAuth() {
|
|
120
126
|
let isInitialized;
|
|
121
127
|
try {
|
|
@@ -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';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncyclistService } from "../../../base/service";
|
|
2
|
-
import { IConnectedApp } from "../../types";
|
|
2
|
+
import { AppsOperation, IConnectedApp } from "../../types";
|
|
3
3
|
import { AppCredentials } from "../types";
|
|
4
4
|
export declare class ConnectedAppService<C extends AppCredentials> extends IncyclistService implements IConnectedApp {
|
|
5
5
|
protected service: any;
|
|
@@ -16,5 +16,7 @@ export declare class ConnectedAppService<C extends AppCredentials> extends Incyc
|
|
|
16
16
|
protected initAuth(): boolean;
|
|
17
17
|
protected checkAuth(): boolean;
|
|
18
18
|
protected ensureInitialized(): boolean;
|
|
19
|
+
getSupportedOperations(): AppsOperation[];
|
|
20
|
+
getDefaultOperations(): AppsOperation[];
|
|
19
21
|
protected getUserSettings(): import("../../../settings").UserSettingsService;
|
|
20
22
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IntervalsApi, IntervalsConfig } from "../base/api";
|
|
2
2
|
import { ConnectedAppService } from "../base/app";
|
|
3
|
+
import { AppsOperation } from "../types";
|
|
3
4
|
import { IntervalsCredentials } from "./types";
|
|
4
5
|
export declare class IntervalsAppConnection extends ConnectedAppService<IntervalsCredentials> {
|
|
5
6
|
protected config: IntervalsConfig;
|
|
@@ -11,6 +12,8 @@ export declare class IntervalsAppConnection extends ConnectedAppService<Interval
|
|
|
11
12
|
isConnected(): boolean;
|
|
12
13
|
getCredentials(): IntervalsCredentials;
|
|
13
14
|
getApi(): IntervalsApi;
|
|
15
|
+
getSupportedOperations(): AppsOperation[];
|
|
16
|
+
getDefaultOperations(): AppsOperation[];
|
|
14
17
|
protected initAuth(): boolean;
|
|
15
18
|
protected updateConfig(config: IntervalsConfig): void;
|
|
16
19
|
protected saveCredentials(config?: IntervalsConfig): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KomootApi } from "../base/api";
|
|
2
2
|
import { ConnectedAppService } from "../base/app";
|
|
3
|
+
import { AppsOperation } from "../types";
|
|
3
4
|
import { KomootAuth, KomootCredentials } from "./types";
|
|
4
5
|
export declare class KomootAppConnection extends ConnectedAppService<KomootCredentials> {
|
|
5
6
|
protected _isConnecting: any;
|
|
@@ -11,7 +12,9 @@ export declare class KomootAppConnection extends ConnectedAppService<KomootCrede
|
|
|
11
12
|
isConnected(): boolean;
|
|
12
13
|
getCredentials(): KomootCredentials;
|
|
13
14
|
getApi(): KomootApi;
|
|
14
|
-
|
|
15
|
+
getSupportedOperations(): AppsOperation[];
|
|
16
|
+
getDefaultOperations(): AppsOperation[];
|
|
17
|
+
protected initAuth(): boolean;
|
|
15
18
|
protected checkAuth(): boolean;
|
|
16
19
|
protected getAuthConfig(): KomootAuth | KomootCredentials;
|
|
17
20
|
protected getUuid(): any;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ActivityUploadFactory } from "../activities/upload";
|
|
2
2
|
import { IncyclistService } from "../base/service";
|
|
3
3
|
import { AppCredentials } from "./base/types";
|
|
4
|
-
import { AppDefinition,
|
|
4
|
+
import { AppDefinition, AppsOperation, IConnectedApp } from "./types";
|
|
5
5
|
export declare class AppsService extends IncyclistService {
|
|
6
|
-
protected readonly services: AppsIntergationSpec;
|
|
7
6
|
protected readonly serviceMap: Array<AppDefinition>;
|
|
8
7
|
constructor();
|
|
9
8
|
openSettings(): {
|
|
@@ -26,6 +25,11 @@ export declare class AppsService extends IncyclistService {
|
|
|
26
25
|
getAvailableServices(operation: AppsOperation): Array<string>;
|
|
27
26
|
getName(key: string): string;
|
|
28
27
|
getKey(name: string): string;
|
|
28
|
+
protected hasSettings(app: string): boolean;
|
|
29
|
+
protected storeInitialSettings(app: string): void;
|
|
30
|
+
protected getServiceIDs(): Array<string>;
|
|
31
|
+
protected getAppConnections(): Array<IConnectedApp>;
|
|
32
|
+
protected getAppConnection(serviceKey: string): IConnectedApp | undefined;
|
|
29
33
|
protected getAppDisplayProps(key: string): {
|
|
30
34
|
name: string;
|
|
31
35
|
key: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StravaApi, StravaConfig } from "../base/api";
|
|
2
2
|
import { ConnectedAppService } from "../base/app";
|
|
3
|
+
import { AppsOperation } from "../types";
|
|
3
4
|
import { StravaCredentials } from "./types";
|
|
4
5
|
export declare class StravaAppConnection extends ConnectedAppService<StravaCredentials> {
|
|
5
6
|
protected config: StravaConfig;
|
|
@@ -12,6 +13,8 @@ export declare class StravaAppConnection extends ConnectedAppService<StravaCrede
|
|
|
12
13
|
isConnected(): boolean;
|
|
13
14
|
getCredentials(): StravaCredentials;
|
|
14
15
|
getApi(): StravaApi;
|
|
16
|
+
getSupportedOperations(): AppsOperation[];
|
|
17
|
+
getDefaultOperations(): AppsOperation[];
|
|
15
18
|
protected initAuth(): boolean;
|
|
16
19
|
protected updateConfig(config: StravaConfig): void;
|
|
17
20
|
protected saveCredentials(config?: StravaConfig): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConnectedAppService } from "./base";
|
|
2
2
|
export type AppsOperation = 'ActivityUpload' | 'WorkoutUpload' | 'WorkoutDownload' | 'RouteDownload' | 'ActivityDownload';
|
|
3
|
-
export type AppsIntergationSpec =
|
|
3
|
+
export type AppsIntergationSpec = Map<AppsOperation, Array<string>>;
|
|
4
4
|
export type AppDefinition = {
|
|
5
5
|
name: string;
|
|
6
6
|
key: string;
|
|
@@ -10,6 +10,8 @@ export type AppDefinition = {
|
|
|
10
10
|
export interface IConnectedApp {
|
|
11
11
|
isConnected(): boolean;
|
|
12
12
|
init(): boolean;
|
|
13
|
+
getSupportedOperations(): AppsOperation[];
|
|
14
|
+
getDefaultOperations(): AppsOperation[];
|
|
13
15
|
}
|
|
14
16
|
export type * from './strava/types';
|
|
15
17
|
export type * from './komoot/types';
|