modify service.js mixin to accept one more parameter and return full response and use this.fetch in PiHole.vue

pull/923/head
Molham 2025-04-19 21:10:44 +02:00 committed by Bastien Wirtz
parent 9e314c960b
commit ad76093a38
2 changed files with 12 additions and 4 deletions

View File

@ -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) {

View File

@ -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();
});
},