mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
7c84ef8c2d
closes https://github.com/TryGhost/Team/issues/2400 - used semver comparison to detect when the app version is less than the content-version header in any API response to toggle `upgradeStatus.requiresRefresh` that is used to conditionally show the upgrade banner - only works on minors as we don't store the full Ghost patch version in `config.APP.version`
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import Service, {inject as service} from '@ember/service';
|
|
import classic from 'ember-classic-decorator';
|
|
import {get, set} from '@ember/object';
|
|
import {htmlSafe} from '@ember/template';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
@classic
|
|
export default class UpgradeStatusService extends Service {
|
|
@service notifications;
|
|
|
|
@tracked refreshRequired = false;
|
|
|
|
isRequired = false;
|
|
message = '';
|
|
|
|
// called when notifications are fetched during app boot for notifications
|
|
// where the `location` is not 'top' and `custom` is false
|
|
handleUpgradeNotification(notification) {
|
|
let message = get(notification, 'message');
|
|
set(this, 'message', htmlSafe(message));
|
|
}
|
|
|
|
// called when a MaintenanceError is encountered
|
|
maintenanceAlert() {
|
|
this.notifications.showAlert(
|
|
'Sorry, Ghost is currently undergoing maintenance, please wait a moment then try again.',
|
|
{type: 'error', key: 'api-error.under-maintenance'}
|
|
);
|
|
}
|
|
|
|
// called when a VersionMismatchError is encountered
|
|
requireUpgrade() {
|
|
set(this, 'isRequired', true);
|
|
this.notifications.showAlert(
|
|
'Ghost has been upgraded, please copy any unsaved data and refresh the page to continue.',
|
|
{type: 'error', key: 'api-error.upgrade-required'}
|
|
);
|
|
}
|
|
}
|