The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Rocket.Chat/app/cloud/server/functions/getWorkspaceLicense.js

42 lines
1.1 KiB

import { HTTP } from 'meteor/http';
import { settings } from '../../../settings';
import { Settings } from '../../../models';
import { getWorkspaceAccessToken } from './getWorkspaceAccessToken';
export function getWorkspaceLicense() {
const token = getWorkspaceAccessToken();
if (!token) {
return { updated: false, license: '' };
}
let licenseResult;
try {
licenseResult = HTTP.get(`${ settings.get('Cloud_Workspace_Registration_Client_Uri') }/license`, {
headers: {
Authorization: `Bearer ${ token }`,
},
});
} catch (e) {
if (e.response && e.response.data && e.response.data.error) {
console.error(`Failed to update license from Rocket.Chat Cloud. Error: ${ e.response.data.error }`);
} else {
console.error(e);
}
return { updated: false, license: '' };
}
const remoteLicense = licenseResult.data;
const currentLicense = settings.get('Cloud_Workspace_License');
if (remoteLicense.updatedAt <= currentLicense._updatedAt) {
return { updated: false, license: '' };
}
Settings.updateValueById('Cloud_Workspace_License', remoteLicense.license);
return { updated: true, license: remoteLicense.license };
}