mirror of https://github.com/bastienwirtz/homer
chore(lint): Apply lint
parent
a5eeb1e44e
commit
1afa0afd00
|
@ -2,16 +2,28 @@
|
||||||
<Generic :item="item">
|
<Generic :item="item">
|
||||||
<template #indicator>
|
<template #indicator>
|
||||||
<div class="notifs">
|
<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 }}
|
{{ running }}
|
||||||
</strong>
|
</strong>
|
||||||
<strong v-if="stopped > 0" class="notif stopped" title="Stopped Containers">
|
<strong
|
||||||
|
v-if="stopped > 0"
|
||||||
|
class="notif stopped"
|
||||||
|
title="Stopped Containers"
|
||||||
|
>
|
||||||
{{ stopped }}
|
{{ stopped }}
|
||||||
</strong>
|
</strong>
|
||||||
<strong v-if="errors > 0" class="notif errors" title="Error">
|
<strong v-if="errors > 0" class="notif errors" title="Error">
|
||||||
{{ errors }}
|
{{ errors }}
|
||||||
</strong>
|
</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
|
Unavailable
|
||||||
</strong>
|
</strong>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,10 +62,14 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch all containers (including stopped) from Docker Socket Proxy
|
// 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) => {
|
.then((containers) => {
|
||||||
this.running = containers.filter(container => container.State === "running").length;
|
this.running = containers.filter(
|
||||||
this.stopped = containers.filter(container => container.State === "exited").length;
|
(container) => container.State === "running",
|
||||||
|
).length;
|
||||||
|
this.stopped = containers.filter(
|
||||||
|
(container) => container.State === "exited",
|
||||||
|
).length;
|
||||||
})
|
})
|
||||||
.catch(handleError);
|
.catch(handleError);
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
item: {
|
item: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
|
@ -50,8 +50,10 @@ export default {
|
||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
isAuthenticated() {
|
isAuthenticated() {
|
||||||
return this.sessionId && this.sessionExpiry && Date.now() < this.sessionExpiry;
|
return (
|
||||||
}
|
this.sessionId && this.sessionExpiry && Date.now() < this.sessionExpiry
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (parseInt(this.item.apiVersion, 10) === 6) {
|
if (parseInt(this.item.apiVersion, 10) === 6) {
|
||||||
|
@ -63,7 +65,7 @@ export default {
|
||||||
this.fetchStatus_v5();
|
this.fetchStatus_v5();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeUnmount() {
|
||||||
if (parseInt(this.item.apiVersion, 10) === 6) {
|
if (parseInt(this.item.apiVersion, 10) === 6) {
|
||||||
this.stopStatusPolling();
|
this.stopStatusPolling();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +81,10 @@ export default {
|
||||||
if (this.localCheckInterval < 1000) {
|
if (this.localCheckInterval < 1000) {
|
||||||
this.localCheckInterval = 1000;
|
this.localCheckInterval = 1000;
|
||||||
}
|
}
|
||||||
this.pollInterval = setInterval(this.fetchStatus, this.localCheckInterval);
|
this.pollInterval = setInterval(
|
||||||
|
this.fetchStatus,
|
||||||
|
this.localCheckInterval,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
stopStatusPolling: function () {
|
stopStatusPolling: function () {
|
||||||
if (this.pollInterval) {
|
if (this.pollInterval) {
|
||||||
|
@ -88,7 +93,9 @@ export default {
|
||||||
},
|
},
|
||||||
loadCachedSession: function () {
|
loadCachedSession: function () {
|
||||||
try {
|
try {
|
||||||
const cachedSession = localStorage.getItem(`pihole_session_${this.item.url}`);
|
const cachedSession = localStorage.getItem(
|
||||||
|
`pihole_session_${this.item.url}`,
|
||||||
|
);
|
||||||
if (cachedSession) {
|
if (cachedSession) {
|
||||||
const session = JSON.parse(cachedSession);
|
const session = JSON.parse(cachedSession);
|
||||||
if (session.expiry > Date.now()) {
|
if (session.expiry > Date.now()) {
|
||||||
|
@ -110,7 +117,10 @@ export default {
|
||||||
},
|
},
|
||||||
authenticate: async function () {
|
authenticate: async function () {
|
||||||
if (!this.item.apikey) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,19 +128,23 @@ export default {
|
||||||
const authResponse = await this.fetch("/api/auth", {
|
const authResponse = await this.fetch("/api/auth", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ password: this.item.apikey }),
|
body: JSON.stringify({ password: this.item.apikey }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (authResponse?.session?.sid) {
|
if (authResponse?.session?.sid) {
|
||||||
this.sessionId = authResponse.session.sid;
|
this.sessionId = authResponse.session.sid;
|
||||||
this.sessionExpiry = Date.now() + (authResponse.session.validity * 1000);
|
this.sessionExpiry =
|
||||||
|
Date.now() + authResponse.session.validity * 1000;
|
||||||
|
|
||||||
localStorage.setItem(`pihole_session_${this.item.url}`, JSON.stringify({
|
localStorage.setItem(
|
||||||
|
`pihole_session_${this.item.url}`,
|
||||||
|
JSON.stringify({
|
||||||
sid: this.sessionId,
|
sid: this.sessionId,
|
||||||
expiry: this.sessionExpiry
|
expiry: this.sessionExpiry,
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
this.retryCount = 0;
|
this.retryCount = 0;
|
||||||
return true;
|
return true;
|
||||||
|
@ -145,7 +159,7 @@ export default {
|
||||||
console.log("Retrying authentication...");
|
console.log("Retrying authentication...");
|
||||||
if (this.retryCount < this.maxRetries) {
|
if (this.retryCount < this.maxRetries) {
|
||||||
this.retryCount++;
|
this.retryCount++;
|
||||||
await new Promise(resolve => setTimeout(resolve, this.retryDelay));
|
await new Promise((resolve) => setTimeout(resolve, this.retryDelay));
|
||||||
return this.fetchStatus();
|
return this.fetchStatus();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -156,7 +170,9 @@ export default {
|
||||||
const authenticated = await this.authenticate();
|
const authenticated = await this.authenticate();
|
||||||
if (!authenticated) return;
|
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) {
|
if (response?.queries?.percent_blocked === undefined) {
|
||||||
throw new Error("Invalid response format");
|
throw new Error("Invalid response format");
|
||||||
|
@ -166,11 +182,17 @@ export default {
|
||||||
this.percent_blocked = response.queries.percent_blocked;
|
this.percent_blocked = response.queries.percent_blocked;
|
||||||
this.retryCount = 0;
|
this.retryCount = 0;
|
||||||
} catch (e) {
|
} 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();
|
this.removeCacheSession();
|
||||||
return this.retryWithDelay();
|
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();
|
this.removeCacheSession();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -185,7 +207,7 @@ export default {
|
||||||
this.status = result.status;
|
this.status = result.status;
|
||||||
this.percent_blocked = result.ads_percentage_today;
|
this.percent_blocked = result.ads_percentage_today;
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
<Generic :item="item">
|
<Generic :item="item">
|
||||||
<template #indicator>
|
<template #indicator>
|
||||||
<div class="notifs">
|
<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 }}
|
{{ streams }}
|
||||||
</strong>
|
</strong>
|
||||||
<strong v-if="series > 0" class="notif series" title="Total Series">
|
<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">
|
<strong v-if="errors > 0" class="notif errors" title="Error">
|
||||||
{{ errors }}
|
{{ errors }}
|
||||||
</strong>
|
</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>
|
</strong>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,7 +64,6 @@ export default {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
this.serverError = true;
|
this.serverError = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fetch(`/status/sessions?X-Plex-Token=${this.item.token}`, {}, false)
|
this.fetch(`/status/sessions?X-Plex-Token=${this.item.token}`, {}, false)
|
||||||
.then((str) => {
|
.then((str) => {
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
|
@ -65,7 +72,6 @@ export default {
|
||||||
this.streams = metadata ? metadata.getAttribute("size") || 0 : 0;
|
this.streams = metadata ? metadata.getAttribute("size") || 0 : 0;
|
||||||
})
|
})
|
||||||
.catch(handleError);
|
.catch(handleError);
|
||||||
|
|
||||||
this.fetch(`/library/sections?X-Plex-Token=${this.item.token}`, {}, false)
|
this.fetch(`/library/sections?X-Plex-Token=${this.item.token}`, {}, false)
|
||||||
.then((str) => {
|
.then((str) => {
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
|
@ -73,7 +79,6 @@ export default {
|
||||||
const directories = xml.getElementsByTagName("Directory");
|
const directories = xml.getElementsByTagName("Directory");
|
||||||
const seriesDirIds = [];
|
const seriesDirIds = [];
|
||||||
const movieDirIds = [];
|
const movieDirIds = [];
|
||||||
|
|
||||||
for (let dir of directories) {
|
for (let dir of directories) {
|
||||||
if (dir.getAttribute("type") === "show") {
|
if (dir.getAttribute("type") === "show") {
|
||||||
seriesDirIds.push(dir.getAttribute("key"));
|
seriesDirIds.push(dir.getAttribute("key"));
|
||||||
|
@ -81,32 +86,39 @@ export default {
|
||||||
movieDirIds.push(dir.getAttribute("key"));
|
movieDirIds.push(dir.getAttribute("key"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let seriesCount = 0;
|
let seriesCount = 0;
|
||||||
Promise.all(seriesDirIds.map(seriesDirId =>
|
Promise.all(
|
||||||
fetch(`${this.endpoint}/library/sections/${seriesDirId}/all?X-Plex-Token=${this.item.token}`)
|
seriesDirIds.map((seriesDirId) =>
|
||||||
.then(response => response.text())
|
fetch(
|
||||||
.then(str => {
|
`${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");
|
const xml = parser.parseFromString(str, "application/xml");
|
||||||
seriesCount += xml.getElementsByTagName("Directory").length;
|
seriesCount += xml.getElementsByTagName("Directory").length;
|
||||||
})
|
})
|
||||||
.catch(handleError)
|
.catch(handleError),
|
||||||
)).then(() => {
|
),
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
this.series = seriesCount;
|
this.series = seriesCount;
|
||||||
})
|
})
|
||||||
.catch(handleError);
|
.catch(handleError);
|
||||||
|
|
||||||
|
|
||||||
let movieCount = 0;
|
let movieCount = 0;
|
||||||
Promise.all(movieDirIds.map(movieDirId =>
|
Promise.all(
|
||||||
fetch(`${this.endpoint}/library/sections/${movieDirId}/all?X-Plex-Token=${this.item.token}`)
|
movieDirIds.map((movieDirId) =>
|
||||||
.then(response => response.text())
|
fetch(
|
||||||
.then(str => {
|
`${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");
|
const xml = parser.parseFromString(str, "application/xml");
|
||||||
movieCount += xml.getElementsByTagName("Video").length;
|
movieCount += xml.getElementsByTagName("Video").length;
|
||||||
})
|
})
|
||||||
.catch(handleError)
|
.catch(handleError),
|
||||||
)).then(() => {
|
),
|
||||||
|
).then(() => {
|
||||||
this.movies = movieCount;
|
this.movies = movieCount;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -91,14 +91,13 @@ export default {
|
||||||
fetchStatus: async function () {
|
fetchStatus: async function () {
|
||||||
try {
|
try {
|
||||||
const response = await this.fetch(
|
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.error = false;
|
||||||
this.stats = response.queue;
|
this.stats = response.queue;
|
||||||
|
|
||||||
// Fetching download speed from "speed" (convert to KB/s if needed)
|
// Fetching download speed from "speed" (convert to KB/s if needed)
|
||||||
this.dlSpeed = parseFloat(response.queue.speed) * 1024; // Convert MB to KB
|
this.dlSpeed = parseFloat(response.queue.speed) * 1024; // Convert MB to KB
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error = true;
|
this.error = true;
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
Loading…
Reference in New Issue