activation: update features after registering cloudron

This commit is contained in:
Girish Ramakrishnan
2025-10-02 11:18:42 +02:00
parent e255f4158f
commit 5b43de944d

View File

@@ -3,8 +3,6 @@
exports = module.exports = {
getFeatures,
checkSubscription,
getApiServerOrigin,
getWebServerOrigin,
getConsoleServerOrigin,
@@ -20,6 +18,7 @@ exports = module.exports = {
unlinkAccount,
getSubscription,
checkSubscription, // cron hook
isFreePlan,
getAppUpdate,
@@ -175,14 +174,6 @@ async function getState() {
return state;
}
async function checkSubscription() {
// getSubscription() also updates the feature cache
const [error, result] = await safe(getSubscription());
if (error && error.reason !== BoxError.LICENSE_ERROR) return debug('Checking subscription failed:', error.reason, error.message);
debug(`Checking subscription: Cloudron ${result.cloudronId} is on the ${result.plan.name} plan.`);
}
async function getApiServerOrigin() {
return await settings.get(settings.API_SERVER_ORIGIN_KEY) || 'https://api.cloudron.io';
}
@@ -229,6 +220,13 @@ async function getSubscription() {
return response.body;
}
// cron hook
async function checkSubscription() {
const [error, result] = await safe(getSubscription());
if (error) debug('checkSubscription error:', error);
else debug(`checkSubscription: Cloudron ${result.cloudronId} is on the ${result.plan.name} plan.`);
}
function isFreePlan(subscription) {
return !subscription || subscription.plan.id === 'free';
}
@@ -322,6 +320,7 @@ async function registerCloudron3() {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (token) { // when installed using setupToken, this updates the domain record when called during provisioning
debug('registerCloudron3: already registered. Just updating the record.');
await getSubscription();
return await updateCloudron({ domain, version });
}
@@ -340,6 +339,8 @@ async function registerCloudron3() {
await settings.set(settings.APPSTORE_API_TOKEN_KEY, response.body.cloudronToken);
debug(`registerCloudron3: Cloudron registered with id ${response.body.cloudronId}`);
await getSubscription();
}
async function unlinkAccount() {