From b6f25d7412085aaaf0ed45010776015cd4f66336 Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 26 Apr 2021 21:29:47 +0300 Subject: [PATCH] wipe caches on version update --- .../app/modules/app-config/app-config.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/red-ui/src/app/modules/app-config/app-config.service.ts b/apps/red-ui/src/app/modules/app-config/app-config.service.ts index 6291a9352..ba0d7ee79 100644 --- a/apps/red-ui/src/app/modules/app-config/app-config.service.ts +++ b/apps/red-ui/src/app/modules/app-config/app-config.service.ts @@ -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 { + 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('/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')); }) );