Improve PiHole status

pull/887/merge
tanasegabriel 2025-05-06 17:09:36 +00:00 committed by Bastien Wirtz
parent 6344970eb6
commit 51b4649628
1 changed files with 13 additions and 6 deletions

View File

@ -162,16 +162,23 @@ export default {
const authenticated = await this.authenticate();
if (!authenticated) return;
}
const response = await this.fetch(
const summary_response = await this.fetch(
`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`,
);
if (response?.queries?.percent_blocked === undefined) {
const status_response = await this.fetch(
`api/dns/blocking?sid=${encodeURIComponent(this.sessionId)}`,
);
if (
summary_response?.queries?.percent_blocked === undefined ||
status_response?.blocking === undefined
) {
throw new Error("Invalid response format");
}
this.status = "enabled";
this.percent_blocked = response.queries.percent_blocked;
this.status = status_response.blocking;
this.percent_blocked = summary_response.queries.percent_blocked;
this.retryCount = 0;
} catch (e) {
const isAuthError =
@ -182,7 +189,7 @@ export default {
}
this.handleError(
`Failed to fetch status: ${e.message || e}`,
"disabled",
"error",
);
this.removeCacheSession();
}
@ -192,7 +199,7 @@ export default {
? `?summaryRaw&auth=${this.item.apikey}`
: "";
const result = await this.fetch(`/api.php${authQueryParams}`).catch((e) =>
this.handleError(`Failed to fetch status: ${e}`, "disabled"),
this.handleError(`Failed to fetch status: ${e}`, "error"),
);
this.status = result.status;