mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
feat: API endpoint /stats/getViewsByLibraryType
This commit is contained in:
@@ -516,6 +516,35 @@ router.get("/getViewsByHour", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/getViewsByLibraryType", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { days = 30 } = req.query;
|
||||||
|
|
||||||
|
const { rows } = await db.query(`
|
||||||
|
SELECT COALESCE(i."Type", 'Other') AS type, COUNT(a."NowPlayingItemId") AS count
|
||||||
|
FROM jf_playback_activity a LEFT JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId"
|
||||||
|
WHERE a."ActivityDateInserted" BETWEEN NOW() - CAST($1 || ' days' as INTERVAL) AND NOW()
|
||||||
|
GROUP BY i."Type"
|
||||||
|
`, [days]);
|
||||||
|
|
||||||
|
const supportedTypes = new Set(["Audio", "Movie", "Series", "Other"]);
|
||||||
|
const reorganizedData = {};
|
||||||
|
|
||||||
|
rows.forEach((item) => {
|
||||||
|
const { type, count } = item;
|
||||||
|
|
||||||
|
if (!supportedTypes.has(type)) return;
|
||||||
|
reorganizedData[type] = count;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(reorganizedData);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
res.status(503);
|
||||||
|
res.send(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/getGenreUserStats", async (req, res) => {
|
router.get("/getGenreUserStats", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { size = 50, page = 1, userid } = req.query;
|
const { size = 50, page = 1, userid } = req.query;
|
||||||
|
|||||||
@@ -3644,6 +3644,53 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/stats/getViewsByLibraryType": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Stats"
|
||||||
|
],
|
||||||
|
"description": "",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "authorization",
|
||||||
|
"in": "header",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "x-api-token",
|
||||||
|
"in": "header",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "req",
|
||||||
|
"in": "query",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "days",
|
||||||
|
"in": "query",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized"
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "Forbidden"
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Not Found"
|
||||||
|
},
|
||||||
|
"503": {
|
||||||
|
"description": "Service Unavailable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/stats/getGenreUserStats": {
|
"/stats/getGenreUserStats": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
Reference in New Issue
Block a user