mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 14:51:45 +00:00
fix(immich): detect http→https redirect on test connection and update URL
When a user enters an http:// Immich URL that redirects to https://, the test succeeded (GET follows redirects fine) but subsequent POST requests (e.g. photo search) broke due to method downgrade on 301/302. Now testConnection() checks resp.url against the input URL after a successful fetch. If the only difference is http→https on the same host and port, it returns a canonicalUrl so the frontend can update the input field before the user saves — ensuring the correct URL is stored.
This commit is contained in:
@@ -176,7 +176,12 @@ export default function SettingsPage(): React.ReactElement {
|
|||||||
try {
|
try {
|
||||||
const res = await apiClient.post('/integrations/immich/test', { immich_url: immichUrl, immich_api_key: immichApiKey })
|
const res = await apiClient.post('/integrations/immich/test', { immich_url: immichUrl, immich_api_key: immichApiKey })
|
||||||
if (res.data.connected) {
|
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)
|
setImmichTestPassed(true)
|
||||||
} else {
|
} else {
|
||||||
toast.error(`${t('memories.connectionError')}: ${res.data.error}`)
|
toast.error(`${t('memories.connectionError')}: ${res.data.error}`)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export async function saveImmichSettings(
|
|||||||
export async function testConnection(
|
export async function testConnection(
|
||||||
immichUrl: string,
|
immichUrl: string,
|
||||||
immichApiKey: 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);
|
const ssrf = await checkSsrf(immichUrl);
|
||||||
if (!ssrf.allowed) return { connected: false, error: ssrf.error ?? 'Invalid Immich URL' };
|
if (!ssrf.allowed) return { connected: false, error: ssrf.error ?? 'Invalid Immich URL' };
|
||||||
try {
|
try {
|
||||||
@@ -79,7 +79,23 @@ export async function testConnection(
|
|||||||
});
|
});
|
||||||
if (!resp.ok) return { connected: false, error: `HTTP ${resp.status}` };
|
if (!resp.ok) return { connected: false, error: `HTTP ${resp.status}` };
|
||||||
const data = await resp.json() as { name?: string; email?: string };
|
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) {
|
} catch (err: unknown) {
|
||||||
return { connected: false, error: err instanceof Error ? err.message : 'Connection failed' };
|
return { connected: false, error: err instanceof Error ? err.message : 'Connection failed' };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user