mirror of
https://github.com/karl0ss/homepage.git
synced 2025-07-01 05:59:07 +01:00
Add Kopia widget (#1018)
* Add Kopia widget * Add Kopia widget * Modify Kopia widget blocks * Kopia next run / last run --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
806b7f3cab
commit
addf0911a0
@ -495,5 +495,12 @@
|
|||||||
"memoryusage": "Memory Usage",
|
"memoryusage": "Memory Usage",
|
||||||
"freespace": "Free Space",
|
"freespace": "Free Space",
|
||||||
"activeusers": "Active Users"
|
"activeusers": "Active Users"
|
||||||
|
},
|
||||||
|
"kopia": {
|
||||||
|
"status": "Status",
|
||||||
|
"size": "Size",
|
||||||
|
"lastrun": "Last Run",
|
||||||
|
"nextrun": "Next Run",
|
||||||
|
"failed": "Failed"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ const components = {
|
|||||||
jellyfin: dynamic(() => import("./emby/component")),
|
jellyfin: dynamic(() => import("./emby/component")),
|
||||||
jellyseerr: dynamic(() => import("./jellyseerr/component")),
|
jellyseerr: dynamic(() => import("./jellyseerr/component")),
|
||||||
komga: dynamic(() => import("./komga/component")),
|
komga: dynamic(() => import("./komga/component")),
|
||||||
|
kopia: dynamic(() => import("./kopia/component")),
|
||||||
lidarr: dynamic(() => import("./lidarr/component")),
|
lidarr: dynamic(() => import("./lidarr/component")),
|
||||||
mastodon: dynamic(() => import("./mastodon/component")),
|
mastodon: dynamic(() => import("./mastodon/component")),
|
||||||
medusa: dynamic(() => import("./medusa/component")),
|
medusa: dynamic(() => import("./medusa/component")),
|
||||||
|
68
src/widgets/kopia/component.jsx
Executable file
68
src/widgets/kopia/component.jsx
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
function relativeDate(date) {
|
||||||
|
const seconds = Math.abs(Math.floor((new Date() - date) / 1000));
|
||||||
|
|
||||||
|
let interval = Math.abs(seconds / 31536000);
|
||||||
|
|
||||||
|
if (interval > 1) {
|
||||||
|
return `${Math.floor(interval)} y`;
|
||||||
|
}
|
||||||
|
interval = seconds / 2592000;
|
||||||
|
if (interval > 1) {
|
||||||
|
return `${Math.floor(interval)} mo`;
|
||||||
|
}
|
||||||
|
interval = seconds / 86400;
|
||||||
|
if (interval > 1) {
|
||||||
|
return `${Math.floor(interval)} d`;
|
||||||
|
}
|
||||||
|
interval = seconds / 3600;
|
||||||
|
if (interval > 1) {
|
||||||
|
return `${Math.floor(interval)} h`;
|
||||||
|
}
|
||||||
|
interval = seconds / 60;
|
||||||
|
if (interval > 1) {
|
||||||
|
return `${Math.floor(interval)} m`;
|
||||||
|
}
|
||||||
|
return `${Math.floor(seconds)} s`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const { widget } = service;
|
||||||
|
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||||
|
|
||||||
|
if (statusError) {
|
||||||
|
return <Container error={statusError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = statusData?.sources[0];
|
||||||
|
|
||||||
|
if (!statusData || !source) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="kopia.status" />
|
||||||
|
<Block label="kopia.size" />
|
||||||
|
<Block label="kopia.lastrun" />
|
||||||
|
<Block label="kopia.nextrun" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastRun = source.lastSnapshot.stats.errorCount === 0 ? new Date(source.lastSnapshot.startTime) : t("kopia.failed");
|
||||||
|
const nextTime = source.nextSnapshotTime ? new Date(source.nextSnapshotTime) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="kopia.status" value={ source.status } />
|
||||||
|
<Block label="kopia.size" value={t("common.bbytes", { value: source.lastSnapshot.stats.totalSize, maximumFractionDigits: 1 })} />
|
||||||
|
<Block label="kopia.lastrun" value={ relativeDate(lastRun) } />
|
||||||
|
{nextTime && <Block label="kopia.nextrun" value={ relativeDate(nextTime) } />}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
14
src/widgets/kopia/widget.js
Executable file
14
src/widgets/kopia/widget.js
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
status: {
|
||||||
|
endpoint: "api/v1/sources",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
@ -19,6 +19,7 @@ import homebridge from "./homebridge/widget";
|
|||||||
import jackett from "./jackett/widget";
|
import jackett from "./jackett/widget";
|
||||||
import jellyseerr from "./jellyseerr/widget";
|
import jellyseerr from "./jellyseerr/widget";
|
||||||
import komga from "./komga/widget";
|
import komga from "./komga/widget";
|
||||||
|
import kopia from "./kopia/widget";
|
||||||
import lidarr from "./lidarr/widget";
|
import lidarr from "./lidarr/widget";
|
||||||
import mastodon from "./mastodon/widget";
|
import mastodon from "./mastodon/widget";
|
||||||
import medusa from "./medusa/widget";
|
import medusa from "./medusa/widget";
|
||||||
@ -89,6 +90,7 @@ const widgets = {
|
|||||||
jellyfin: emby,
|
jellyfin: emby,
|
||||||
jellyseerr,
|
jellyseerr,
|
||||||
komga,
|
komga,
|
||||||
|
kopia,
|
||||||
lidarr,
|
lidarr,
|
||||||
mastodon,
|
mastodon,
|
||||||
medusa,
|
medusa,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user