mirror of https://github.com/bastienwirtz/homer
Improve PiHole status
parent
6344970eb6
commit
51b4649628
|
@ -162,16 +162,23 @@ export default {
|
||||||
const authenticated = await this.authenticate();
|
const authenticated = await this.authenticate();
|
||||||
if (!authenticated) return;
|
if (!authenticated) return;
|
||||||
}
|
}
|
||||||
const response = await this.fetch(
|
const summary_response = await this.fetch(
|
||||||
`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`,
|
`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");
|
throw new Error("Invalid response format");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = "enabled";
|
this.status = status_response.blocking;
|
||||||
this.percent_blocked = response.queries.percent_blocked;
|
this.percent_blocked = summary_response.queries.percent_blocked;
|
||||||
this.retryCount = 0;
|
this.retryCount = 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const isAuthError =
|
const isAuthError =
|
||||||
|
@ -182,7 +189,7 @@ export default {
|
||||||
}
|
}
|
||||||
this.handleError(
|
this.handleError(
|
||||||
`Failed to fetch status: ${e.message || e}`,
|
`Failed to fetch status: ${e.message || e}`,
|
||||||
"disabled",
|
"error",
|
||||||
);
|
);
|
||||||
this.removeCacheSession();
|
this.removeCacheSession();
|
||||||
}
|
}
|
||||||
|
@ -192,7 +199,7 @@ export default {
|
||||||
? `?summaryRaw&auth=${this.item.apikey}`
|
? `?summaryRaw&auth=${this.item.apikey}`
|
||||||
: "";
|
: "";
|
||||||
const result = await this.fetch(`/api.php${authQueryParams}`).catch((e) =>
|
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;
|
this.status = result.status;
|
||||||
|
|
Loading…
Reference in New Issue