reset the api_v5 function to fetch the remote api with this.fetch

pull/923/head
Molham 2025-04-19 15:19:08 +02:00 committed by Bastien Wirtz
parent 59b0ed7688
commit 07207dca55
1 changed files with 12 additions and 25 deletions

View File

@ -42,7 +42,7 @@ export default {
}), }),
computed: { computed: {
percentage: function () { percentage: function () {
if (typeof this.percent_blocked === 'number' && this.percent_blocked >= 0) { if (this.percent_blocked) {
return this.percent_blocked.toFixed(1); return this.percent_blocked.toFixed(1);
} }
return ""; return "";
@ -187,37 +187,24 @@ export default {
throw new Error(`HTTP error: ${response.status}`); throw new Error(`HTTP error: ${response.status}`);
} }
} catch (e) { } catch (e) {
if (e.includes("HTTP error: 401") || e.includes("HTTP error: 403")) { if (e.message.includes("HTTP error: 401") || e.message.includes("HTTP error: 403")) {
this.removeCacheSession(); this.removeCacheSession();
return this.retryWithDelay(); return this.retryWithDelay();
} }
this.handleError(`Failed to fetch status: ${e}`, "disabled"); this.handleError(`Failed to fetch status: ${e.message || e}`, "disabled");
this.removeCacheSession(); this.removeCacheSession();
} }
}, },
async fetchStatus_v5() { async fetchStatus_v5() {
try { const authQueryParams = this.item.apikey
const params = {}; ? `?summaryRaw&auth=${this.item.apikey}`
if (this.item.apikey) { : "";
params.auth = this.item.apikey; const result = await this.fetch(`/api.php${authQueryParams}`).catch((e) =>
} this.handleError(`Failed to fetch status: ${e}`, "disabled"),
const url = new URL(`${this.endpoint}/api.php`); );
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
const response = await fetch(url); this.status = result.status;
this.status = response.status.toString();
if (response.ok) {
const result = await response.json();
if (result?.ads_percentage_today !== undefined) {
this.percent_blocked = result.ads_percentage_today; this.percent_blocked = result.ads_percentage_today;
}
} else {
throw new Error(`HTTP error: ${response.status}`);
}
} catch (e) {
this.handleError(`Failed to fetch v5 status: ${e}`, "error");
}
}, },
} }
}; };