Skip to content

Commit 8219dce

Browse files
committed
refactor(maloja): Handle maloja server version use cases for auth/readiness
1 parent 42a5fdf commit 8219dce

File tree

3 files changed

+23
-1612
lines changed

3 files changed

+23
-1612
lines changed

clients/MalojaScrobbler.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import AbstractScrobbleClient from "./AbstractScrobbleClient.js";
22
import request from 'superagent';
33
import dayjs from 'dayjs';
4+
import compareVersions from 'compare-versions';
45
import {
56
buildTrackString,
67
playObjDataMatch,
@@ -17,6 +18,7 @@ export default class MalojaScrobbler extends AbstractScrobbleClient {
1718

1819
requiresAuth = true;
1920
ready = false;
21+
serverVersion;
2022

2123
constructor(name, config = {}, options = {}) {
2224
super('maloja', name, config, options);
@@ -118,7 +120,8 @@ export default class MalojaScrobbler extends AbstractScrobbleClient {
118120
this.logger.warn('Server did not respond with a version. Either the base URL is incorrect or this Maloja server is too old. multi-scrobbler will most likely not work with this server.');
119121
} else {
120122
this.logger.info(`Maloja Server Version: ${versionstring}`);
121-
if (version[0] < 2 || version[1] < 7) {
123+
this.serverVersion = versionstring;
124+
if(compareVersions(versionstring, '2.7.0') < 0) {
122125
this.logger.warn('Maloja Server Version is less than 2.7, please upgrade to ensure compatibility');
123126
}
124127
}
@@ -174,12 +177,6 @@ export default class MalojaScrobbler extends AbstractScrobbleClient {
174177

175178
testAuth = async () => {
176179

177-
// can remove once https://github.com/krateng/maloja/pull/92 is merged
178-
if(!(await this.isReady())) {
179-
this.logger.error(`Could not test auth because server is not ready`);
180-
this.authed = false;
181-
return this.authed;
182-
}
183180
const {url, apiKey} = this.config;
184181
try {
185182
const resp = await this.callApi(request
@@ -206,6 +203,17 @@ export default class MalojaScrobbler extends AbstractScrobbleClient {
206203
});
207204
}
208205
} catch (e) {
206+
if(e.status === 403) {
207+
// may be an older version that doesn't support auth readiness before db upgrade
208+
// and if it was before api was accessible during db build then test would fail during testConnection()
209+
if(compareVersions(this.serverVersion, '2.12.19') < 0) {
210+
if(!(await this.isReady())) {
211+
this.logger.error(`Could not test auth because server is not ready`);
212+
this.authed = false;
213+
return this.authed;
214+
}
215+
}
216+
}
209217
this.logger.error('Auth test failed');
210218
this.logger.error(e);
211219
this.authed = false;

0 commit comments

Comments
 (0)