From ad76093a389f799f029acba3b1d94afb21c55193 Mon Sep 17 00:00:00 2001 From: Molham Date: Sat, 19 Apr 2025 21:10:44 +0200 Subject: [PATCH] modify service.js mixin to accept one more parameter and return full response and use this.fetch in PiHole.vue --- src/components/services/PiHole.vue | 10 +++++++--- src/mixins/service.js | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/services/PiHole.vue b/src/components/services/PiHole.vue index afbc5c6..1703bf3 100644 --- a/src/components/services/PiHole.vue +++ b/src/components/services/PiHole.vue @@ -169,10 +169,14 @@ export default { const authenticated = await this.authenticate(); if (!authenticated) return; } + const options = { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }; + const response = await this.fetch(`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`, options, false, true); - const url = `${this.endpoint}/${`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`.replace(/^\/+/, '')}`; - const response = await fetch(url); - if (response.ok) { const result = await response.json(); if (result?.queries?.percent_blocked !== undefined) { diff --git a/src/mixins/service.js b/src/mixins/service.js index d52fc29..f1e77bf 100644 --- a/src/mixins/service.js +++ b/src/mixins/service.js @@ -12,7 +12,7 @@ export default { } }, methods: { - fetch: function (path, init, json = true) { + fetch: function (path, init, json = true, returnFullResponse = false) { let options = {}; if (this.proxy?.useCredentials) { @@ -58,6 +58,10 @@ export default { ); } + if (returnFullResponse) { + return response; + } + return json ? response.json() : response.text(); }); },