wipe caches on version update

This commit is contained in:
Timo 2021-04-26 21:29:47 +03:00
parent 052347c457
commit b6f25d7412

View File

@ -4,6 +4,7 @@ import { tap } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { Title } from '@angular/platform-browser';
import { version } from '../../../../../../package.json';
import { CacheApiService, wipeCaches } from '@redaction/red-cache';
export enum AppConfigKey {
OAUTH_URL = 'OAUTH_URL',
@ -33,14 +34,23 @@ export enum AppConfigKey {
export class AppConfigService {
private _config: { [key in AppConfigKey]?: any } = {};
constructor(private readonly _httpClient: HttpClient, private readonly _titleService: Title) {}
constructor(private readonly _httpClient: HttpClient, private readonly _cacheApiService: CacheApiService, private readonly _titleService: Title) {}
loadAppConfig(): Observable<any> {
this._cacheApiService.getCachedValue(AppConfigKey.FRONTEND_APP_VERSION).then(async (lastVersion) => {
console.log('[REDACTION] Last app version: ', lastVersion, ' current version ', version);
if (lastVersion !== version) {
console.log('[REDACTION] Version-missmatch - wiping caches!');
await wipeCaches();
}
await this._cacheApiService.cacheValue(AppConfigKey.FRONTEND_APP_VERSION, version);
});
return this._httpClient.get<any>('/assets/config/config.json').pipe(
tap((config) => {
console.log('[REDACTION] Started with config: ', config);
this._config = config;
this._config['FRONTEND_APP_VERSION'] = version;
this._config[AppConfigKey.FRONTEND_APP_VERSION] = version;
this._titleService.setTitle(this.getConfig(AppConfigKey.APP_NAME, 'DDA-R'));
})
);