From b89f11adebd4fb7e5d485507a71613b5053650f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Tue, 26 Oct 2021 15:18:36 +0100 Subject: [PATCH] fix: add default number of cassette server side to avoid pairing issues on older machine versions --- lib/pairing.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pairing.js b/lib/pairing.js index 00916abe..929231fa 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -5,6 +5,10 @@ const db = require('./db') const options = require('./options') const logger = require('./logger') +// A machine on an older version (no multicassette code) could be paired with a server with multicassette code. +// This makes sure that the server stores a default value +const DEFAULT_NUMBER_OF_CASSETTES = 2 + function pullToken (token) { const sql = `delete from pairing_tokens where token=$1 @@ -20,7 +24,7 @@ function unpair (deviceId) { return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId])]) } -function pair (token, deviceId, machineModel, numOfCassettes) { +function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) { return pullToken(token) .then(r => { if (r.expired) return false