Files
homepage/src/widgets/immich/component.jsx
T
dependabot[bot] 81accd8dbe
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Chore(deps-dev): Bump eslint-config-next from 15.5.22 to 16.3.3 (#7082)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
2026-09-01 10:52:46 -07:00

61 lines
2.1 KiB
React

import { useTranslation } from "next-i18next/pages";
import Block from "components/services/widget/block";
import Container from "components/services/widget/container";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { version = 1 } = widget;
const versionEndpoint = version === 2 ? "version_v2" : "version";
const { data: versionData, error: versionError } = useWidgetAPI(widget, versionEndpoint);
let statsEndpoint = version === 2 ? "statistics_v2" : "stats";
if (version === 1) {
// see https://github.com/gethomepage/homepage/issues/2282
statsEndpoint =
versionData?.major > 1 || (versionData?.major === 1 && versionData?.minor > 84) ? "statistics" : "stats";
}
const { data: immichData, error: immichError } = useWidgetAPI(widget, statsEndpoint);
if (immichError || versionError || immichData?.statusCode === 401) {
return <Container service={service} error={immichData ?? immichError ?? versionError} />;
}
if (!immichData) {
return (
<Container service={service}>
<Block label="immich.users" />
<Block label="immich.photos" />
<Block label="immich.videos" />
<Block label="immich.storage" />
</Container>
);
}
return (
<Container service={service}>
<Block label="immich.users" value={t("common.number", { value: immichData.usageByUser.length })} />
<Block label="immich.photos" value={t("common.number", { value: immichData.photos })} />
<Block label="immich.videos" value={t("common.number", { value: immichData.videos })} />
<Block
label="immich.storage"
value={
// backwards-compatible e.g. '9 GiB'
immichData.usage.toString().toLowerCase().includes("b")
? immichData.usage
: t("common.bytes", {
value: immichData.usage,
maximumFractionDigits: 1,
binary: true, // match immich
})
}
/>
</Container>
);
}