Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(immich): detect http→https redirect on test connection and update URL

jubnle0105115f4ce
diff --git a/client/src/pages/SettingsPage.tsx b/client/src/pages/SettingsPage.tsx
index 65583443d..d888fc4f6 100644
--- a/client/src/pages/SettingsPage.tsx
+++ b/client/src/pages/SettingsPage.tsx
@@ -176,7 +176,12 @@ export default function SettingsPage(): React.ReactElement {
try {
const res = await apiClient.post('/integrations/immich/test', { immich_url: immichUrl, immich_api_key: immichApiKey })
if (res.data.connected) {
- toast.success(`${t('memories.connectionSuccess')} — ${res.data.user?.name || ''}`)
+ if (res.data.canonicalUrl) {
+ setImmichUrl(res.data.canonicalUrl)
+ toast.success(`${t('memories.connectionSuccess')} — ${res.data.user?.name || ''} (URL updated to ${res.data.canonicalUrl})`)
+ } else {
+ toast.success(`${t('memories.connectionSuccess')} — ${res.data.user?.name || ''}`)
+ }
setImmichTestPassed(true)
} else {
toast.error(`${t('memories.connectionError')}: ${res.data.error}`)
diff --git a/server/src/services/immichService.ts b/server/src/services/immichService.ts
index 9dd3de50d..64683382d 100644
--- a/server/src/services/immichService.ts
+++ b/server/src/services/immichService.ts
@@ -69,7 +69,7 @@ export async function saveImmichSettings(
export async function testConnection(
immichUrl: string,
immichApiKey: string
-): Promise<{ connected: boolean; error?: string; user?: { name?: string; email?: string } }> {
+): Promise<{ connected: boolean; error?: string; user?: { name?: string; email?: string }; canonicalUrl?: string }> {
const ssrf = await checkSsrf(immichUrl);
if (!ssrf.allowed) return { connected: false, error: ssrf.error ?? 'Invalid Immich URL' };
try {
@@ -79,7 +79,23 @@ export async function testConnection(
});
if (!resp.ok) return { connected: false, error: `HTTP ${resp.status}` };
const data = await resp.json() as { name?: string; email?: string };
- return { connected: true, user: { name: data.name, email: data.email } };
+
+ // Detect http → https upgrade only: same host/port, protocol changed to https
+ let canonicalUrl: string | undefined;
+ if (resp.url) {
+ const finalUrl = new URL(resp.url);
+ const inputUrl = new URL(immichUrl);
+ if (
+ inputUrl.protocol === 'http:' &&
+ finalUrl.protocol === 'https:' &&
+ finalUrl.hostname === inputUrl.hostname &&
+ finalUrl.port === inputUrl.port
+ ) {
+ canonicalUrl = finalUrl.origin;
+ }
+ }
+
+ return { connected: true, user: { name: data.name, email: data.email }, canonicalUrl };
} catch (err: unknown) {
return { connected: false, error: err instanceof Error ? err.message : 'Connection failed' };
}