mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
32 lines
899 B
TypeScript
32 lines
899 B
TypeScript
import { Injectable } from '@angular/core'
|
|
import { CanActivate, Router, CanActivateChild } from '@angular/router'
|
|
import { ServerStatus } from '../services/patch-db/data-model'
|
|
import { PatchDbService } from '../services/patch-db/patch-db.service'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class MaintenanceGuard implements CanActivate, CanActivateChild {
|
|
|
|
constructor (
|
|
private readonly router: Router,
|
|
private readonly patch: PatchDbService,
|
|
) { }
|
|
|
|
canActivate (): boolean {
|
|
return this.runServerStatusCheck()
|
|
}
|
|
|
|
canActivateChild (): boolean {
|
|
return this.runServerStatusCheck()
|
|
}
|
|
|
|
private runServerStatusCheck (): boolean {
|
|
if ([ServerStatus.Updating, ServerStatus.BackingUp].includes(this.patch.data['server-info']?.status)) {
|
|
this.router.navigate(['/maintenance'], { replaceUrl: true })
|
|
return false
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
} |