chore(lint): Apply lint

pull/925/head
Bastien Wirtz 2025-05-04 15:15:12 +02:00
parent a5eeb1e44e
commit 1afa0afd00
4 changed files with 109 additions and 60 deletions

View File

@ -2,16 +2,28 @@
<Generic :item="item">
<template #indicator>
<div class="notifs">
<strong v-if="running > 0" class="notif running" title="Running Containers">
<strong
v-if="running > 0"
class="notif running"
title="Running Containers"
>
{{ running }}
</strong>
<strong v-if="stopped > 0" class="notif stopped" title="Stopped Containers">
<strong
v-if="stopped > 0"
class="notif stopped"
title="Stopped Containers"
>
{{ stopped }}
</strong>
<strong v-if="errors > 0" class="notif errors" title="Error">
{{ errors }}
</strong>
<strong v-if="serverError" class="notif errors" title="Connection error to Docker Socket Proxy API">
<strong
v-if="serverError"
class="notif errors"
title="Connection error to Docker Socket Proxy API"
>
Unavailable
</strong>
</div>
@ -50,10 +62,14 @@ export default {
};
// Fetch all containers (including stopped) from Docker Socket Proxy
this.fetch('/containers/json?all=true') // Docker endpoint for container statuses
this.fetch("/containers/json?all=true") // Docker endpoint for container statuses
.then((containers) => {
this.running = containers.filter(container => container.State === "running").length;
this.stopped = containers.filter(container => container.State === "exited").length;
this.running = containers.filter(
(container) => container.State === "running",
).length;
this.stopped = containers.filter(
(container) => container.State === "exited",
).length;
})
.catch(handleError);
},

View File

