SYNC: renew license from set license page

This commit is contained in:
SPRINX0\prochazka
2025-07-14 13:41:36 +02:00
committed by Diflow
parent b7e6838d26
commit 16d2a9bf99
3 changed files with 18 additions and 7 deletions

View File

@@ -209,7 +209,7 @@ module.exports = {
},
saveLicenseKey_meta: true,
async saveLicenseKey({ licenseKey, forceSave = false }) {
async saveLicenseKey({ licenseKey, forceSave = false, tryToRenew = false }) {
if (!forceSave) {
const decoded = jwt.decode(licenseKey?.trim());
if (!decoded) {
@@ -221,10 +221,21 @@ module.exports = {
const { exp } = decoded;
if (exp * 1000 < Date.now()) {
return {
status: 'error',
errorMessage: 'License key is expired',
};
let renewed = false;
if (tryToRenew) {
const newLicenseKey = await tryToGetRefreshedLicense(licenseKey);
if (newLicenseKey.status == 'ok') {
licenseKey = newLicenseKey.token;
renewed = true;
}
}
if (!renewed) {
return {
status: 'error',
errorMessage: 'License key is expired',
};
}
}
}