Skip to content

Commit

Permalink
Enhancement: handle immich v1.118 breaking API change (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamoon authored Oct 10, 2024
1 parent cd8c224 commit 19bdc0e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
6 changes: 6 additions & 0 deletions docs/widgets/services/immich.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ description: Immich Widget Configuration

Learn more about [Immich](https://github.com/immich-app/immich).

| Immich Version | Homepage Widget Version |
| -------------- | ----------------------- |
| < v1.118 | 1 (default) |
| >= v1.118 | 2 |

Find your API key under `Account Settings > API Keys`.

Allowed fields: `["users" ,"photos", "videos", "storage"]`.
Expand All @@ -16,4 +21,5 @@ widget:
type: immich
url: http://immich.host.or.ip
key: adminapikeyadminapikeyadminapikey
version: 2 # optional, default is 1
```
6 changes: 3 additions & 3 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function cleanServiceGroups(groups) {
// frigate
enableRecentEvents,

// glances, mealie, pihole, pfsense
// glances, immich, mealie, pihole, pfsense
version,

// glances
Expand Down Expand Up @@ -568,8 +568,8 @@ export function cleanServiceGroups(groups) {
if (snapshotHost) cleanedService.widget.snapshotHost = snapshotHost;
if (snapshotPath) cleanedService.widget.snapshotPath = snapshotPath;
}
if (["glances", "mealie", "pfsense", "pihole"].includes(type)) {
if (version) cleanedService.widget.version = version;
if (["glances", "immich", "mealie", "pfsense", "pihole"].includes(type)) {
if (version) cleanedService.widget.version = parseInt(version, 10);
}
if (type === "glances") {
if (metric) cleanedService.widget.metric = metric;
Expand Down
18 changes: 13 additions & 5 deletions src/widgets/immich/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;

const { data: versionData, error: versionError } = useWidgetAPI(widget, "version");
// see https://github.com/gethomepage/homepage/issues/2282
const endpoint =
versionData?.major > 1 || (versionData?.major === 1 && versionData?.minor > 84) ? "statistics" : "stats";
const { data: immichData, error: immichError } = useWidgetAPI(widget, endpoint);
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} />;
Expand Down
14 changes: 10 additions & 4 deletions src/widgets/immich/widget.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";

const widget = {
api: "{url}/api/server-info/{endpoint}",
api: "{url}/api/{endpoint}",
proxyHandler: credentialedProxyHandler,

mappings: {
version: {
endpoint: "version",
endpoint: "server-info/version",
},
statistics: {
endpoint: "statistics",
endpoint: "server-info/statistics",
},
stats: {
endpoint: "stats",
endpoint: "server-info/stats",
},
version_v2: {
endpoint: "server/version",
},
statistics_v2: {
endpoint: "server/statistics",
},
},
};
Expand Down

0 comments on commit 19bdc0e

Please sign in to comment.