plexsonic 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.js +28 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plexsonic",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "PlexMusic to OpenSubsonic bridge",
5
5
  "main": "./src/index.js",
6
6
  "bin": {
package/src/server.js CHANGED
@@ -384,6 +384,31 @@ function decodePasswordParam(rawPassword) {
384
384
  }
385
385
  }
386
386
 
387
+ function syncStoredSubsonicPassword(repo, tokenCipher, account, clearPassword) {
388
+ const normalizedPassword = String(clearPassword || '');
389
+ if (!account || !account.id || !normalizedPassword) {
390
+ return;
391
+ }
392
+
393
+ let shouldUpdate = false;
394
+ if (!account.subsonic_password_enc) {
395
+ shouldUpdate = true;
396
+ } else {
397
+ try {
398
+ const decrypted = tokenCipher.decrypt(account.subsonic_password_enc);
399
+ if (decrypted !== normalizedPassword) {
400
+ shouldUpdate = true;
401
+ }
402
+ } catch {
403
+ shouldUpdate = true;
404
+ }
405
+ }
406
+
407
+ if (shouldUpdate) {
408
+ repo.updateSubsonicPasswordEnc(account.id, tokenCipher.encrypt(normalizedPassword));
409
+ }
410
+ }
411
+
387
412
  async function authenticateSubsonicRequest(request, reply, repo, tokenCipher) {
388
413
  const username = normalizeUsername(getRequestParam(request, 'u'));
389
414
  const passwordRaw = normalizePassword(getRequestParam(request, 'p'));
@@ -457,9 +482,7 @@ async function authenticateSubsonicRequest(request, reply, repo, tokenCipher) {
457
482
  return null;
458
483
  }
459
484
 
460
- if (!account.subsonic_password_enc) {
461
- repo.updateSubsonicPasswordEnc(account.id, tokenCipher.encrypt(decodedPassword));
462
- }
485
+ syncStoredSubsonicPassword(repo, tokenCipher, account, decodedPassword);
463
486
 
464
487
  return account;
465
488
  }
@@ -2397,9 +2420,7 @@ export async function buildServer(config = loadConfig()) {
2397
2420
  return reply.code(401).type('text/html; charset=utf-8').send(loginPage('Invalid username or password.'));
2398
2421
  }
2399
2422
 
2400
- if (!account.subsonic_password_enc) {
2401
- repo.updateSubsonicPasswordEnc(account.id, tokenCipher.encrypt(password));
2402
- }
2423
+ syncStoredSubsonicPassword(repo, tokenCipher, account, password);
2403
2424
 
2404
2425
  request.session.accountId = account.id;
2405
2426
  request.session.username = account.username;
@@ -2457,9 +2478,7 @@ export async function buildServer(config = loadConfig()) {
2457
2478
  });
2458
2479
  }
2459
2480
 
2460
- if (!account.subsonic_password_enc) {
2461
- repo.updateSubsonicPasswordEnc(account.id, tokenCipher.encrypt(password));
2462
- }
2481
+ syncStoredSubsonicPassword(repo, tokenCipher, account, password);
2463
2482
 
2464
2483
  request.session.accountId = account.id;
2465
2484
  request.session.username = account.username;