@@ -39,7 +39,8 @@ import {
3939 DARK_MODE ,
4040 CUSTOM_COLUMNS ,
4141 OAUTH_DOMAIN ,
42- OAUTH_PROVIDER
42+ OAUTH_PROVIDER ,
43+ LATEST_CS_VERSION
4344} from '@/store/mutation-types'
4445
4546const user = {
@@ -170,6 +171,7 @@ const user = {
170171 vueProps . $localStorage . set ( OAUTH_PROVIDER , provider )
171172 } ,
172173 SET_LATEST_VERSION : ( state , version ) => {
174+ vueProps . $localStorage . set ( LATEST_CS_VERSION , version )
173175 state . latestVersion = version
174176 }
175177 } ,
@@ -216,7 +218,8 @@ const user = {
216218 commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
217219 commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
218220 commit ( 'SET_LOGIN_FLAG' , false )
219- commit ( 'SET_LATEST_VERSION' , '' )
221+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
222+ commit ( 'SET_LATEST_VERSION' , latestVersion )
220223 notification . destroy ( )
221224
222225 resolve ( )
@@ -282,10 +285,12 @@ const user = {
282285 const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
283286 const domainStore = vueProps . $localStorage . get ( DOMAIN_STORE , { } )
284287 const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
288+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
285289 const hasAuth = Object . keys ( cachedApis ) . length > 0
286290
287291 commit ( 'SET_DOMAIN_STORE' , domainStore )
288292 commit ( 'SET_DARK_MODE' , darkMode )
293+ commit ( 'SET_LATEST_VERSION' , latestVersion )
289294 if ( hasAuth ) {
290295 console . log ( 'Login detected, using cached APIs' )
291296 commit ( 'SET_ZONES' , cachedZones )
@@ -299,20 +304,7 @@ const user = {
299304 const result = response . listusersresponse . user [ 0 ]
300305 commit ( 'SET_INFO' , result )
301306 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
302- if ( result . rolename === 'Root Admin' ) {
303- axios . get (
304- 'https://api.github.com/repos/apache/cloudstack/releases'
305- ) . then ( response => {
306- for ( const release of response ) {
307- if ( release . tag_name . toLowerCase ( ) . includes ( 'rc' ) ) {
308- continue
309- } else {
310- commit ( 'SET_LATEST_VERSION' , release . tag_name )
311- break
312- }
313- }
314- } ) . catch ( ignored => { } )
315- }
307+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
316308 resolve ( cachedApis )
317309 } ) . catch ( error => {
318310 reject ( error )
@@ -393,6 +385,7 @@ const user = {
393385 const result = response . listusersresponse . user [ 0 ]
394386 commit ( 'SET_INFO' , result )
395387 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
388+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
396389 } ) . catch ( error => {
397390 reject ( error )
398391 } )
@@ -543,6 +536,22 @@ const user = {
543536 SetDomainStore ( { commit } , domainStore ) {
544537 commit ( 'SET_DOMAIN_STORE' , domainStore )
545538 } ,
539+ SetCsLatestVersion ( { commit } , rolename ) {
540+ if ( rolename === 'Root Admin' && ( + new Date ( ) - store . getters . latestVersion . fetchedTs ) > 24 * 60 * 60 * 1000 ) {
541+ axios . get (
542+ 'https://api.github.com/repos/apache/cloudstack/releases'
543+ ) . then ( response => {
544+ for ( const release of response ) {
545+ if ( release . tag_name . toLowerCase ( ) . includes ( 'rc' ) ) {
546+ continue
547+ } else {
548+ commit ( 'SET_LATEST_VERSION' , { version : release . tag_name , fetchedTs : ( + new Date ( ) ) } )
549+ break
550+ }
551+ }
552+ } ) . catch ( ignored => { } )
553+ }
554+ } ,
546555 SetDarkMode ( { commit } , darkMode ) {
547556 commit ( 'SET_DARK_MODE' , darkMode )
548557 } ,
0 commit comments