Enhancement: use duration for audiobookshelf tottal, refactor uptime (#4229)

pull/4232/head
shamoon 3 weeks ago committed by GitHub
parent 3736c1fcab
commit e6cf86ed4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.ms` | `1,000 ms` | Format a number in milliseconds. |
| `common.date` | `2024-01-01` | Format a date. | | `common.date` | `2024-01-01` | Format a date. |
| `common.relativeDate` | `1 day ago` | Format a relative 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 ### Text

@ -84,12 +84,12 @@ function prettyBytes(number, options) {
return `${prefix + numberString} ${unit}`; return `${prefix + numberString} ${unit}`;
} }
function uptime(uptimeInSeconds, i18next) { function duration(durationInSeconds, i18next) {
const mo = Math.floor(uptimeInSeconds / (3600 * 24 * 31)); const mo = Math.floor(durationInSeconds / (3600 * 24 * 31));
const d = Math.floor((uptimeInSeconds % (3600 * 24 * 31)) / (3600 * 24)); const d = Math.floor((durationInSeconds % (3600 * 24 * 31)) / (3600 * 24));
const h = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600); const h = Math.floor((durationInSeconds % (3600 * 24)) / 3600);
const m = Math.floor((uptimeInSeconds % 3600) / 60); const m = Math.floor((durationInSeconds % 3600) / 60);
const s = Math.floor(uptimeInSeconds % 60); const s = Math.floor(durationInSeconds % 60);
const moDisplay = mo > 0 ? mo + i18next.t("common.months") : ""; const moDisplay = mo > 0 ? mo + i18next.t("common.months") : "";
const dDisplay = d > 0 ? d + i18next.t("common.days") : ""; const dDisplay = d > 0 ? d + i18next.t("common.days") : "";
@ -156,7 +156,7 @@ module.exports = {
i18next.services.formatter.add("relativeDate", (value, lng, options) => i18next.services.formatter.add("relativeDate", (value, lng, options) =>
relativeDate(new Date(value), new Intl.RelativeTimeFormat(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", type: "3rdParty",
}, },

@ -13,7 +13,7 @@
"ms": "{{value, number}}", "ms": "{{value, number}}",
"date": "{{value, date}}", "date": "{{value, date}}",
"relativeDate": "{{value, relativeDate}}", "relativeDate": "{{value, relativeDate}}",
"uptime": "{{value, uptime}}", "duration": "{{value, duration}}",
"months": "mo", "months": "mo",
"days": "d", "days": "d",
"hours": "h", "hours": "h",

@ -25,7 +25,7 @@ export default function Uptime({ refresh = 1500 }) {
return ( return (
<Resource <Resource
icon={FaRegClock} icon={FaRegClock}
value={t("common.uptime", { value: data.uptime })} value={t("common.duration", { value: data.uptime })}
label={t("resources.uptime")} label={t("resources.uptime")}
percentage={percent} percentage={percent}
/> />

@ -39,11 +39,8 @@ export default function Component({ service }) {
<Block label="audiobookshelf.podcasts" value={t("common.number", { value: totalPodcasts })} /> <Block label="audiobookshelf.podcasts" value={t("common.number", { value: totalPodcasts })} />
<Block <Block
label="audiobookshelf.podcastsDuration" label="audiobookshelf.podcastsDuration"
value={t("common.number", { value={t("common.duration", {
value: totalPodcastsDuration / 60, value: totalPodcastsDuration,
maximumFractionDigits: 0,
style: "unit",
unit: "minute",
})} })}
/> />
<Block label="audiobookshelf.books" value={t("common.number", { value: totalBooks })} /> <Block label="audiobookshelf.books" value={t("common.number", { value: totalBooks })} />

@ -40,7 +40,7 @@ export default function Component({ service }) {
/> />
<Block <Block
label="frigate.uptime" label="frigate.uptime"
value={t("common.uptime", { value={t("common.duration", {
value: data.uptime, value: data.uptime,
})} })}
/> />

@ -44,7 +44,7 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="fritzbox.connectionStatus" value={t(`fritzbox.connectionStatus${fritzboxData.connectionStatus}`)} /> <Block label="fritzbox.connectionStatus" value={t(`fritzbox.connectionStatus${fritzboxData.connectionStatus}`)} />
<Block label="fritzbox.uptime" value={t("common.uptime", { value: fritzboxData.uptime })} /> <Block label="fritzbox.uptime" value={t("common.duration", { value: fritzboxData.uptime })} />
<Block label="fritzbox.maxDown" value={t("common.byterate", { value: fritzboxData.maxDown / 8, decimals: 1 })} /> <Block label="fritzbox.maxDown" value={t("common.byterate", { value: fritzboxData.maxDown / 8, decimals: 1 })} />
<Block label="fritzbox.maxUp" value={t("common.byterate", { value: fritzboxData.maxUp / 8, decimals: 1 })} /> <Block label="fritzbox.maxUp" value={t("common.byterate", { value: fritzboxData.maxUp / 8, decimals: 1 })} />
<Block label="fritzbox.down" value={t("common.byterate", { value: fritzboxData.down, decimals: 1 })} /> <Block label="fritzbox.down" value={t("common.byterate", { value: fritzboxData.down, decimals: 1 })} />

@ -20,7 +20,7 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="openwrt.uptime" value={t("common.uptime", { value: uptime })} /> <Block label="openwrt.uptime" value={t("common.duration", { value: uptime })} />
<Block label="openwrt.cpuLoad" value={cpuLoad} /> <Block label="openwrt.cpuLoad" value={cpuLoad} />
</Container> </Container>
); );

@ -46,12 +46,12 @@ export default function Component({ service }) {
<Block label="stash.scenes" value={t("common.number", { value: stats.scene_count })} /> <Block label="stash.scenes" value={t("common.number", { value: stats.scene_count })} />
<Block label="stash.scenesPlayed" value={t("common.number", { value: stats.scenes_played })} /> <Block label="stash.scenesPlayed" value={t("common.number", { value: stats.scenes_played })} />
<Block label="stash.playCount" value={t("common.number", { value: stats.total_play_count })} /> <Block label="stash.playCount" value={t("common.number", { value: stats.total_play_count })} />
<Block label="stash.playDuration" value={t("common.uptime", { value: stats.total_play_duration })} /> <Block label="stash.playDuration" value={t("common.duration", { value: stats.total_play_duration })} />
<Block <Block
label="stash.sceneSize" label="stash.sceneSize"
value={t("common.bbytes", { value: stats.scenes_size, maximumFractionDigits: 1 })} value={t("common.bbytes", { value: stats.scenes_size, maximumFractionDigits: 1 })}
/> />
<Block label="stash.sceneDuration" value={t("common.uptime", { value: stats.scenes_duration })} /> <Block label="stash.sceneDuration" value={t("common.duration", { value: stats.scenes_duration })} />
<Block label="stash.images" value={t("common.number", { value: stats.image_count })} /> <Block label="stash.images" value={t("common.number", { value: stats.image_count })} />
<Block <Block

@ -35,7 +35,7 @@ export default function Component({ service }) {
<> <>
<Container service={service}> <Container service={service}>
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} /> <Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
<Block label="truenas.uptime" value={t("common.uptime", { value: statusData.uptime_seconds })} /> <Block label="truenas.uptime" value={t("common.duration", { value: statusData.uptime_seconds })} />
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} /> <Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
</Container> </Container>
{enablePools && {enablePools &&

@ -58,7 +58,7 @@ export default function Component({ service }) {
break; break;
case 2: case 2:
status = t("uptimerobot.up"); status = t("uptimerobot.up");
uptime = t("common.uptime", { value: monitor.logs[0].duration }); uptime = t("common.duration", { value: monitor.logs[0].duration });
logIndex = 1; logIndex = 1;
break; break;
case 8: case 8:
@ -73,7 +73,7 @@ export default function Component({ service }) {
} }
const lastDown = new Date(monitor.logs[logIndex].datetime * 1000).toLocaleString(); 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; const hideDown = logIndex === 1 && monitor.logs[logIndex].type !== 1;
return ( return (

Loading…
Cancel
Save