From 2de6616129a434494e5c2af4252a0664f1465a8a Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Fri, 2 May 2025 08:04:56 +0200 Subject: [PATCH 01/24] bump version to 1.1.7 in package.json and package-lock.json --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c04afa4..f9449fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jfstat", - "version": "1.1.6", + "version": "1.1.7", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index eb28e84..79a9494 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jfstat", - "version": "1.1.6", + "version": "1.1.7", "private": true, "main": "src/index.jsx", "scripts": { From f05d9fb948ecbf205c5785ce256e36f08a4e3e62 Mon Sep 17 00:00:00 2001 From: Sanidhya Singh Date: Mon, 5 May 2025 15:39:05 +0530 Subject: [PATCH 02/24] Initial changes for total time view --- ...atch_stats_over_time_include_total_time.js | 121 ++++++++++++++++++ public/locales/en-UK/translation.json | 4 +- src/pages/css/statCard.css | 9 ++ src/pages/statistics.jsx | 45 ++++++- 4 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 backend/migrations/095_fs_watch_stats_over_time_include_total_time.js diff --git a/backend/migrations/095_fs_watch_stats_over_time_include_total_time.js b/backend/migrations/095_fs_watch_stats_over_time_include_total_time.js new file mode 100644 index 0000000..d8d29cf --- /dev/null +++ b/backend/migrations/095_fs_watch_stats_over_time_include_total_time.js @@ -0,0 +1,121 @@ +exports.up = async function (knex) { + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); + + CREATE OR REPLACE FUNCTION public.fs_watch_stats_over_time( + days integer) + RETURNS TABLE("Date" date, "Count" bigint, "TotalTime" bigint, "Library" text, "LibraryID" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 + +AS $BODY$ + BEGIN + RETURN QUERY + SELECT + dates."Date", + COALESCE(counts."Count", 0) AS "Count", + COALESCE(counts."TotalTime", 0) AS "TotalTime", + l."Name" as "Library", + l."Id" as "LibraryID" + FROM + (SELECT generate_series( + DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), + DATE_TRUNC('day', NOW()), + '1 day')::DATE AS "Date" + ) dates + CROSS JOIN jf_libraries l + + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + (SUM(a."PlaybackDuration") / 60)::bigint AS "TotalTime", + l."Name" as "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + + GROUP BY + l."Name", DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."Date" = dates."Date" AND counts."Library" = l."Name" + where l.archived=false + + ORDER BY + "Date", "Library"; + END; + +$BODY$; + +ALTER FUNCTION public.fs_watch_stats_over_time(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); + } catch (error) { + console.error(error); + } +}; + +exports.down = async function (knex) { + // try { + // await knex.schema.raw(` + // DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); + + // CREATE OR REPLACE FUNCTION fs_watch_stats_over_time( + // days integer + // ) + // RETURNS TABLE( + // "Date" date, + // "Count" bigint, + // "Library" text + // ) + // LANGUAGE 'plpgsql' + // COST 100 + // VOLATILE PARALLEL UNSAFE + // ROWS 1000 + + // AS $BODY$ + // BEGIN + // RETURN QUERY + // SELECT + // dates."Date", + // COALESCE(counts."Count", 0) AS "Count", + // l."Name" as "Library" + // FROM + // (SELECT generate_series( + // DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), + // DATE_TRUNC('day', NOW()), + // '1 day')::DATE AS "Date" + // ) dates + // CROSS JOIN jf_libraries l + // LEFT JOIN + // (SELECT + // DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + // COUNT(*) AS "Count", + // l."Name" as "Library" + // FROM + // jf_playback_activity a + // JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + // JOIN jf_libraries l ON i."ParentId" = l."Id" + // WHERE + // a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + // GROUP BY + // l."Name", DATE_TRUNC('day', a."ActivityDateInserted") + // ) counts + // ON counts."Date" = dates."Date" AND counts."Library" = l."Name" + // ORDER BY + // "Date", "Library"; + // END; + // $BODY$; + + // ALTER FUNCTION fs_watch_stats_over_time(integer) + // OWNER TO "${process.env.POSTGRES_ROLE}";`); + // } catch (error) { + // console.error(error); + // } +}; diff --git a/public/locales/en-UK/translation.json b/public/locales/en-UK/translation.json index 4b9357b..bd048d4 100644 --- a/public/locales/en-UK/translation.json +++ b/public/locales/en-UK/translation.json @@ -167,7 +167,9 @@ "STAT_PAGE": { "STATISTICS": "Statistics", "DAILY_PLAY_PER_LIBRARY": "Daily Play Count Per Library", - "PLAY_COUNT_BY": "Play Count By" + "PLAY_COUNT_BY": "Play Count By", + "COUNT_VIEW": "Total Count", + "TIME_VIEW": "Total Time" }, "SETTINGS_PAGE": { "SETTINGS": "Settings", diff --git a/src/pages/css/statCard.css b/src/pages/css/statCard.css index d4e2200..2bf73ed 100644 --- a/src/pages/css/statCard.css +++ b/src/pages/css/statCard.css @@ -143,3 +143,12 @@ input[type="number"] { .item-name :hover { color: var(--secondary-color) !important; } + +.pill-wrapper { + color: white; + display: flex; + border-radius: 8px; + font-size: 1.2em; + align-self: flex-end; + justify-content: center; +} \ No newline at end of file diff --git a/src/pages/statistics.jsx b/src/pages/statistics.jsx index ae1fb05..1e38913 100644 --- a/src/pages/statistics.jsx +++ b/src/pages/statistics.jsx @@ -1,3 +1,4 @@ +import { Tabs, Tab } from "react-bootstrap"; import { useState } from "react"; import "./css/stats.css"; @@ -20,6 +21,13 @@ function Statistics() { localStorage.setItem("PREF_STATISTICS_STAT_DAYS_INPUT", event.target.value); }; + const [activeTab, setActiveTab] = useState(localStorage.getItem(`PREF_STATISTICS_LAST_SELECTED_TAB`) ?? "tabCount"); + + function setTab(tabName) { + setActiveTab(tabName); + localStorage.setItem(`PREF_STATISTICS_LAST_SELECTED_TAB`, tabName); + } + const handleKeyDown = (event) => { if (event.key === "Enter") { if (input < 1) { @@ -43,6 +51,17 @@ function Statistics() {

+
+ + } /> + } /> + +
@@ -55,14 +74,26 @@ function Statistics() {
-
- -
- - -
-
+ {activeTab === "tabCount" && ( + <> + +
+ + +
+ + )} + + {activeTab === "tabTime" && ( + <> + +
+ + +
+ + )} ); } From c1800334a6d9eb7075cf620d0657551b84d01042 Mon Sep 17 00:00:00 2001 From: Sanidhya Singh Date: Mon, 5 May 2025 22:56:18 +0530 Subject: [PATCH 03/24] Daily watch time changes --- backend/routes/stats.js | 3 +- public/locales/en-UK/translation.json | 2 ++ src/pages/components/statistics/chart.jsx | 34 ++++++++++++------- .../statistics/daily-play-count.jsx | 12 +++++-- src/pages/statistics.jsx | 13 ++++--- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/backend/routes/stats.js b/backend/routes/stats.js index a727991..2cfe320 100644 --- a/backend/routes/stats.js +++ b/backend/routes/stats.js @@ -423,6 +423,7 @@ router.get("/getViewsOverTime", async (req, res) => { stats.forEach((item) => { const library = item.Library; const count = item.Count; + const watchTime = item.TotalTime; const date = new Date(item.Date).toLocaleDateString("en-US", { year: "numeric", month: "short", @@ -435,7 +436,7 @@ router.get("/getViewsOverTime", async (req, res) => { }; } - reorganizedData[date] = { ...reorganizedData[date], [library]: count }; + reorganizedData[date] = { ...reorganizedData[date], [library]: { count, watchTime } }; }); const finalData = { libraries: libraries, stats: Object.values(reorganizedData) }; res.send(finalData); diff --git a/public/locales/en-UK/translation.json b/public/locales/en-UK/translation.json index bd048d4..2d38e64 100644 --- a/public/locales/en-UK/translation.json +++ b/public/locales/en-UK/translation.json @@ -167,7 +167,9 @@ "STAT_PAGE": { "STATISTICS": "Statistics", "DAILY_PLAY_PER_LIBRARY": "Daily Play Count Per Library", + "DAILY_TIME_PER_LIBRARY": "Daily Watch Time Per Library", "PLAY_COUNT_BY": "Play Count By", + "PLAY_TIME_BY": "Play Time By", "COUNT_VIEW": "Total Count", "TIME_VIEW": "Total Time" }, diff --git a/src/pages/components/statistics/chart.jsx b/src/pages/components/statistics/chart.jsx index 7204f0b..1ba9762 100644 --- a/src/pages/components/statistics/chart.jsx +++ b/src/pages/components/statistics/chart.jsx @@ -1,6 +1,6 @@ import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, Tooltip, Legend } from "recharts"; -function Chart({ stats, libraries }) { +function Chart({ stats, libraries, viewName }) { const colors = [ "rgb(54, 162, 235)", // blue "rgb(255, 99, 132)", // pink @@ -24,13 +24,25 @@ function Chart({ stats, libraries }) { "rgb(147, 112, 219)", // medium purple ]; + const flattenedStats = stats.map(item => { + const flatItem = { Key: item.Key }; + for (const [libraryName, data] of Object.entries(item)) { + if (libraryName === "Key") continue; + flatItem[libraryName] = data[viewName] ?? 0; + } + return flatItem; + }); + const CustomTooltip = ({ payload, label, active }) => { if (active) { return (

{label}

{libraries.map((library, index) => ( -

{`${library.Name} : ${payload[index].value} Views`}

+ //

{`${library.Name} : ${payload[index].value} Views`}

+

+ {`${library.Name} : ${payload?.find(p => p.dataKey === library.Name).value} ${viewName === "count" ? "Views" : "Minutes"}`} +

))}
); @@ -41,16 +53,14 @@ function Chart({ stats, libraries }) { const getMaxValue = () => { let max = 0; - if (stats) { - stats.forEach((datum) => { - Object.keys(datum).forEach((key) => { - if (key !== "Key") { - max = Math.max(max, parseInt(datum[key])); - } - }); + flattenedStats.forEach(datum => { + libraries.forEach(library => { + const value = parseFloat(datum[library.Name]); + if (!isNaN(value)) { + max = Math.max(max, value); + } }); - } - + }); return max; }; @@ -58,7 +68,7 @@ function Chart({ stats, libraries }) { return ( - + {libraries.map((library, index) => ( diff --git a/src/pages/components/statistics/daily-play-count.jsx b/src/pages/components/statistics/daily-play-count.jsx index e7b9316..a79f358 100644 --- a/src/pages/components/statistics/daily-play-count.jsx +++ b/src/pages/components/statistics/daily-play-count.jsx @@ -10,6 +10,7 @@ function DailyPlayStats(props) { const [stats, setStats] = useState(); const [libraries, setLibraries] = useState(); const [days, setDays] = useState(20); + const [viewName, setViewName] = useState("viewCount"); const token = localStorage.getItem("token"); @@ -45,6 +46,9 @@ function DailyPlayStats(props) { setDays(props.days); fetchLibraries(); } + if (props.viewName !== viewName) { + setViewName(props.viewName); + } const intervalId = setInterval(fetchLibraries, 60000 * 5); return () => clearInterval(intervalId); @@ -54,10 +58,12 @@ function DailyPlayStats(props) { return <>; } + const titleKey = viewName === "count" ? "STAT_PAGE.DAILY_PLAY_PER_LIBRARY" : "STAT_PAGE.DAILY_TIME_PER_LIBRARY"; + if (stats.length === 0) { return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

@@ -65,10 +71,10 @@ function DailyPlayStats(props) { } return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

- +
); diff --git a/src/pages/statistics.jsx b/src/pages/statistics.jsx index 1e38913..a81cb50 100644 --- a/src/pages/statistics.jsx +++ b/src/pages/statistics.jsx @@ -56,7 +56,6 @@ function Statistics() { activeKey={activeTab} onSelect={setTab} variant="pills" - className="custom-tabs" > } /> } /> @@ -77,20 +76,20 @@ function Statistics() { {activeTab === "tabCount" && ( <> - +
- - + +
)} {activeTab === "tabTime" && ( <> - +
- - + +
)} From 579a7a3f8b476949ebb2b0ca7f0f50fbde27b64b Mon Sep 17 00:00:00 2001 From: Sanidhya Singh Date: Tue, 6 May 2025 00:24:16 +0530 Subject: [PATCH 04/24] Changes for the daily & weekly playback duration charts --- ...watch_stats_over_time_include_duration.js} | 6 +- ...s_popular_days_of_week_include_duration.js | 141 ++++++++++++++++++ ...ts_popular_hour_of_day_include_duration.js | 115 ++++++++++++++ backend/routes/stats.js | 10 +- public/locales/en-UK/translation.json | 8 +- .../statistics/daily-play-count.jsx | 8 +- .../statistics/play-stats-by-day.jsx | 14 +- .../statistics/play-stats-by-hour.jsx | 13 +- src/pages/css/statCard.css | 9 -- src/pages/css/stats.css | 8 + src/pages/statistics.jsx | 30 ++-- 11 files changed, 319 insertions(+), 43 deletions(-) rename backend/migrations/{095_fs_watch_stats_over_time_include_total_time.js => 095_fs_watch_stats_over_time_include_duration.js} (94%) create mode 100644 backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js create mode 100644 backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js diff --git a/backend/migrations/095_fs_watch_stats_over_time_include_total_time.js b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js similarity index 94% rename from backend/migrations/095_fs_watch_stats_over_time_include_total_time.js rename to backend/migrations/095_fs_watch_stats_over_time_include_duration.js index d8d29cf..e88fa04 100644 --- a/backend/migrations/095_fs_watch_stats_over_time_include_total_time.js +++ b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js @@ -5,7 +5,7 @@ exports.up = async function (knex) { CREATE OR REPLACE FUNCTION public.fs_watch_stats_over_time( days integer) - RETURNS TABLE("Date" date, "Count" bigint, "TotalTime" bigint, "Library" text, "LibraryID" text) + RETURNS TABLE("Date" date, "Count" bigint, "Duration" bigint, "Library" text, "LibraryID" text) LANGUAGE 'plpgsql' COST 100 VOLATILE PARALLEL UNSAFE @@ -17,7 +17,7 @@ AS $BODY$ SELECT dates."Date", COALESCE(counts."Count", 0) AS "Count", - COALESCE(counts."TotalTime", 0) AS "TotalTime", + COALESCE(counts."Duration", 0) AS "Duration", l."Name" as "Library", l."Id" as "LibraryID" FROM @@ -32,7 +32,7 @@ AS $BODY$ (SELECT DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", COUNT(*) AS "Count", - (SUM(a."PlaybackDuration") / 60)::bigint AS "TotalTime", + (SUM(a."PlaybackDuration") / 60)::bigint AS "Duration", l."Name" as "Library" FROM jf_playback_activity a diff --git a/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js new file mode 100644 index 0000000..630f72b --- /dev/null +++ b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js @@ -0,0 +1,141 @@ +exports.up = async function (knex) { + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); + +CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( + days integer) + RETURNS TABLE("Day" text, "Count" bigint, "Duration" bigint, "Library" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 + +AS $BODY$ + BEGIN + RETURN QUERY + WITH library_days AS ( + SELECT + l."Name" AS "Library", + d.day_of_week, + d.day_name + FROM + jf_libraries l, + (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL + SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL + SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL + SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL + SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL + SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL + SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" + ) d + where l.archived=false + ) + SELECT + library_days.day_name AS "Day", + COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", + COALESCE(SUM(counts."Duration"), 0)::bigint AS "Duration", + library_days."Library" AS "Library" + FROM + library_days + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + (SUM(a."PlaybackDuration") / 60)::bigint AS "Duration", + EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", + l."Name" AS "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" and l.archived=false + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + GROUP BY + l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" + GROUP BY + library_days.day_name, library_days.day_of_week, library_days."Library" + ORDER BY + library_days.day_of_week, library_days."Library"; + END; + +$BODY$; + +ALTER FUNCTION public.fs_watch_stats_popular_days_of_week(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); + } catch (error) { + console.error(error); + } +}; + +exports.down = async function (knex) { +// try { +// await knex.schema.raw(` +// DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); + +// CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( +// days integer) +// RETURNS TABLE("Day" text, "Count" bigint, "Library" text) +// LANGUAGE 'plpgsql' +// COST 100 +// VOLATILE PARALLEL UNSAFE +// ROWS 1000 + +// AS $BODY$ +// BEGIN +// RETURN QUERY +// WITH library_days AS ( +// SELECT +// l."Name" AS "Library", +// d.day_of_week, +// d.day_name +// FROM +// jf_libraries l, +// (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL +// SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL +// SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL +// SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL +// SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL +// SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL +// SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" +// ) d +// ) +// SELECT +// library_days.day_name AS "Day", +// COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", +// library_days."Library" AS "Library" +// FROM +// library_days +// LEFT JOIN +// (SELECT +// DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", +// COUNT(*) AS "Count", +// EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", +// l."Name" AS "Library" +// FROM +// jf_playback_activity a +// JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" +// JOIN jf_libraries l ON i."ParentId" = l."Id" +// WHERE +// a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() +// GROUP BY +// l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") +// ) counts +// ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" +// GROUP BY +// library_days.day_name, library_days.day_of_week, library_days."Library" +// ORDER BY +// library_days.day_of_week, library_days."Library"; +// END; + +// $BODY$; + +// ALTER FUNCTION fs_watch_stats_popular_days_of_week(integer) +// OWNER TO "${process.env.POSTGRES_ROLE}";`); +// } catch (error) { +// console.error(error); +// } +}; diff --git a/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js new file mode 100644 index 0000000..4909788 --- /dev/null +++ b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js @@ -0,0 +1,115 @@ +exports.up = async function (knex) { + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_hour_of_day(integer); + +CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_hour_of_day( + days integer) + RETURNS TABLE("Hour" integer, "Count" integer, "Duration" integer, "Library" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 + +AS $BODY$ + BEGIN + RETURN QUERY + SELECT + h."Hour", + COUNT(a."Id")::integer AS "Count", + COALESCE(SUM(a."PlaybackDuration") / 60, 0)::integer AS "Duration", + l."Name" AS "Library" + FROM + ( + SELECT + generate_series(0, 23) AS "Hour" + ) h + CROSS JOIN jf_libraries l + LEFT JOIN jf_library_items i ON i."ParentId" = l."Id" + LEFT JOIN ( + SELECT + "NowPlayingItemId", + DATE_PART('hour', "ActivityDateInserted") AS "Hour", + "Id", + "PlaybackDuration" + FROM + jf_playback_activity + WHERE + "ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' AS INTERVAL) AND NOW() + ) a ON a."NowPlayingItemId" = i."Id" AND a."Hour"::integer = h."Hour" + WHERE + l.archived=false + and l."Id" IN (SELECT "Id" FROM jf_libraries) + GROUP BY + h."Hour", + l."Name" + ORDER BY + l."Name", + h."Hour"; + END; + +$BODY$; + +ALTER FUNCTION public.fs_watch_stats_popular_hour_of_day(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); + } catch (error) { + console.error(error); + } +}; + +exports.down = async function (knex) { + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_hour_of_day(integer); + +CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_hour_of_day( + days integer) + RETURNS TABLE("Hour" integer, "Count" integer, "Library" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 + +AS $BODY$ + BEGIN + RETURN QUERY + SELECT + h."Hour", + COUNT(a."Id")::integer AS "Count", + l."Name" AS "Library" + FROM + ( + SELECT + generate_series(0, 23) AS "Hour" + ) h + CROSS JOIN jf_libraries l + LEFT JOIN jf_library_items i ON i."ParentId" = l."Id" + LEFT JOIN ( + SELECT + "NowPlayingItemId", + DATE_PART('hour', "ActivityDateInserted") AS "Hour", + "Id" + FROM + jf_playback_activity + WHERE + "ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' AS INTERVAL) AND NOW() + ) a ON a."NowPlayingItemId" = i."Id" AND a."Hour"::integer = h."Hour" + WHERE + l."Id" IN (SELECT "Id" FROM jf_libraries) + GROUP BY + h."Hour", + l."Name" + ORDER BY + l."Name", + h."Hour"; + END; + +$BODY$; + + ALTER FUNCTION fs_watch_stats_popular_hour_of_day(integer) + OWNER TO "${process.env.POSTGRES_ROLE}";`); + } catch (error) { + console.error(error); + } +}; diff --git a/backend/routes/stats.js b/backend/routes/stats.js index 2cfe320..a3f105a 100644 --- a/backend/routes/stats.js +++ b/backend/routes/stats.js @@ -423,7 +423,7 @@ router.get("/getViewsOverTime", async (req, res) => { stats.forEach((item) => { const library = item.Library; const count = item.Count; - const watchTime = item.TotalTime; + const duration = item.Duration; const date = new Date(item.Date).toLocaleDateString("en-US", { year: "numeric", month: "short", @@ -436,7 +436,7 @@ router.get("/getViewsOverTime", async (req, res) => { }; } - reorganizedData[date] = { ...reorganizedData[date], [library]: { count, watchTime } }; + reorganizedData[date] = { ...reorganizedData[date], [library]: { count, duration } }; }); const finalData = { libraries: libraries, stats: Object.values(reorganizedData) }; res.send(finalData); @@ -463,6 +463,7 @@ router.get("/getViewsByDays", async (req, res) => { stats.forEach((item) => { const library = item.Library; const count = item.Count; + const duration = item.Duration; const day = item.Day; if (!reorganizedData[day]) { @@ -471,7 +472,7 @@ router.get("/getViewsByDays", async (req, res) => { }; } - reorganizedData[day] = { ...reorganizedData[day], [library]: count }; + reorganizedData[day] = { ...reorganizedData[day], [library]: { count, duration } }; }); const finalData = { libraries: libraries, stats: Object.values(reorganizedData) }; res.send(finalData); @@ -498,6 +499,7 @@ router.get("/getViewsByHour", async (req, res) => { stats.forEach((item) => { const library = item.Library; const count = item.Count; + const duration = item.Duration; const hour = item.Hour; if (!reorganizedData[hour]) { @@ -506,7 +508,7 @@ router.get("/getViewsByHour", async (req, res) => { }; } - reorganizedData[hour] = { ...reorganizedData[hour], [library]: count }; + reorganizedData[hour] = { ...reorganizedData[hour], [library]: { count, duration } }; }); const finalData = { libraries: libraries, stats: Object.values(reorganizedData) }; res.send(finalData); diff --git a/public/locales/en-UK/translation.json b/public/locales/en-UK/translation.json index 2d38e64..67d4b18 100644 --- a/public/locales/en-UK/translation.json +++ b/public/locales/en-UK/translation.json @@ -167,11 +167,11 @@ "STAT_PAGE": { "STATISTICS": "Statistics", "DAILY_PLAY_PER_LIBRARY": "Daily Play Count Per Library", - "DAILY_TIME_PER_LIBRARY": "Daily Watch Time Per Library", + "DAILY_DURATION_PER_LIBRARY": "Daily Play Duration Per Library", "PLAY_COUNT_BY": "Play Count By", - "PLAY_TIME_BY": "Play Time By", - "COUNT_VIEW": "Total Count", - "TIME_VIEW": "Total Time" + "PLAY_DURATION_BY": "Play Duration By", + "COUNT_VIEW": "Count", + "DURATION_VIEW": "Duration" }, "SETTINGS_PAGE": { "SETTINGS": "Settings", diff --git a/src/pages/components/statistics/daily-play-count.jsx b/src/pages/components/statistics/daily-play-count.jsx index a79f358..76411d6 100644 --- a/src/pages/components/statistics/daily-play-count.jsx +++ b/src/pages/components/statistics/daily-play-count.jsx @@ -10,7 +10,7 @@ function DailyPlayStats(props) { const [stats, setStats] = useState(); const [libraries, setLibraries] = useState(); const [days, setDays] = useState(20); - const [viewName, setViewName] = useState("viewCount"); + const [viewName, setViewName] = useState("count"); const token = localStorage.getItem("token"); @@ -52,14 +52,14 @@ function DailyPlayStats(props) { const intervalId = setInterval(fetchLibraries, 60000 * 5); return () => clearInterval(intervalId); - }, [stats,libraries, days, props.days, token]); + }, [stats,libraries, days, props.days, props.viewName, token]); if (!stats) { return <>; } - const titleKey = viewName === "count" ? "STAT_PAGE.DAILY_PLAY_PER_LIBRARY" : "STAT_PAGE.DAILY_TIME_PER_LIBRARY"; - + const titleKey = viewName === "count" ? "STAT_PAGE.DAILY_PLAY_PER_LIBRARY" : "STAT_PAGE.DAILY_DURATION_PER_LIBRARY"; + if (stats.length === 0) { return (
diff --git a/src/pages/components/statistics/play-stats-by-day.jsx b/src/pages/components/statistics/play-stats-by-day.jsx index c7f5c09..7bc25cb 100644 --- a/src/pages/components/statistics/play-stats-by-day.jsx +++ b/src/pages/components/statistics/play-stats-by-day.jsx @@ -9,6 +9,7 @@ function PlayStatsByDay(props) { const [stats, setStats] = useState(); const [libraries, setLibraries] = useState(); const [days, setDays] = useState(20); + const [viewName, setViewName] = useState("count"); const token = localStorage.getItem("token"); useEffect(() => { @@ -41,19 +42,24 @@ function PlayStatsByDay(props) { setDays(props.days); fetchLibraries(); } + if (props.viewName !== viewName) { + setViewName(props.viewName); + } const intervalId = setInterval(fetchLibraries, 60000 * 5); return () => clearInterval(intervalId); - }, [stats, libraries, days, props.days, token]); + }, [stats, libraries, days, props.days, props.viewName, token]); if (!stats) { return <>; } + const titleKey = viewName === "count" ? "STAT_PAGE.PLAY_COUNT_BY" : "STAT_PAGE.PLAY_DURATION_BY"; + if (stats.length === 0) { return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

@@ -62,9 +68,9 @@ function PlayStatsByDay(props) { return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

- +
); diff --git a/src/pages/components/statistics/play-stats-by-hour.jsx b/src/pages/components/statistics/play-stats-by-hour.jsx index f1895d3..6198768 100644 --- a/src/pages/components/statistics/play-stats-by-hour.jsx +++ b/src/pages/components/statistics/play-stats-by-hour.jsx @@ -8,6 +8,7 @@ function PlayStatsByHour(props) { const [stats, setStats] = useState(); const [libraries, setLibraries] = useState(); const [days, setDays] = useState(20); + const [viewName, setViewName] = useState("count"); const token = localStorage.getItem("token"); useEffect(() => { @@ -40,19 +41,23 @@ function PlayStatsByHour(props) { setDays(props.days); fetchLibraries(); } + if (props.viewName !== viewName) { + setViewName(props.viewName); + } const intervalId = setInterval(fetchLibraries, 60000 * 5); return () => clearInterval(intervalId); - }, [stats, libraries, days, props.days, token]); + }, [stats, libraries, days, props.days, props.viewName, token]); if (!stats) { return <>; } + const titleKey = viewName === "count" ? "STAT_PAGE.PLAY_COUNT_BY" : "STAT_PAGE.PLAY_DURATION_BY"; if (stats.length === 0) { return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

@@ -62,9 +67,9 @@ function PlayStatsByHour(props) { return (
-

- {days} 1 ? 'S':''}`}/>

+

- {days} 1 ? 'S':''}`}/>

- +
); diff --git a/src/pages/css/statCard.css b/src/pages/css/statCard.css index 2bf73ed..d4e2200 100644 --- a/src/pages/css/statCard.css +++ b/src/pages/css/statCard.css @@ -143,12 +143,3 @@ input[type="number"] { .item-name :hover { color: var(--secondary-color) !important; } - -.pill-wrapper { - color: white; - display: flex; - border-radius: 8px; - font-size: 1.2em; - align-self: flex-end; - justify-content: center; -} \ No newline at end of file diff --git a/src/pages/css/stats.css b/src/pages/css/stats.css index ca7761b..f300da5 100644 --- a/src/pages/css/stats.css +++ b/src/pages/css/stats.css @@ -47,6 +47,14 @@ margin-bottom: 10px !important; } +.stats-tab-nav { + background-color: var(--secondary-background-color); + display: flex; + border-radius: 8px; + align-self: flex-end; + justify-content: center; +} + .chart-canvas { width: 100%; height: 400px; diff --git a/src/pages/statistics.jsx b/src/pages/statistics.jsx index a81cb50..b04ff7e 100644 --- a/src/pages/statistics.jsx +++ b/src/pages/statistics.jsx @@ -51,14 +51,22 @@ function Statistics() {

-
+
- } /> - } /> + } + /> + } + />
@@ -75,23 +83,23 @@ function Statistics() {
{activeTab === "tabCount" && ( - <> +
- +
)} - {activeTab === "tabTime" && ( - <> - + {activeTab === "tabDuration" && ( +
+
- - + +
- +
)}
); From 07fbfdca7193ea8f1b46f3312ae69d139a3ffdc5 Mon Sep 17 00:00:00 2001 From: Sanidhya Singh Date: Tue, 6 May 2025 14:38:10 +0530 Subject: [PATCH 05/24] Updating exports.down for migrations and css change --- ..._watch_stats_over_time_include_duration.js | 106 +++++++-------- ...s_popular_days_of_week_include_duration.js | 128 +++++++++--------- ...ts_popular_hour_of_day_include_duration.js | 10 +- src/pages/css/stats.css | 9 +- src/pages/statistics.jsx | 2 + 5 files changed, 134 insertions(+), 121 deletions(-) diff --git a/backend/migrations/095_fs_watch_stats_over_time_include_duration.js b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js index e88fa04..78e63b5 100644 --- a/backend/migrations/095_fs_watch_stats_over_time_include_duration.js +++ b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js @@ -62,60 +62,60 @@ ALTER FUNCTION public.fs_watch_stats_over_time(integer) }; exports.down = async function (knex) { - // try { - // await knex.schema.raw(` - // DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); - // CREATE OR REPLACE FUNCTION fs_watch_stats_over_time( - // days integer - // ) - // RETURNS TABLE( - // "Date" date, - // "Count" bigint, - // "Library" text - // ) - // LANGUAGE 'plpgsql' - // COST 100 - // VOLATILE PARALLEL UNSAFE - // ROWS 1000 + CREATE OR REPLACE FUNCTION fs_watch_stats_over_time( + days integer + ) + RETURNS TABLE( + "Date" date, + "Count" bigint, + "Library" text + ) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 - // AS $BODY$ - // BEGIN - // RETURN QUERY - // SELECT - // dates."Date", - // COALESCE(counts."Count", 0) AS "Count", - // l."Name" as "Library" - // FROM - // (SELECT generate_series( - // DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), - // DATE_TRUNC('day', NOW()), - // '1 day')::DATE AS "Date" - // ) dates - // CROSS JOIN jf_libraries l - // LEFT JOIN - // (SELECT - // DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", - // COUNT(*) AS "Count", - // l."Name" as "Library" - // FROM - // jf_playback_activity a - // JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" - // JOIN jf_libraries l ON i."ParentId" = l."Id" - // WHERE - // a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() - // GROUP BY - // l."Name", DATE_TRUNC('day', a."ActivityDateInserted") - // ) counts - // ON counts."Date" = dates."Date" AND counts."Library" = l."Name" - // ORDER BY - // "Date", "Library"; - // END; - // $BODY$; + AS $BODY$ + BEGIN + RETURN QUERY + SELECT + dates."Date", + COALESCE(counts."Count", 0) AS "Count", + l."Name" as "Library" + FROM + (SELECT generate_series( + DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), + DATE_TRUNC('day', NOW()), + '1 day')::DATE AS "Date" + ) dates + CROSS JOIN jf_libraries l + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + l."Name" as "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + GROUP BY + l."Name", DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."Date" = dates."Date" AND counts."Library" = l."Name" + ORDER BY + "Date", "Library"; + END; + $BODY$; - // ALTER FUNCTION fs_watch_stats_over_time(integer) - // OWNER TO "${process.env.POSTGRES_ROLE}";`); - // } catch (error) { - // console.error(error); - // } + ALTER FUNCTION fs_watch_stats_over_time(integer) + OWNER TO "${process.env.POSTGRES_ROLE}";`); + } catch (error) { + console.error(error); + } }; diff --git a/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js index 630f72b..c0849e0 100644 --- a/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js +++ b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js @@ -72,70 +72,72 @@ ALTER FUNCTION public.fs_watch_stats_popular_days_of_week(integer) }; exports.down = async function (knex) { -// try { -// await knex.schema.raw(` -// DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); -// CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( -// days integer) -// RETURNS TABLE("Day" text, "Count" bigint, "Library" text) -// LANGUAGE 'plpgsql' -// COST 100 -// VOLATILE PARALLEL UNSAFE -// ROWS 1000 +CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( + days integer) + RETURNS TABLE("Day" text, "Count" bigint, "Library" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 -// AS $BODY$ -// BEGIN -// RETURN QUERY -// WITH library_days AS ( -// SELECT -// l."Name" AS "Library", -// d.day_of_week, -// d.day_name -// FROM -// jf_libraries l, -// (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL -// SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL -// SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL -// SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL -// SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL -// SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL -// SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" -// ) d -// ) -// SELECT -// library_days.day_name AS "Day", -// COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", -// library_days."Library" AS "Library" -// FROM -// library_days -// LEFT JOIN -// (SELECT -// DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", -// COUNT(*) AS "Count", -// EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", -// l."Name" AS "Library" -// FROM -// jf_playback_activity a -// JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" -// JOIN jf_libraries l ON i."ParentId" = l."Id" -// WHERE -// a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() -// GROUP BY -// l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") -// ) counts -// ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" -// GROUP BY -// library_days.day_name, library_days.day_of_week, library_days."Library" -// ORDER BY -// library_days.day_of_week, library_days."Library"; -// END; +AS $BODY$ + BEGIN + RETURN QUERY + WITH library_days AS ( + SELECT + l."Name" AS "Library", + d.day_of_week, + d.day_name + FROM + jf_libraries l, + (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL + SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL + SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL + SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL + SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL + SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL + SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" + ) d + where l.archived=false + ) + SELECT + library_days.day_name AS "Day", + COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", + library_days."Library" AS "Library" + FROM + library_days + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", + l."Name" AS "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" and l.archived=false + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + GROUP BY + l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" + GROUP BY + library_days.day_name, library_days.day_of_week, library_days."Library" + ORDER BY + library_days.day_of_week, library_days."Library"; + END; -// $BODY$; - -// ALTER FUNCTION fs_watch_stats_popular_days_of_week(integer) -// OWNER TO "${process.env.POSTGRES_ROLE}";`); -// } catch (error) { -// console.error(error); -// } +$BODY$; + +ALTER FUNCTION public.fs_watch_stats_popular_days_of_week(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); + } catch (error) { + console.error(error); + } }; diff --git a/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js index 4909788..57f943f 100644 --- a/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js +++ b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js @@ -96,7 +96,8 @@ AS $BODY$ "ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' AS INTERVAL) AND NOW() ) a ON a."NowPlayingItemId" = i."Id" AND a."Hour"::integer = h."Hour" WHERE - l."Id" IN (SELECT "Id" FROM jf_libraries) + l.archived=false + and l."Id" IN (SELECT "Id" FROM jf_libraries) GROUP BY h."Hour", l."Name" @@ -106,9 +107,10 @@ AS $BODY$ END; $BODY$; - - ALTER FUNCTION fs_watch_stats_popular_hour_of_day(integer) - OWNER TO "${process.env.POSTGRES_ROLE}";`); + +ALTER FUNCTION public.fs_watch_stats_popular_hour_of_day(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); } catch (error) { console.error(error); } diff --git a/src/pages/css/stats.css b/src/pages/css/stats.css index f300da5..3e0f186 100644 --- a/src/pages/css/stats.css +++ b/src/pages/css/stats.css @@ -49,12 +49,19 @@ .stats-tab-nav { background-color: var(--secondary-background-color); - display: flex; border-radius: 8px; align-self: flex-end; +} + +.nav-item { + display: flex; justify-content: center; } +/* .tab-content { + display: none; +} */ + .chart-canvas { width: 100%; height: 400px; diff --git a/src/pages/statistics.jsx b/src/pages/statistics.jsx index b04ff7e..283db21 100644 --- a/src/pages/statistics.jsx +++ b/src/pages/statistics.jsx @@ -53,6 +53,7 @@ function Statistics() {
} /> + Date: Tue, 6 May 2025 14:39:09 +0530 Subject: [PATCH 06/24] Removing debug changes --- src/pages/css/stats.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pages/css/stats.css b/src/pages/css/stats.css index 3e0f186..de9ff7a 100644 --- a/src/pages/css/stats.css +++ b/src/pages/css/stats.css @@ -58,10 +58,6 @@ justify-content: center; } -/* .tab-content { - display: none; -} */ - .chart-canvas { width: 100%; height: 400px; From e0aa9dee77a33d3a057312914494da55842f597b Mon Sep 17 00:00:00 2001 From: Nath1416 Date: Wed, 21 May 2025 22:31:28 -0400 Subject: [PATCH 07/24] Added github container registry to pipeline --- .github/workflows/docker-image.yml | 11 ++++++++++- .github/workflows/docker-latest.yml | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6312cb2..da225f3 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -39,12 +39,21 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build Docker image uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} + tags: | + ${{ steps.meta.outputs.tags }} + ghcr.io/${{ steps.meta.outputs.tags }} platforms: linux/amd64,linux/arm64,linux/arm/v7 cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-latest.yml b/.github/workflows/docker-latest.yml index 0d63960..23dd6a7 100644 --- a/.github/workflows/docker-latest.yml +++ b/.github/workflows/docker-latest.yml @@ -44,6 +44,13 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build Docker image uses: docker/build-push-action@v5 @@ -53,4 +60,6 @@ jobs: tags: | cyfershepard/jellystat:latest cyfershepard/jellystat:${{ env.VERSION }} + ghcr.io/cyfershepard/jellystat:latest + ghcr.io/cyfershepard/jellystat:${{ env.VERSION }} platforms: linux/amd64,linux/arm64,linux/arm/v7 From 41e9a6e0cf0e6f021755770c2fa08d85d69d4ad9 Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Sat, 24 May 2025 22:14:06 +0200 Subject: [PATCH 08/24] Fix failed backup bug due to not awaiting log insert #393 --- backend/classes/backup.js | 12 ++++++------ backend/tasks/BackupTask.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/classes/backup.js b/backend/classes/backup.js index 5282ca0..d2c21f0 100644 --- a/backend/classes/backup.js +++ b/backend/classes/backup.js @@ -34,7 +34,7 @@ async function backup(refLog) { if (config.error) { refLog.logData.push({ color: "red", Message: "Backup Failed: Failed to get config" }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); return; } @@ -61,7 +61,7 @@ async function backup(refLog) { console.error("No write permissions for the folder:", backuppath); refLog.logData.push({ color: "red", Message: "Backup Failed: No write permissions for the folder: " + backuppath }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); await pool.end(); return; } @@ -73,7 +73,7 @@ async function backup(refLog) { if (filteredTables.length === 0) { refLog.logData.push({ color: "red", Message: "Backup Failed: No tables to backup" }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); await pool.end(); return; } @@ -82,9 +82,9 @@ async function backup(refLog) { const directoryPath = path.join(__dirname, "..", backupfolder, `backup_${now.format("yyyy-MM-DD HH-mm-ss")}.json`); refLog.logData.push({ color: "yellow", Message: "Begin Backup " + directoryPath }); const stream = fs.createWriteStream(directoryPath, { flags: "a" }); - stream.on("error", (error) => { + stream.on("error", async (error) => { refLog.logData.push({ color: "red", Message: "Backup Failed: " + error }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); return; }); const backup_data = []; @@ -152,7 +152,7 @@ async function backup(refLog) { } catch (error) { console.log(error); refLog.logData.push({ color: "red", Message: "Backup Failed: " + error }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); } await pool.end(); diff --git a/backend/tasks/BackupTask.js b/backend/tasks/BackupTask.js index 7f55e97..50d780d 100644 --- a/backend/tasks/BackupTask.js +++ b/backend/tasks/BackupTask.js @@ -27,10 +27,10 @@ async function runBackupTask(triggerType = triggertype.Automatic) { console.log("Running Scheduled Backup"); - Logging.insertLog(uuid, triggerType, taskName.backup); + await Logging.insertLog(uuid, triggerType, taskName.backup); await backup(refLog); - Logging.updateLog(uuid, refLog.logData, taskstate.SUCCESS); + await Logging.updateLog(uuid, refLog.logData, taskstate.SUCCESS); sendUpdate("BackupTask", { type: "Success", message: `${triggerType} Backup Completed` }); console.log("Scheduled Backup Complete"); parentPort.postMessage({ status: "complete" }); From db8d0a3ca0c26de96081a85a1cf1a9fc2158a393 Mon Sep 17 00:00:00 2001 From: chrisvgt <30186211+chrisvgt@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:18:14 +0200 Subject: [PATCH 09/24] feat: add language german --- public/locales/de-DE/translation.json | 319 ++++++++++++++++++++++++++ src/lib/languages.jsx | 4 + 2 files changed, 323 insertions(+) create mode 100644 public/locales/de-DE/translation.json diff --git a/public/locales/de-DE/translation.json b/public/locales/de-DE/translation.json new file mode 100644 index 0000000..4094711 --- /dev/null +++ b/public/locales/de-DE/translation.json @@ -0,0 +1,319 @@ +{ + "JELLYSTAT": "Jellystat", + "MENU_TABS": { + "HOME": "Startseite", + "LIBRARIES": "Bibliotheken", + "USERS": "Benutzer", + "ACTIVITY": "Aktivitäten", + "STATISTICS": "Statistiken", + "SETTINGS": "Einstellungen", + "ABOUT": "Über", + "LOGOUT": "Abmelden", + "TIMELINE": "Zeitleiste" + }, + "HOME_PAGE": { + "SESSIONS": "Sitzungen", + "RECENTLY_ADDED": "Zuletzt hinzugefügt", + "WATCH_STATISTIC": "Wiedergabestatistiken", + "LIBRARY_OVERVIEW": "Bibliothek-Übersicht" + }, + "SESSIONS": { + "NO_SESSIONS": "Keine aktiven Sitzungen gefunden", + "DIRECT_PLAY": "Direkte Wiedergabe", + "TRANSCODE": "Transkodieren" + }, + "STAT_CARDS": { + "MOST_VIEWED_MOVIES": "MEISTGESEHENE FILME", + "MOST_POPULAR_MOVIES": "BELIEBTESTE FILME", + "MOST_VIEWED_SERIES": "MEISTGESEHENE SERIEN", + "MOST_POPULAR_SERIES": "BELIEBTESTE SERIEN", + "MOST_LISTENED_MUSIC": "MEISTGEHÖRTE MUSIK", + "MOST_POPULAR_MUSIC": "BELIEBTESTE MUSIK", + "MOST_VIEWED_LIBRARIES": "MEISTGESEHENE BIBLIOTHEKEN", + "MOST_USED_CLIENTS": "MEISTGENUTZTE CLIENTS", + "MOST_ACTIVE_USERS": "AKTIVSTE BENUTZER", + "CONCURRENT_STREAMS": "GLEICHZEITIGE STREAMS" + }, + "LIBRARY_OVERVIEW": { + "MOVIE_LIBRARIES": "FILM-BIBLIOTHEKEN", + "SHOW_LIBRARIES": "SERIEN-BIBLIOTHEKEN", + "MUSIC_LIBRARIES": "MUSIK-BIBLIOTHEKEN", + "MIXED_LIBRARIES": "GEMISCHTE BIBLIOTHEKEN" + }, + "LIBRARY_CARD": { + "LIBRARY": "Bibliothek", + "TOTAL_TIME": "Gesamtlaufzeit", + "TOTAL_FILES": "Gesamtzahl der Dateien", + "LIBRARY_SIZE": "Größe der Bibliothek", + "TOTAL_PLAYBACK": "Gesamtwiedergabezeit", + "LAST_PLAYED": "Zuletzt gespielt", + "LAST_ACTIVITY": "Letzte Aktivität", + "TRACKED": "Daten-Tracking" + }, + "GLOBAL_STATS": { + "LAST_24_HRS": "Letzten 24 Stunden", + "LAST_7_DAYS": "Letzten 7 Tage", + "LAST_30_DAYS": "Letzten 30 Tage", + "LAST_180_DAYS": "Letzten 180 Tage", + "LAST_365_DAYS": "Letzten 365 Tage", + "ALL_TIME": "Gesamtzeit", + "ITEM_STATS": "Statistik" + }, + "ITEM_INFO": { + "FILE_PATH": "Dateipfad", + "FILE_SIZE": "Dateigröße", + "RUNTIME": "Laufzeit", + "AVERAGE_RUNTIME": "Durchschnittliche Laufzeit", + "OPEN_IN_JELLYFIN": "In Jellyfin öffnen", + "ARCHIVED_DATA_OPTIONS": "Optionen für archivierte Daten", + "PURGE": "Löschen", + "CONFIRM_ACTION": "Aktion bestätigen", + "CONFIRM_ACTION_MESSAGE": "Sind Sie sicher, dass Sie dieses Element löschen möchten", + "CONFIRM_ACTION_MESSAGE_2": "und zugehörige Wiedergabeaktivitäten" + }, + "LIBRARY_INFO": { + "LIBRARY_STATS": "Bibliothek-Statistiken", + "LIBRARY_ACTIVITY": "Bibliothek-Aktivität" + }, + "TAB_CONTROLS": { + "OVERVIEW": "Übersicht", + "ACTIVITY": "Aktivität", + "OPTIONS": "Optionen", + "TIMELINE": "Zeitleiste" + }, + "ITEM_ACTIVITY": "Elementaktivität", + "ACTIVITY_TABLE": { + "MODAL": { + "HEADER": "Stream-Informationen" + }, + "IP_ADDRESS": "IP-Adresse", + "CLIENT": "Client", + "DEVICE": "Gerät", + "PLAYBACK_DURATION": "Wiedergabedauer", + "TOTAL_PLAYBACK": "Gesamtwiedergabezeit", + "EXPAND": "Erweitern", + "COLLAPSE": "Reduzieren", + "SORT_BY": "Sortieren nach", + "ASCENDING": "Aufsteigend", + "DESCENDING": "Absteigend", + "CLEAR_SORT": "Sortierung aufheben", + "CLEAR_FILTER": "Filter löschen", + "FILTER_BY": "Filtern nach", + "COLUMN_ACTIONS": "Spaltenaktionen", + "TOGGLE_SELECT_ROW": "Zeile auswählen/abwählen", + "TOGGLE_SELECT_ALL": "Alle auswählen/abwählen", + "MIN": "Min", + "MAX": "Max" + }, + "TABLE_NAV_BUTTONS": { + "FIRST": "Erste", + "LAST": "Letzte", + "NEXT": "Nächste", + "PREVIOUS": "Vorherige" + }, + "PURGE_OPTIONS": { + "PURGE_CACHE": "Zwischengespeichertes Element löschen", + "PURGE_CACHE_WITH_ACTIVITY": "Zwischengespeichertes Element und Wiedergabeaktivität löschen", + "PURGE_LIBRARY_CACHE": "Zwischengespeicherte Bibliothek und Elemente löschen", + "PURGE_LIBRARY_CACHE_WITH_ACTIVITY": "Zwischengespeicherte Bibliothek, Elemente und Aktivität löschen", + "PURGE_LIBRARY_ITEMS_CACHE": "Nur zwischengespeicherte Bibliothekelemente löschen", + "PURGE_LIBRARY_ITEMS_CACHE_WITH_ACTIVITY": "Nur zwischengespeicherte Bibliothekelemente und Aktivität löschen", + "PURGE_ACTIVITY": "Möchten Sie die ausgewählte Wiedergabeaktivität wirklich löschen?" + }, + "ERROR_MESSAGES": { + "FETCH_THIS_ITEM": "Dieses Element von Jellyfin abrufen", + "NO_ACTIVITY": "Keine Aktivität gefunden", + "NEVER": "Nie", + "N/A": "N/A", + "NO_STATS": "Keine Statistiken zum Anzeigen", + "NO_BACKUPS": "Keine Sicherungen gefunden", + "NO_LOGS": "Keine Protokolle gefunden", + "NO_API_KEYS": "Keine Schlüssel gefunden", + "NETWORK_ERROR": "Verbindung zum Jellyfin-Server nicht möglich", + "INVALID_LOGIN": "Ungültiger Benutzername oder Passwort", + "INVALID_URL": "Fehler {STATUS}: Die angeforderte URL wurde nicht gefunden.", + "UNAUTHORIZED": "Fehler {STATUS}: Nicht autorisiert", + "PASSWORD_LENGTH": "Passwort muss mindestens 6 Zeichen lang sein", + "USERNAME_REQUIRED": "Benutzername ist erforderlich" + }, + "SHOW_ARCHIVED_LIBRARIES": "Archivierte Bibliotheken anzeigen", + "HIDE_ARCHIVED_LIBRARIES": "Archivierte Bibliotheken ausblenden", + "UNITS": { + "YEAR": "Jahr", + "YEARS": "Jahre", + "MONTH": "Monat", + "MONTHS": "Monate", + "DAY": "Tag", + "DAYS": "Tage", + "HOUR": "Stunde", + "HOURS": "Stunden", + "MINUTE": "Minute", + "MINUTES": "Minuten", + "SECOND": "Sekunde", + "SECONDS": "Sekunden", + "PLAYS": "Wiedergaben", + "ITEMS": "Elemente", + "STREAMS": "Streams" + }, + "USERS_PAGE": { + "ALL_USERS": "Alle Benutzer", + "LAST_CLIENT": "Letzter Client", + "LAST_SEEN": "Zuletzt gesehen", + "AGO": "vor", + "AGO_ALT": "", + "USER_STATS": "Benutzerstatistiken", + "USER_ACTIVITY": "Benutzeraktivität" + }, + "STAT_PAGE": { + "STATISTICS": "Statistiken", + "DAILY_PLAY_PER_LIBRARY": "Tägliche Wiedergabezahl pro Bibliothek", + "PLAY_COUNT_BY": "Wiedergabezahl nach" + }, + "SETTINGS_PAGE": { + "SETTINGS": "Allgemein", + "LANGUAGE": "Sprache", + "SELECT_AN_ADMIN": "Einen bevorzugten Administrator auswählen", + "LIBRARY_SETTINGS": "Bibliothek", + "BACKUP": "Sicherung", + "BACKUPS": "Sicherungen", + "CHOOSE_FILE": "Datei auswählen", + "LOGS": "Protokolle", + "SIZE": "Größe", + "JELLYFIN_URL": "Jellyfin URL", + "EMBY_URL": "Emby URL", + "EXTERNAL_URL": "Externe URL", + "API_KEY": "API-Schlüssel", + "API_KEYS": "API-Schlüssel", + "KEY_NAME": "Schlüsselname", + "KEY": "Schlüssel", + "NAME": "Name", + "ADD_KEY": "Schlüssel hinzufügen", + "DURATION": "Dauer", + "EXECUTION_TYPE": "Ausführungstyp", + "RESULTS": "Ergebnisse", + "SELECT_ADMIN": "Bevorzugtes Administratorkonto auswählen", + "HOUR_FORMAT": "Stundenformat", + "HOUR_FORMAT_12": "12 Stunden", + "HOUR_FORMAT_24": "24 Stunden", + "SECURITY": "Sicherheit", + "CURRENT_PASSWORD": "Aktuelles Passwort", + "NEW_PASSWORD": "Neues Passwort", + "UPDATE": "Aktualisieren", + "REQUIRE_LOGIN": "Anmeldung erforderlich", + "TASK": "Aufgabe", + "TASKS": "Aufgaben", + "INTERVAL": "Intervall", + "INTERVALS": { + "15_MIN": "15 Minuten", + "30_MIN": "30 Minuten", + "1_HOUR": "1 Stunde", + "12_HOURS": "12 Stunden", + "1_DAY": "1 Tag", + "1_WEEK": "1 Woche" + }, + "SELECT_LIBRARIES_TO_IMPORT": "Bibliotheken zum Importieren auswählen", + "SELECT_LIBRARIES_TO_IMPORT_TOOLTIP": "Die Aktivität für Elemente innerhalb dieser Bibliotheken wird weiterhin verfolgt - auch wenn sie nicht importiert werden.", + "DATE_ADDED": "Hinzugefügt am" + }, + "TASK_TYPE": { + "JOB": "Job", + "IMPORT": "Import" + }, + "TASK_DESCRIPTION": { + "PartialJellyfinSync": "Synchronisierung kürzlich hinzugefügter Elemente", + "JellyfinSync": "Vollständige Synchronisierung mit Jellyfin", + "Jellyfin_Playback_Reporting_Plugin_Sync": "Import von Wiedergabeberichts-Plugin-Daten", + "Backup": "Jellystat Sicherung" + }, + "ABOUT_PAGE": { + "ABOUT_JELLYSTAT": "Über Jellystat", + "VERSION": "Version", + "UPDATE_AVAILABLE": "Update verfügbar", + "GITHUB": "Github", + "Backup": "Jellystat Sicherung" + }, + "TIMELINE_PAGE": { + "TIMELINE": "Zeitleiste", + "EPISODES_one": "Episode", + "EPISODES_other": "Episoden" + }, + "SEARCH": "Suchen", + "TOTAL": "Gesamt", + "LAST": "Letzten", + "SERIES": "Serien", + "SEASON": "Staffel", + "SEASONS": "Staffeln", + "EPISODE": "Episode", + "EPISODES": "Episoden", + "MOVIES": "Filme", + "MUSIC": "Musik", + "SONGS": "Lieder", + "FILES": "Dateien", + "LIBRARIES": "Bibliotheken", + "USER": "Benutzer", + "USERS": "Benutzer", + "TYPE": "Typ", + "NEW_VERSION_AVAILABLE": "Neue Version verfügbar", + "ARCHIVED": "Archiviert", + "NOT_ARCHIVED": "Nicht archiviert", + "ALL": "Alle", + "CLOSE": "Schließen", + "TOTAL_PLAYS": "Gesamtwiedergaben", + "TITLE": "Titel", + "VIEWS": "Ansichten", + "WATCH_TIME": "Wiedergabezeit", + "LAST_WATCHED": "Zuletzt angesehen", + "MEDIA": "Medien", + "SAVE": "Speichern", + "YES": "Ja", + "NO": "Nein", + "FILE_NAME": "Dateiname", + "DATE": "Datum", + "START": "Start", + "STOP": "Stop", + "DOWNLOAD": "Herunterladen", + "RESTORE": "Wiederherstellen", + "ACTIONS": "Aktionen", + "DELETE": "Löschen", + "BITRATE": "Bitrate", + "CONTAINER": "Container", + "VIDEO": "Video", + "CODEC": "Codec", + "WIDTH": "Breite", + "HEIGHT": "Höhe", + "FRAMERATE": "Bildrate", + "DYNAMIC_RANGE": "Dynamikbereich", + "ASPECT_RATIO": "Seitenverhältnis", + "AUDIO": "Audio", + "CHANNELS": "Kanäle", + "LANGUAGE": "Sprache", + "STREAM_DETAILS": "Stream Details", + "SOURCE_DETAILS": "Details zur Videoquelle", + "DIRECT": "Direkt", + "TRANSCODE": "Transkodieren", + "DIRECT_STREAM": "Direkt-Stream", + "USERNAME": "Benutzername", + "PASSWORD": "Passwort", + "LOGIN": "Anmelden", + "FT_SETUP_PROGRESS": "Erster Einrichtungsschritt {STEP} von {TOTAL}", + "VALIDATING": "Validierung läuft", + "SAVE_JELLYFIN_DETAILS": "Jellyfin-Details speichern", + "SETTINGS_SAVED": "Einstellungen gespeichert", + "SUCCESS": "Erfolg", + "PASSWORD_UPDATE_SUCCESS": "Passwort erfolgreich aktualisiert", + "CREATE_USER": "Benutzer erstellen", + "GEOLOCATION_INFO_FOR": "Geolokalisierungsinformationen für", + "CITY": "Stadt", + "REGION": "Region", + "COUNTRY": "Land", + "ORGANIZATION": "Organisation", + "ISP": "ISP", + "LATITUDE": "Breitengrad", + "LONGITUDE": "Längengrad", + "TIMEZONE": "Zeitzone", + "POSTCODE": "Postleitzahl", + "X_ROWS_SELECTED": "{ROWS} Zeilen ausgewählt", + "TRANSCODE_REASONS": "Transkodierungsgründe", + "SUBTITLES": "Untertitel", + "GENRES": "Genres" +} \ No newline at end of file diff --git a/src/lib/languages.jsx b/src/lib/languages.jsx index 86683f7..3e00a9f 100644 --- a/src/lib/languages.jsx +++ b/src/lib/languages.jsx @@ -23,4 +23,8 @@ export const languages = [ id: "ca-ES", description: "Català", }, + { + id: "de-DE", + description: "Deutsch", + }, ]; From f11dfc187c5342bf427a5b1768b08ed1ceb55714 Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Sat, 14 Jun 2025 18:33:56 +0200 Subject: [PATCH 10/24] fix: update base image to node:lts-slim for improved stability --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3abb606..26a325f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build the application -FROM node:slim AS builder +FROM node:lts-slim AS builder WORKDIR /app From 24517c4d82382b4b55f575073ffcf4def1ce9984 Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Sat, 14 Jun 2025 18:45:17 +0200 Subject: [PATCH 11/24] fix: update base image to node:lts-slim for improved stability --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 26a325f..f00d2eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ COPY entry.sh ./ RUN npm run build # Stage 2: Create the production image -FROM node:slim +FROM node:lts-slim RUN apt-get update && \ apt-get install -yqq --no-install-recommends wget && \ From 67bdb8dafba095876a693d2f186861f95549834e Mon Sep 17 00:00:00 2001 From: Zlendy Date: Thu, 12 Jun 2025 01:33:15 +0200 Subject: [PATCH 12/24] refactor: Replace `moment` with `dayjs` https://day.js.org/en/ --- backend/classes/backup.js | 4 ++-- backend/classes/logging.js | 8 ++++---- backend/models/jf_activity_watchdog.js | 4 ++-- backend/routes/api.js | 18 +++++++++--------- backend/routes/stats.js | 18 +++++++++--------- backend/routes/sync.js | 18 +++++++++--------- backend/tasks/ActivityMonitor.js | 14 +++++++------- package-lock.json | 11 ++++++----- package.json | 2 +- .../activity-timeline-item.jsx | 6 +++--- 10 files changed, 52 insertions(+), 51 deletions(-) diff --git a/backend/classes/backup.js b/backend/classes/backup.js index d2c21f0..1c95fbd 100644 --- a/backend/classes/backup.js +++ b/backend/classes/backup.js @@ -3,7 +3,7 @@ const fs = require("fs"); const path = require("path"); const configClass = require("./config"); -const moment = require("moment"); +const dayjs = require("dayjs"); const Logging = require("./logging"); const taskstate = require("../logging/taskstate"); @@ -50,7 +50,7 @@ async function backup(refLog) { // Get data from each table and append it to the backup file try { - let now = moment(); + let now = dayjs(); const backuppath = "./" + backupfolder; if (!fs.existsSync(backuppath)) { diff --git a/backend/classes/logging.js b/backend/classes/logging.js index c75a864..16c78df 100644 --- a/backend/classes/logging.js +++ b/backend/classes/logging.js @@ -1,12 +1,12 @@ const db = require("../db"); -const moment = require("moment"); +const dayjs = require("dayjs"); const taskstate = require("../logging/taskstate"); const { jf_logging_columns, jf_logging_mapping } = require("../models/jf_logging"); async function insertLog(uuid, triggertype, taskType) { try { - let startTime = moment(); + let startTime = dayjs(); const log = { Id: uuid, Name: taskType, @@ -32,8 +32,8 @@ async function updateLog(uuid, data, taskstate) { if (task.length === 0) { console.log("Unable to find task to update"); } else { - let endtime = moment(); - let startTime = moment(task[0].TimeRun); + let endtime = dayjs(); + let startTime = dayjs(task[0].TimeRun); let duration = endtime.diff(startTime, "seconds"); const log = { Id: uuid, diff --git a/backend/models/jf_activity_watchdog.js b/backend/models/jf_activity_watchdog.js index bde3de8..6a1b3b7 100644 --- a/backend/models/jf_activity_watchdog.js +++ b/backend/models/jf_activity_watchdog.js @@ -1,4 +1,4 @@ -const moment = require("moment"); +const dayjs = require("dayjs"); const { randomUUID } = require("crypto"); const jf_activity_watchdog_columns = [ @@ -45,7 +45,7 @@ const jf_activity_watchdog_mapping = (item) => ({ PlaybackDuration: item.PlaybackDuration !== undefined ? item.PlaybackDuration : 0, PlayMethod: item.PlayState.PlayMethod, ActivityDateInserted: - item.ActivityDateInserted !== undefined ? item.ActivityDateInserted : moment().format("YYYY-MM-DD HH:mm:ss.SSSZ"), + item.ActivityDateInserted !== undefined ? item.ActivityDateInserted : dayjs().format("YYYY-MM-DD HH:mm:ss.SSSZ"), MediaStreams: item.NowPlayingItem.MediaStreams ? item.NowPlayingItem.MediaStreams : null, TranscodingInfo: item.TranscodingInfo ? item.TranscodingInfo : null, PlayState: item.PlayState ? item.PlayState : null, diff --git a/backend/routes/api.js b/backend/routes/api.js index 7cbe0f5..de18996 100644 --- a/backend/routes/api.js +++ b/backend/routes/api.js @@ -11,7 +11,7 @@ const configClass = require("../classes/config"); const { checkForUpdates } = require("../version-control"); const API = require("../classes/api-loader"); const { sendUpdate } = require("../ws"); -const moment = require("moment"); +const dayjs = require("dayjs"); const { tables } = require("../global/backup_tables"); const TaskScheduler = require("../classes/task-scheduler-singleton"); const TaskManager = require("../classes/task-manager-singleton.js"); @@ -329,11 +329,11 @@ router.get("/getRecentlyAdded", async (req, res) => { let lastSynctedItemDate; if (items.length > 0 && items[0].DateCreated !== undefined && items[0].DateCreated !== null) { - lastSynctedItemDate = moment(items[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); + lastSynctedItemDate = dayjs(items[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); } if (episodes.length > 0 && episodes[0].DateCreated !== undefined && episodes[0].DateCreated !== null) { - const newLastSynctedItemDate = moment(episodes[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); + const newLastSynctedItemDate = dayjs(episodes[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); if (lastSynctedItemDate === undefined || newLastSynctedItemDate.isAfter(lastSynctedItemDate)) { lastSynctedItemDate = newLastSynctedItemDate; @@ -342,7 +342,7 @@ router.get("/getRecentlyAdded", async (req, res) => { if (lastSynctedItemDate !== undefined) { recentlyAddedFromJellystatMapped = recentlyAddedFromJellystatMapped.filter((item) => - moment(item.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ").isAfter(lastSynctedItemDate) + dayjs(item.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ").isAfter(lastSynctedItemDate) ); } @@ -354,7 +354,7 @@ router.get("/getRecentlyAdded", async (req, res) => { const recentlyAdded = [...recentlyAddedFromJellystatMapped, ...filteredDbRows]; // Sort recentlyAdded by DateCreated in descending order recentlyAdded.sort( - (a, b) => moment(b.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") - moment(a.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") + (a, b) => dayjs(b.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") - dayjs(a.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") ); res.send(recentlyAdded); @@ -383,11 +383,11 @@ router.get("/getRecentlyAdded", async (req, res) => { ); let lastSynctedItemDate; if (items.length > 0 && items[0].DateCreated !== undefined && items[0].DateCreated !== null) { - lastSynctedItemDate = moment(items[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); + lastSynctedItemDate = dayjs(items[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); } if (episodes.length > 0 && episodes[0].DateCreated !== undefined && episodes[0].DateCreated !== null) { - const newLastSynctedItemDate = moment(episodes[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); + const newLastSynctedItemDate = dayjs(episodes[0].DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ"); if (lastSynctedItemDate === undefined || newLastSynctedItemDate.isAfter(lastSynctedItemDate)) { lastSynctedItemDate = newLastSynctedItemDate; @@ -396,7 +396,7 @@ router.get("/getRecentlyAdded", async (req, res) => { if (lastSynctedItemDate !== undefined) { recentlyAddedFromJellystatMapped = recentlyAddedFromJellystatMapped.filter((item) => - moment(item.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ").isAfter(lastSynctedItemDate) + dayjs(item.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ").isAfter(lastSynctedItemDate) ); } @@ -414,7 +414,7 @@ router.get("/getRecentlyAdded", async (req, res) => { // Sort recentlyAdded by DateCreated in descending order recentlyAdded.sort( - (a, b) => moment(b.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") - moment(a.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") + (a, b) => dayjs(b.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") - dayjs(a.DateCreated, "YYYY-MM-DD HH:mm:ss.SSSZ") ); res.send(recentlyAdded); diff --git a/backend/routes/stats.js b/backend/routes/stats.js index a3f105a..a54a007 100644 --- a/backend/routes/stats.js +++ b/backend/routes/stats.js @@ -2,7 +2,7 @@ const express = require("express"); const db = require("../db"); const dbHelper = require("../classes/db-helper"); -const moment = require("moment"); +const dayjs = require("dayjs"); const router = express.Router(); @@ -11,8 +11,8 @@ function countOverlapsPerHour(records) { const hourCounts = {}; records.forEach((record) => { - const start = moment(record.StartTime).subtract(1, "hour"); - const end = moment(record.EndTime).add(1, "hour"); + const start = dayjs(record.StartTime).subtract(1, "hour"); + const end = dayjs(record.EndTime).add(1, "hour"); // Iterate through each hour from start to end for (let hour = start.clone().startOf("hour"); hour.isBefore(end); hour.add(1, "hour")) { @@ -289,12 +289,12 @@ router.post("/getLibraryItemsWithStats", async (req, res) => { router.post("/getLibraryItemsPlayMethodStats", async (req, res) => { try { - let { libraryid, startDate, endDate = moment(), hours = 24 } = req.body; + let { libraryid, startDate, endDate = dayjs(), hours = 24 } = req.body; - // Validate startDate and endDate using moment + // Validate startDate and endDate using dayjs if ( startDate !== undefined && - (!moment(startDate, moment.ISO_8601, true).isValid() || !moment(endDate, moment.ISO_8601, true).isValid()) + (!dayjs(startDate, dayjs.ISO_8601, true).isValid() || !dayjs(endDate, dayjs.ISO_8601, true).isValid()) ) { return res.status(400).send({ error: "Invalid date format" }); } @@ -308,7 +308,7 @@ router.post("/getLibraryItemsPlayMethodStats", async (req, res) => { } if (startDate === undefined) { - startDate = moment(endDate).subtract(hours, "hour").format("YYYY-MM-DD HH:mm:ss"); + startDate = dayjs(endDate).subtract(hours, "hour").format("YYYY-MM-DD HH:mm:ss"); } const { rows } = await db.query( @@ -336,8 +336,8 @@ router.post("/getLibraryItemsPlayMethodStats", async (req, res) => { NowPlayingItemName: item.NowPlayingItemName, EpisodeId: item.EpisodeId || null, SeasonId: item.SeasonId || null, - StartTime: moment(item.ActivityDateInserted).subtract(item.PlaybackDuration, "seconds").format("YYYY-MM-DD HH:mm:ss"), - EndTime: moment(item.ActivityDateInserted).format("YYYY-MM-DD HH:mm:ss"), + StartTime: dayjs(item.ActivityDateInserted).subtract(item.PlaybackDuration, "seconds").format("YYYY-MM-DD HH:mm:ss"), + EndTime: dayjs(item.ActivityDateInserted).format("YYYY-MM-DD HH:mm:ss"), PlaybackDuration: item.PlaybackDuration, PlayMethod: item.PlayMethod, TranscodedVideo: item.TranscodingInfo?.IsVideoDirect || false, diff --git a/backend/routes/sync.js b/backend/routes/sync.js index 4f811ce..eff6318 100644 --- a/backend/routes/sync.js +++ b/backend/routes/sync.js @@ -1,7 +1,7 @@ const express = require("express"); const db = require("../db"); -const moment = require("moment"); +const dayjs = require("dayjs"); const { randomUUID } = require("crypto"); const { sendUpdate } = require("../ws"); @@ -530,13 +530,13 @@ async function syncPlaybackPluginData() { let query = `SELECT rowid, * FROM PlaybackActivity`; if (OldestPlaybackActivity && NewestPlaybackActivity) { - const formattedDateTimeOld = moment(OldestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); - const formattedDateTimeNew = moment(NewestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); + const formattedDateTimeOld = dayjs(OldestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); + const formattedDateTimeNew = dayjs(NewestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); query = query + ` WHERE (DateCreated < '${formattedDateTimeOld}' or DateCreated > '${formattedDateTimeNew}')`; } if (OldestPlaybackActivity && !NewestPlaybackActivity) { - const formattedDateTimeOld = moment(OldestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); + const formattedDateTimeOld = dayjs(OldestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); query = query + ` WHERE DateCreated < '${formattedDateTimeOld}'`; if (MaxPlaybackReportingPluginID) { query = query + ` AND rowid > ${MaxPlaybackReportingPluginID}`; @@ -544,7 +544,7 @@ async function syncPlaybackPluginData() { } if (!OldestPlaybackActivity && NewestPlaybackActivity) { - const formattedDateTimeNew = moment(NewestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); + const formattedDateTimeNew = dayjs(NewestPlaybackActivity).format("YYYY-MM-DD HH:mm:ss"); query = query + ` WHERE DateCreated > '${formattedDateTimeNew}'`; if (MaxPlaybackReportingPluginID) { query = query + ` AND rowid > ${MaxPlaybackReportingPluginID}`; @@ -871,7 +871,7 @@ async function partialSync(triggertype) { let updateItemInfoCount = 0; let updateEpisodeInfoCount = 0; - let lastSyncDate = moment().subtract(24, "hours"); + let lastSyncDate = dayjs().subtract(24, "hours"); const last_execution = await db .query( @@ -882,7 +882,7 @@ async function partialSync(triggertype) { ) .then((res) => res.rows); if (last_execution.length !== 0) { - lastSyncDate = moment(last_execution[0].DateCreated); + lastSyncDate = dayjs(last_execution[0].DateCreated); } //for each item in library run get item using that id as the ParentId (This gets the children of the parent id) @@ -909,7 +909,7 @@ async function partialSync(triggertype) { }, }); - libraryItems = libraryItems.filter((item) => moment(item.DateCreated).isAfter(lastSyncDate)); + libraryItems = libraryItems.filter((item) => dayjs(item.DateCreated).isAfter(lastSyncDate)); while (libraryItems.length != 0) { if (libraryItems.length === 0 && startIndex === 0) { @@ -974,7 +974,7 @@ async function partialSync(triggertype) { }, }); - libraryItems = libraryItems.filter((item) => moment(item.DateCreated).isAfter(lastSyncDate)); + libraryItems = libraryItems.filter((item) => dayjs(item.DateCreated).isAfter(lastSyncDate)); } } diff --git a/backend/tasks/ActivityMonitor.js b/backend/tasks/ActivityMonitor.js index 43f1969..f716366 100644 --- a/backend/tasks/ActivityMonitor.js +++ b/backend/tasks/ActivityMonitor.js @@ -1,6 +1,6 @@ const db = require("../db"); -const moment = require("moment"); +const dayjs = require("dayjs"); const { columnsPlayback } = require("../models/jf_playback_activity"); const { jf_activity_watchdog_columns, jf_activity_watchdog_mapping } = require("../models/jf_activity_watchdog"); const configClass = require("../classes/config"); @@ -31,8 +31,8 @@ async function getSessionsInWatchDog(SessionData, WatchdogData) { //if the playstate was paused, calculate the difference in seconds and add to the playback duration if (sessionData.PlayState.IsPaused == true) { - let startTime = moment(wdData.ActivityDateInserted, "YYYY-MM-DD HH:mm:ss.SSSZ"); - let lastPausedDate = moment(sessionData.LastPausedDate); + let startTime = dayjs(wdData.ActivityDateInserted, "YYYY-MM-DD HH:mm:ss.SSSZ"); + let lastPausedDate = dayjs(sessionData.LastPausedDate); let diffInSeconds = lastPausedDate.diff(startTime, "seconds"); @@ -40,7 +40,7 @@ async function getSessionsInWatchDog(SessionData, WatchdogData) { wdData.ActivityDateInserted = `${lastPausedDate.format("YYYY-MM-DD HH:mm:ss.SSSZ")}`; } else { - wdData.ActivityDateInserted = moment().format("YYYY-MM-DD HH:mm:ss.SSSZ"); + wdData.ActivityDateInserted = dayjs().format("YYYY-MM-DD HH:mm:ss.SSSZ"); } return true; } @@ -97,8 +97,8 @@ function getWatchDogNotInSessions(SessionData, WatchdogData) { removedData.map((obj) => { obj.Id = obj.ActivityId; - let startTime = moment(obj.ActivityDateInserted, "YYYY-MM-DD HH:mm:ss.SSSZ"); - let endTime = moment(); + let startTime = dayjs(obj.ActivityDateInserted, "YYYY-MM-DD HH:mm:ss.SSSZ"); + let endTime = dayjs(); let diffInSeconds = endTime.diff(startTime, "seconds"); @@ -212,7 +212,7 @@ async function ActivityMonitor(interval) { if (existingrow) { playbackData.Id = existingrow.Id; playbackData.PlaybackDuration = Number(existingrow.PlaybackDuration) + Number(playbackData.PlaybackDuration); - playbackData.ActivityDateInserted = moment().format("YYYY-MM-DD HH:mm:ss.SSSZ"); + playbackData.ActivityDateInserted = dayjs().format("YYYY-MM-DD HH:mm:ss.SSSZ"); return true; } return false; diff --git a/package-lock.json b/package-lock.json index f9449fc..a6b09d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "jfstat", - "version": "1.1.4", + "version": "1.1.7", "dependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.0", @@ -29,6 +29,7 @@ "config": "^3.3.9", "cors": "^2.8.5", "crypto-js": "^4.1.1", + "dayjs": "^1.11.13", "dns-cache": "^2.0.0", "dotenv": "^16.3.1", "dottie": "^2.0.6", @@ -44,7 +45,6 @@ "knex": "^2.4.2", "material-react-table": "^3.1.0", "memoizee": "^0.4.17", - "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "passport": "^0.6.0", "passport-jwt": "^4.0.1", @@ -8798,9 +8798,10 @@ } }, "node_modules/dayjs": { - "version": "1.11.10", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", - "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" + "version": "1.11.13", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz", + "integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==", + "license": "MIT" }, "node_modules/debug": { "version": "2.6.9", diff --git a/package.json b/package.json index 79a9494..2b612a8 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "config": "^3.3.9", "cors": "^2.8.5", "crypto-js": "^4.1.1", + "dayjs": "^1.11.13", "dns-cache": "^2.0.0", "dotenv": "^16.3.1", "dottie": "^2.0.6", @@ -51,7 +52,6 @@ "knex": "^2.4.2", "material-react-table": "^3.1.0", "memoizee": "^0.4.17", - "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "passport": "^0.6.0", "passport-jwt": "^4.0.1", diff --git a/src/pages/components/activity-timeline/activity-timeline-item.jsx b/src/pages/components/activity-timeline/activity-timeline-item.jsx index 20a78a0..a7e2c6c 100644 --- a/src/pages/components/activity-timeline/activity-timeline-item.jsx +++ b/src/pages/components/activity-timeline/activity-timeline-item.jsx @@ -13,7 +13,7 @@ import baseUrl from "../../../lib/baseurl"; import "../../css/timeline/activity-timeline.css"; import { useMediaQuery, useTheme } from "@mui/material"; -import moment from "moment"; +import dayjs from "dayjs"; import TvLineIcon from "remixicon-react/TvLineIcon.js"; import FilmLineIcon from "remixicon-react/FilmLineIcon.js"; import { MEDIA_TYPES } from "./helpers"; @@ -29,8 +29,8 @@ const dateFormatOptions = { }; function formatEntryDates(FirstActivityDate, LastActivityDate, MediaType) { - const startDate = moment(FirstActivityDate); - const endDate = moment(LastActivityDate); + const startDate = dayjs(FirstActivityDate); + const endDate = dayjs(LastActivityDate); if (startDate.isSame(endDate, "day") || MediaType === MEDIA_TYPES.Movies) { return Intl.DateTimeFormat(localization, dateFormatOptions).format( From 5b3b0396cbd806a2590d0b90c9c7922615946732 Mon Sep 17 00:00:00 2001 From: jon4hz Date: Sun, 29 Jun 2025 23:08:28 +0200 Subject: [PATCH 13/24] fix: sanitize data before db insert --- backend/routes/sync.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/routes/sync.js b/backend/routes/sync.js index 4f811ce..b5ab4ae 100644 --- a/backend/routes/sync.js +++ b/backend/routes/sync.js @@ -39,13 +39,41 @@ function getErrorLineNumber(error) { return lineNumber; } +function sanitizeNullBytes(obj) { + if (typeof obj === 'string') { + // Remove various forms of null bytes and control characters that cause Unicode escape sequence errors + return obj + .replace(/\u0000/g, '') // Remove null bytes + .replace(/\\u0000/g, '') // Remove escaped null bytes + .replace(/\x00/g, '') // Remove hex null bytes + .replace(/[\u0000-\u001F\u007F-\u009F]/g, '') // Remove all control characters + .trim(); // Remove leading/trailing whitespace + } + + if (Array.isArray(obj)) { + return obj.map(sanitizeNullBytes); + } + + if (obj && typeof obj === 'object') { + const sanitized = {}; + for (const [key, value] of Object.entries(obj)) { + sanitized[key] = sanitizeNullBytes(value); + } + return sanitized; + } + + return obj; +} + class sync { async getExistingIDsforTable(tablename) { return await db.query(`SELECT "Id" FROM ${tablename}`).then((res) => res.rows.map((row) => row.Id)); } async insertData(tablename, dataToInsert, column_mappings) { - let result = await db.insertBulk(tablename, dataToInsert, column_mappings); + const sanitizedData = sanitizeNullBytes(dataToInsert); + + let result = await db.insertBulk(tablename, sanitizedData, column_mappings); if (result.Result === "SUCCESS") { // syncTask.loggedData.push({ color: "dodgerblue", Message: dataToInsert.length + " Rows Inserted." }); } else { From 03e8ced53c60b3de32d9183af31ac2e4f41c380e Mon Sep 17 00:00:00 2001 From: Simon Caron <8635747+simoncaron@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:55:15 -0400 Subject: [PATCH 14/24] Update iOS PWA Icon Sizing and Background --- index.html | 2 +- public/apple-touch-icon.png | Bin 0 -> 4269 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 public/apple-touch-icon.png diff --git a/index.html b/index.html index 948e3aa..7e6b101 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ - +