|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { BootProbeIds, BootProbeInfo, BootProbeResult } from 'app/common/BootProbe';
|
|
|
|
|
import { removeTrailingSlash } from 'app/common/gutil';
|
|
|
|
|
import { InstallAPI } from 'app/common/InstallAPI';
|
|
|
|
|
import { getGristConfig } from 'app/common/urlUtils';
|
|
|
|
|
import { Disposable, Observable, UseCBOwner } from 'grainjs';
|
|
|
|
|
|
|
|
|
@ -19,7 +19,7 @@ export class AdminChecks {
|
|
|
|
|
// Keep track of probe results we have received, by probe ID.
|
|
|
|
|
private _results: Map<string, Observable<BootProbeResult>>;
|
|
|
|
|
|
|
|
|
|
constructor(private _parent: Disposable) {
|
|
|
|
|
constructor(private _parent: Disposable, private _installAPI: InstallAPI) {
|
|
|
|
|
this.probes = Observable.create(_parent, []);
|
|
|
|
|
this._results = new Map();
|
|
|
|
|
this._requests = new Map();
|
|
|
|
@ -32,20 +32,14 @@ export class AdminChecks {
|
|
|
|
|
const config = getGristConfig();
|
|
|
|
|
const errMessage = config.errMessage;
|
|
|
|
|
if (!errMessage) {
|
|
|
|
|
// Probe tool URLs are relative to the current URL. Don't trust configuration,
|
|
|
|
|
// because it may be buggy if the user is here looking at the boot page
|
|
|
|
|
// to figure out some problem.
|
|
|
|
|
//
|
|
|
|
|
// We have been careful to make URLs available with appropriate
|
|
|
|
|
// middleware relative to both of the admin panel and the boot page.
|
|
|
|
|
const url = new URL(removeTrailingSlash(document.location.href));
|
|
|
|
|
url.pathname += '/probe';
|
|
|
|
|
const resp = await fetch(url.href);
|
|
|
|
|
const _probes = await resp.json();
|
|
|
|
|
const _probes = await this._installAPI.getChecks().catch(() => undefined);
|
|
|
|
|
if (!this._parent.isDisposed()) {
|
|
|
|
|
this.probes.set(_probes.probes);
|
|
|
|
|
// Currently, no probes are allowed if not admin.
|
|
|
|
|
// May want to relax this to allow some probes that help
|
|
|
|
|
// diagnose some initial auth problems.
|
|
|
|
|
this.probes.set(_probes ? _probes.probes : []);
|
|
|
|
|
}
|
|
|
|
|
return _probes.probes;
|
|
|
|
|
return _probes;
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
@ -63,7 +57,7 @@ export class AdminChecks {
|
|
|
|
|
}
|
|
|
|
|
let request = this._requests.get(id);
|
|
|
|
|
if (!request) {
|
|
|
|
|
request = new AdminCheckRunner(id, this._results, this._parent);
|
|
|
|
|
request = new AdminCheckRunner(this._installAPI, id, this._results, this._parent);
|
|
|
|
|
this._requests.set(id, request);
|
|
|
|
|
}
|
|
|
|
|
request.start();
|
|
|
|
@ -97,16 +91,15 @@ export interface AdminCheckRequest {
|
|
|
|
|
* Manage a single check.
|
|
|
|
|
*/
|
|
|
|
|
export class AdminCheckRunner {
|
|
|
|
|
constructor(public id: string, public results: Map<string, Observable<BootProbeResult>>,
|
|
|
|
|
constructor(private _installAPI: InstallAPI,
|
|
|
|
|
public id: string,
|
|
|
|
|
public results: Map<string, Observable<BootProbeResult>>,
|
|
|
|
|
public parent: Disposable) {
|
|
|
|
|
const url = new URL(removeTrailingSlash(document.location.href));
|
|
|
|
|
url.pathname = url.pathname + '/probe/' + id;
|
|
|
|
|
fetch(url.href).then(async resp => {
|
|
|
|
|
const _probes: BootProbeResult = await resp.json();
|
|
|
|
|
this._installAPI.runCheck(id).then(async result => {
|
|
|
|
|
if (parent.isDisposed()) { return; }
|
|
|
|
|
const ob = results.get(id);
|
|
|
|
|
if (ob) {
|
|
|
|
|
ob.set(_probes);
|
|
|
|
|
ob.set(result);
|
|
|
|
|
}
|
|
|
|
|
}).catch(e => console.error(e));
|
|
|
|
|
}
|
|
|
|
|