mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
Merge branches 'unstable' and 'unstable' of https://github.com/CyferShepard/Jellystat into unstable
This commit is contained in:
@@ -407,9 +407,9 @@ router.post("/getLibraryLastPlayed", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/getViewsOverTime", async (req, res) => {
|
||||
router.get("/getViewsOverTime", async (req, res) => {
|
||||
try {
|
||||
const { days } = req.body;
|
||||
const { days } = req.query;
|
||||
let _days = days;
|
||||
if (days === undefined) {
|
||||
_days = 30;
|
||||
@@ -446,9 +446,9 @@ router.post("/getViewsOverTime", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/getViewsByDays", async (req, res) => {
|
||||
router.get("/getViewsByDays", async (req, res) => {
|
||||
try {
|
||||
const { days } = req.body;
|
||||
const { days } = req.query;
|
||||
let _days = days;
|
||||
if (days === undefined) {
|
||||
_days = 30;
|
||||
@@ -481,9 +481,9 @@ router.post("/getViewsByDays", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/getViewsByHour", async (req, res) => {
|
||||
router.get("/getViewsByHour", async (req, res) => {
|
||||
try {
|
||||
const { days } = req.body;
|
||||
const { days } = req.query;
|
||||
let _days = days;
|
||||
if (days === undefined) {
|
||||
_days = 30;
|
||||
@@ -516,6 +516,41 @@ router.post("/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"]);
|
||||
/** @type {Map<string, number>} */
|
||||
const reorganizedData = new Map();
|
||||
|
||||
rows.forEach((item) => {
|
||||
const { type, count } = item;
|
||||
|
||||
if (!supportedTypes.has(type)) return;
|
||||
reorganizedData.set(type, count);
|
||||
});
|
||||
|
||||
supportedTypes.forEach((type) => {
|
||||
if (reorganizedData.has(type)) return;
|
||||
reorganizedData.set(type, 0);
|
||||
});
|
||||
|
||||
res.send(Object.fromEntries(reorganizedData));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(503);
|
||||
res.send(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/getGenreUserStats", async (req, res) => {
|
||||
try {
|
||||
const { size = 50, page = 1, userid } = req.query;
|
||||
|
||||
@@ -3504,7 +3504,7 @@
|
||||
}
|
||||
},
|
||||
"/stats/getViewsOverTime": {
|
||||
"post": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Stats"
|
||||
],
|
||||
@@ -3526,16 +3526,9 @@
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"days": {
|
||||
"example": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
"name": "days",
|
||||
"in": "query",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -3558,7 +3551,7 @@
|
||||
}
|
||||
},
|
||||
"/stats/getViewsByDays": {
|
||||
"post": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Stats"
|
||||
],
|
||||
@@ -3580,16 +3573,9 @@
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"days": {
|
||||
"example": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
"name": "days",
|
||||
"in": "query",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -3612,7 +3598,7 @@
|
||||
}
|
||||
},
|
||||
"/stats/getViewsByHour": {
|
||||
"post": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Stats"
|
||||
],
|
||||
@@ -3634,16 +3620,56 @@
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"days": {
|
||||
"example": "any"
|
||||
}
|
||||
}
|
||||
}
|
||||
"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/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": {
|
||||
|
||||
Reference in New Issue
Block a user