From c582902902bb2a5ee7f95dbbedf6480e8c52a5be Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Wed, 14 Aug 2024 13:12:06 +0200 Subject: [PATCH] save license key --- packages/api/src/controllers/auth.js | 1 + packages/api/src/controllers/config.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/api/src/controllers/auth.js b/packages/api/src/controllers/auth.js index fb456542..c7845a9f 100644 --- a/packages/api/src/controllers/auth.js +++ b/packages/api/src/controllers/auth.js @@ -30,6 +30,7 @@ function authMiddleware(req, res, next) { '/config/get', '/config/logout', '/config/get-settings', + '/config/save-license-key', '/auth/oauth-token', '/auth/login', '/auth/redirect', diff --git a/packages/api/src/controllers/config.js b/packages/api/src/controllers/config.js index 67379e29..26cd5845 100644 --- a/packages/api/src/controllers/config.js +++ b/packages/api/src/controllers/config.js @@ -12,8 +12,8 @@ const currentVersion = require('../currentVersion'); const platformInfo = require('../utility/platformInfo'); const connections = require('../controllers/connections'); const { getAuthProviderFromReq } = require('../auth/authProvider'); -const isElectron = require('is-electron'); const { checkLicense, checkLicenseKey } = require('../utility/checkLicense'); +const { storageWriteConfig } = require('./storageDb'); const lock = new AsyncLock(); @@ -126,7 +126,7 @@ module.exports = { const settingsText = await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }); return { ...this.fillMissingSettings(JSON.parse(settingsText)), - 'other.licenseKey': await this.loadLicenseKey(), + 'other.licenseKey': platformInfo.isElectron ? await this.loadLicenseKey() : undefined, }; } catch (err) { return this.fillMissingSettings({}); @@ -145,7 +145,11 @@ module.exports = { saveLicenseKey_meta: true, async saveLicenseKey({ licenseKey }) { try { - await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey); + if (process.env.STORAGE_DATABASE) { + await storageWriteConfig('license', { licenseKey }); + } else { + await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey); + } socket.emitChanged(`config-changed`); } catch (err) { return null;