@ -28,7 +28,7 @@ export default {
props: {
item: {
type: Object,
required: true
required: true,
},
},
data: () => ({
@ -50,8 +50,10 @@ export default {
return "";
},
isAuthenticated() {
return this.sessionId && this.sessionExpiry && Date.now() < this.sessionExpiry;
}
return (
this.sessionId && this.sessionExpiry && Date.now() < this.sessionExpiry
);
},
},
created() {
if (parseInt(this.item.apiVersion, 10) === 6) {
@ -63,23 +65,26 @@ export default {
this.fetchStatus_v5();
}
},
beforeDestroy() {
beforeUnmount() {
if (parseInt(this.item.apiVersion, 10) === 6) {
this.stopStatusPolling();
}
},
methods: {
handleError: function (error, status) {
console.error(error);
this.subtitle = error;
this.status = status;
console.error(error);
this.subtitle = error;
this.status = status;
},
startStatusPolling: function () {
this.fetchStatus();
if (this.localCheckInterval < 1000) {
this.localCheckInterval = 1000;
}
this.pollInterval = setInterval(this.fetchStatus, this.localCheckInterval);
this.pollInterval = setInterval(
this.fetchStatus,
this.localCheckInterval,
);
},
stopStatusPolling: function () {
if (this.pollInterval) {
@ -88,7 +93,9 @@ export default {
},
loadCachedSession: function () {
try {
const cachedSession = localStorage.getItem(`pihole_session_${this.item.url}`);
const cachedSession = localStorage.getItem(
`pihole_session_${this.item.url}`,
);
if (cachedSession) {
const session = JSON.parse(cachedSession);
if (session.expiry > Date.now()) {
@ -110,7 +117,10 @@ export default {
},
authenticate: async function () {
if (!this.item.apikey) {
this.handleError("API key is required for PiHole authentication", "disabled");
this.handleError(
"API key is required for PiHole authentication",
"disabled",
);
return false;
}
@ -118,20 +128,24 @@ export default {
const authResponse = await this.fetch("/api/auth", {
method: "POST",
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json",
},
body: JSON.stringify({ password: this.item.apikey }),
});
if (authResponse?.session?.sid) {
this.sessionId = authResponse.session.sid;
this.sessionExpiry = Date.now() + (authResponse.session.validity * 1000);
localStorage.setItem(`pihole_session_${this.item.url}`, JSON.stringify({
sid: this.sessionId,
expiry: this.sessionExpiry
}));
this.sessionExpiry =
Date.now() + authResponse.session.validity * 1000;
localStorage.setItem(
`pihole_session_${this.item.url}`,
JSON.stringify({
sid: this.sessionId,
expiry: this.sessionExpiry,
}),
);
this.retryCount = 0;
return true;
}
@ -145,7 +159,7 @@ export default {
console.log("Retrying authentication...");
if (this.retryCount < this.maxRetries) {
this.retryCount++;
await new Promise(resolve => setTimeout(resolve, this.retryDelay));
await new Promise((resolve) => setTimeout(resolve, this.retryDelay));
return this.fetchStatus();
}
return false;
@ -156,7 +170,9 @@ export default {
const authenticated = await this.authenticate();
if (!authenticated) return;
}
const response = await this.fetch(`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`);
const response = await this.fetch(
`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`,
);
if (response?.queries?.percent_blocked === undefined) {
throw new Error("Invalid response format");
@ -166,11 +182,17 @@ export default {
this.percent_blocked = response.queries.percent_blocked;
this.retryCount = 0;
} catch (e) {
if (e.message.includes("401 error") || e.message.includes("403 error")) {
if (
e.message.includes("401 error") ||
e.message.includes("403 error")
) {
this.removeCacheSession();
return this.retryWithDelay();
}
this.handleError(`Failed to fetch status: ${e.message || e}`, "disabled");
this.handleError(
`Failed to fetch status: ${e.message || e}`,
"disabled",
);
this.removeCacheSession();
}
},
@ -185,7 +207,7 @@ export default {
this.status = result.status;
this.percent_blocked = result.ads_percentage_today;
},
}
},
};
</script>

View File

@ -2,7 +2,11 @@
<Generic :item="item">
<template #indicator>
<div class="notifs">
<strong v-if="streams > 0" class="notif activity" title="Active Streams">
<strong
v-if="streams > 0"
class="notif activity"
title="Active Streams"
>
{{ streams }}
</strong>
<strong v-if="series > 0" class="notif series" title="Total Series">
@ -17,7 +21,11 @@
<strong v-if="errors > 0" class="notif errors" title="Error">
{{ errors }}
</strong>
<strong v-if="serverError" class="notif errors" title="Connection error to Plex API, check url and token in config.yml">
<strong
v-if="serverError"
class="notif errors"
title="Connection error to Plex API, check url and token in config.yml"
>
?
</strong>
</div>
@ -56,7 +64,6 @@ export default {
console.error(e);
this.serverError = true;
};
this.fetch(`/status/sessions?X-Plex-Token=${this.item.token}`, {}, false)
.then((str) => {
const parser = new DOMParser();
@ -65,7 +72,6 @@ export default {
this.streams = metadata ? metadata.getAttribute("size") || 0 : 0;
})
.catch(handleError);
this.fetch(`/library/sections?X-Plex-Token=${this.item.token}`, {}, false)
.then((str) => {
const parser = new DOMParser();
@ -73,7 +79,6 @@ export default {
const directories = xml.getElementsByTagName("Directory");
const seriesDirIds = [];
const movieDirIds = [];
for (let dir of directories) {
if (dir.getAttribute("type") === "show") {
seriesDirIds.push(dir.getAttribute("key"));
@ -81,32 +86,39 @@ export default {
movieDirIds.push(dir.getAttribute("key"));
}
}
let seriesCount = 0;
Promise.all(seriesDirIds.map(seriesDirId =>
fetch(`${this.endpoint}/library/sections/${seriesDirId}/all?X-Plex-Token=${this.item.token}`)
.then(response => response.text())
.then(str => {
const xml = parser.parseFromString(str, "application/xml");
seriesCount += xml.getElementsByTagName("Directory").length;
})
.catch(handleError)
)).then(() => {
this.series = seriesCount;
})
.catch(handleError);
Promise.all(
seriesDirIds.map((seriesDirId) =>
fetch(
`${this.endpoint}/library/sections/${seriesDirId}/all?X-Plex-Token=${this.item.token}`,
)
.then((response) => response.text())
.then((str) => {
const xml = parser.parseFromString(str, "application/xml");
seriesCount += xml.getElementsByTagName("Directory").length;
})
.catch(handleError),
),
)
.then(() => {
this.series = seriesCount;
})
.catch(handleError);
let movieCount = 0;
Promise.all(movieDirIds.map(movieDirId =>
fetch(`${this.endpoint}/library/sections/${movieDirId}/all?X-Plex-Token=${this.item.token}`)
.then(response => response.text())
.then(str => {
const xml = parser.parseFromString(str, "application/xml");
movieCount += xml.getElementsByTagName("Video").length;
})
.catch(handleError)
)).then(() => {
Promise.all(
movieDirIds.map((movieDirId) =>
fetch(
`${this.endpoint}/library/sections/${movieDirId}/all?X-Plex-Token=${this.item.token}`,
)
.then((response) => response.text())
.then((str) => {
const xml = parser.parseFromString(str, "application/xml");
movieCount += xml.getElementsByTagName("Video").length;
})
.catch(handleError),
),
).then(() => {
this.movies = movieCount;
});
})

View File

@ -91,14 +91,13 @@ export default {
fetchStatus: async function () {
try {
const response = await this.fetch(
`/api?output=json&apikey=${this.item.apikey}&mode=queue`
`/api?output=json&apikey=${this.item.apikey}&mode=queue`,
);
this.error = false;
this.stats = response.queue;
// Fetching download speed from "speed" (convert to KB/s if needed)
this.dlSpeed = parseFloat(response.queue.speed) * 1024; // Convert MB to KB
} catch (e) {
this.error = true;
console.error(e);