From e6cf86ed4a06a48bfb34d7c0217325395f754bad Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:09:23 -0700 Subject: [PATCH] Enhancement: use duration for audiobookshelf tottal, refactor uptime (#4229) --- docs/widgets/authoring/translations.md | 2 +- next-i18next.config.js | 14 +++++++------- public/locales/en/common.json | 2 +- src/components/widgets/resources/uptime.jsx | 2 +- src/widgets/audiobookshelf/component.jsx | 7 ++----- src/widgets/frigate/component.jsx | 2 +- src/widgets/fritzbox/component.jsx | 2 +- src/widgets/openwrt/methods/system.jsx | 2 +- src/widgets/stash/component.jsx | 4 ++-- src/widgets/truenas/component.jsx | 2 +- src/widgets/uptimerobot/component.jsx | 4 ++-- 11 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/widgets/authoring/translations.md b/docs/widgets/authoring/translations.md index 13473f05b..77ad07038 100644 --- a/docs/widgets/authoring/translations.md +++ b/docs/widgets/authoring/translations.md @@ -71,7 +71,7 @@ Homepage provides a set of common translations that you can use in your widgets. | `common.ms` | `1,000 ms` | Format a number in milliseconds. | | `common.date` | `2024-01-01` | Format a date. | | `common.relativeDate` | `1 day ago` | Format a relative date. | -| `common.uptime` | `1 day, 1 hour` | Format an uptime. | +| `common.duration` | `1 day, 1 hour` | Format an duration. | ### Text diff --git a/next-i18next.config.js b/next-i18next.config.js index 96483cc3f..a1b5c7b3f 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -84,12 +84,12 @@ function prettyBytes(number, options) { return `${prefix + numberString} ${unit}`; } -function uptime(uptimeInSeconds, i18next) { - const mo = Math.floor(uptimeInSeconds / (3600 * 24 * 31)); - const d = Math.floor((uptimeInSeconds % (3600 * 24 * 31)) / (3600 * 24)); - const h = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600); - const m = Math.floor((uptimeInSeconds % 3600) / 60); - const s = Math.floor(uptimeInSeconds % 60); +function duration(durationInSeconds, i18next) { + const mo = Math.floor(durationInSeconds / (3600 * 24 * 31)); + const d = Math.floor((durationInSeconds % (3600 * 24 * 31)) / (3600 * 24)); + const h = Math.floor((durationInSeconds % (3600 * 24)) / 3600); + const m = Math.floor((durationInSeconds % 3600) / 60); + const s = Math.floor(durationInSeconds % 60); const moDisplay = mo > 0 ? mo + i18next.t("common.months") : ""; const dDisplay = d > 0 ? d + i18next.t("common.days") : ""; @@ -156,7 +156,7 @@ module.exports = { i18next.services.formatter.add("relativeDate", (value, lng, options) => relativeDate(new Date(value), new Intl.RelativeTimeFormat(lng, { ...options })), ); - i18next.services.formatter.add("uptime", (value, lng) => uptime(value, i18next)); + i18next.services.formatter.add("duration", (value, lng) => duration(value, i18next)); }, type: "3rdParty", }, diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 384f44bef..fd52aef4a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -13,7 +13,7 @@ "ms": "{{value, number}}", "date": "{{value, date}}", "relativeDate": "{{value, relativeDate}}", - "uptime": "{{value, uptime}}", + "duration": "{{value, duration}}", "months": "mo", "days": "d", "hours": "h", diff --git a/src/components/widgets/resources/uptime.jsx b/src/components/widgets/resources/uptime.jsx index 025d1aa53..2fac0fcdf 100644 --- a/src/components/widgets/resources/uptime.jsx +++ b/src/components/widgets/resources/uptime.jsx @@ -25,7 +25,7 @@ export default function Uptime({ refresh = 1500 }) { return ( diff --git a/src/widgets/audiobookshelf/component.jsx b/src/widgets/audiobookshelf/component.jsx index 406a81c28..6eb786381 100755 --- a/src/widgets/audiobookshelf/component.jsx +++ b/src/widgets/audiobookshelf/component.jsx @@ -39,11 +39,8 @@ export default function Component({ service }) { diff --git a/src/widgets/frigate/component.jsx b/src/widgets/frigate/component.jsx index 43b566e8e..ac77be51b 100644 --- a/src/widgets/frigate/component.jsx +++ b/src/widgets/frigate/component.jsx @@ -40,7 +40,7 @@ export default function Component({ service }) { /> diff --git a/src/widgets/fritzbox/component.jsx b/src/widgets/fritzbox/component.jsx index 5939f9edc..c3ea1bf64 100644 --- a/src/widgets/fritzbox/component.jsx +++ b/src/widgets/fritzbox/component.jsx @@ -44,7 +44,7 @@ export default function Component({ service }) { return ( - + diff --git a/src/widgets/openwrt/methods/system.jsx b/src/widgets/openwrt/methods/system.jsx index 7be8aa29b..0a8146cc0 100644 --- a/src/widgets/openwrt/methods/system.jsx +++ b/src/widgets/openwrt/methods/system.jsx @@ -20,7 +20,7 @@ export default function Component({ service }) { return ( - + ); diff --git a/src/widgets/stash/component.jsx b/src/widgets/stash/component.jsx index 3d64c4902..b7c259a89 100644 --- a/src/widgets/stash/component.jsx +++ b/src/widgets/stash/component.jsx @@ -46,12 +46,12 @@ export default function Component({ service }) { - + - + - + {enablePools && diff --git a/src/widgets/uptimerobot/component.jsx b/src/widgets/uptimerobot/component.jsx index 274854019..b2027a6f1 100644 --- a/src/widgets/uptimerobot/component.jsx +++ b/src/widgets/uptimerobot/component.jsx @@ -58,7 +58,7 @@ export default function Component({ service }) { break; case 2: status = t("uptimerobot.up"); - uptime = t("common.uptime", { value: monitor.logs[0].duration }); + uptime = t("common.duration", { value: monitor.logs[0].duration }); logIndex = 1; break; case 8: @@ -73,7 +73,7 @@ export default function Component({ service }) { } const lastDown = new Date(monitor.logs[logIndex].datetime * 1000).toLocaleString(); - const downDuration = t("common.uptime", { value: monitor.logs[logIndex].duration }); + const downDuration = t("common.duration", { value: monitor.logs[logIndex].duration }); const hideDown = logIndex === 1 && monitor.logs[logIndex].type !== 1; return (