Separate upload-ok

This commit is contained in:
Alan Grainger
2026-10-17 16:10:48 +13:00
parent c739e931ea
commit 396bf7bede
7 changed files with 77 additions and 19 deletions
+6 -5
View File
@@ -23,17 +23,18 @@ function readInitParams (): InitParams {
* Show the "Add photos" button once the upload service answers. The button * Show the "Add photos" button once the upload service answers. The button
* is rendered hidden when the service is assumed to be at `/upload` on this * is rendered hidden when the service is assumed to be at `/upload` on this
* hostname rather than configured, so an install without the upload * hostname rather than configured, so an install without the upload
* container never shows a dead button. The upload service answers `ok`; * container never shows a dead button. The upload service answers
* IPP itself answers the same path with an empty 204 when nothing is routed * `upload-ok`, or `ok` from a 4.0.0 upload container, still accepted so the
* there. The header may exist only for this button, in which case it is * two containers can be pulled in either order; IPP itself answers the same
* hidden too. * path with an empty 204 when nothing is routed there. The header may exist
* only for this button, in which case it is hidden too.
*/ */
function revealUploadLink () { function revealUploadLink () {
const link = document.getElementById('upload-link') const link = document.getElementById('upload-link')
const url = link?.dataset.healthcheck const url = link?.dataset.healthcheck
if (!link || !url) return if (!link || !url) return
fetch(url, { cache: 'no-store' }).then(async res => { fetch(url, { cache: 'no-store' }).then(async res => {
if (res.status !== 200 || (await res.text()).trim() !== 'ok') return if (res.status !== 200 || !['upload-ok', 'ok'].includes((await res.text()).trim())) return
link.hidden = false link.hidden = false
document.getElementById('header')?.removeAttribute('hidden') document.getElementById('header')?.removeAttribute('hidden')
}).catch(() => {}) }).catch(() => {})
+1 -1
View File
@@ -142,7 +142,7 @@ With it off, a slug link gets a 404 and only the key form works.
Where the optional upload service (the `immich-public-proxy-upload` container) is served. A share whose "Allow public user to upload" option is on in Immich then shows an "Add photos" button in the gallery header, which opens that share's page on the upload service. To set up the service, see [Let visitors send photos back](/visitor-uploads). Where the optional upload service (the `immich-public-proxy-upload` container) is served. A share whose "Allow public user to upload" option is on in Immich then shows an "Add photos" button in the gallery header, which opens that share's page on the upload service. To set up the service, see [Let visitors send photos back](/visitor-uploads).
- **A path**, such as the default `/upload`, means the service is on IPP's own hostname under that path. Before showing the button, the gallery page checks that the upload service answers `ok` at `<path>/healthcheck`, so an install without the upload container never shows a dead button. When nothing is routed there, IPP answers that path itself with an empty 204. - **A path**, such as the default `/upload`, means the service is on IPP's own hostname under that path. Before showing the button, the gallery page checks that the upload service answers `upload-ok` at `<path>/healthcheck`, so an install without the upload container never shows a dead button. When nothing is routed there, IPP answers that path itself with an empty 204.
- **An absolute URL**, such as `https://upload.example.com`, means the service has a hostname of its own. It is trusted without a check. The URL may include a path, such as `https://photos.example.com/upload`, which points at the same place as the default but without the check. - **An absolute URL**, such as `https://upload.example.com`, means the service has a hostname of its own. It is trusted without a check. The URL may include a path, such as `https://photos.example.com/upload`, which points at the same place as the default but without the check.
- **An empty string** never shows the button. - **An empty string** never shows the button.
+2 -2
View File
@@ -32,7 +32,7 @@ See [Request size limits](/visitor-uploads#request-size-limits).
## The "Add photos" button does not appear ## The "Add photos" button does not appear
The upload service runs and its `/healthcheck` answers `ok`, but a share with **Allow public user to upload** turned The upload service runs and its `/healthcheck` answers `upload-ok`, but a share with **Allow public user to upload** turned
on shows no button in the gallery. View the gallery page's source and look for `id="upload-link"`: on shows no button in the gallery. View the gallery page's source and look for `id="upload-link"`:
- **The page source has no `upload-link`, and the script URL is `/share/static/3.x.x/...`.** IPP is still 3.x, which - **The page source has no `upload-link`, and the script URL is `/share/static/3.x.x/...`.** IPP is still 3.x, which
@@ -42,7 +42,7 @@ on shows no button in the gallery. View the gallery page's source and look for `
upload option is off in Immich, or [`uploadUrl`](/config/ipp-options#uploadurl) is set to an empty string or upload option is off in Immich, or [`uploadUrl`](/config/ipp-options#uploadurl) is set to an empty string or
something other than a path or an absolute URL. A changed `config.json` or `CONFIG` needs a restart. something other than a path or an absolute URL. A changed `config.json` or `CONFIG` needs a restart.
- **`upload-link` is there with a `hidden` attribute.** IPP assumed the service at `/upload` on its own hostname and - **`upload-link` is there with a `hidden` attribute.** IPP assumed the service at `/upload` on its own hostname and
the browser's check of `/upload/healthcheck` there did not answer `ok`. Open that URL on the **gallery** hostname, the browser's check of `/upload/healthcheck` there did not answer `upload-ok`. Open that URL on the **gallery** hostname,
for example `https://photos.example.com/upload/healthcheck`. An empty page means the reverse proxy sent the for example `https://photos.example.com/upload/healthcheck`. An empty page means the reverse proxy sent the
request to IPP rather than to the upload service, so add or fix the `/upload` route. If the upload service has its request to IPP rather than to the upload service, so add or fix the `/upload` route. If the upload service has its
own hostname, set [`uploadUrl`](/config/ipp-options#uploadurl) to it in IPP's config; a setting elsewhere in the own hostname, set [`uploadUrl`](/config/ipp-options#uploadurl) to it in IPP's config; a setting elsewhere in the
+6 -3
View File
@@ -234,9 +234,12 @@ keys, and the upload service reads only those and [two shared options](/config/u
### Check the route ### Check the route
Open `/healthcheck` on the upload URL: `https://photos.example.com/upload/healthcheck` or Open `/healthcheck` on the upload URL: `https://photos.example.com/upload/healthcheck` or
`https://upload.example.com/healthcheck`. It answers `ok` when the upload service can reach Immich, and a 503 when `https://upload.example.com/healthcheck`. It answers `upload-ok` when the upload service can reach Immich, and a
it cannot. With the upload service on a path on the IPP hostname, IPP shows the **Add photos** button only while 503 when it cannot. With the upload service on a path on the IPP hostname, IPP shows the **Add photos** button only
this answers `ok`. With its own hostname, IPP shows the button whenever `uploadUrl` is set. while this answers `upload-ok`. With its own hostname, IPP shows the button whenever `uploadUrl` is set.
A plain `ok` at `https://upload.example.com/healthcheck` means the hostname reached IPP, not the upload
service: IPP answers `ok` on its own `/healthcheck`. Point the upload hostname at the upload container's port.
An empty page at `https://photos.example.com/upload/healthcheck` means the request reached IPP, not the upload An empty page at `https://photos.example.com/upload/healthcheck` means the request reached IPP, not the upload
service: IPP answers its own hostname's `/upload/healthcheck` with nothing when the route is missing. Check the service: IPP answers its own hostname's `/upload/healthcheck` with nothing when the route is missing. Check the
+13 -6
View File
@@ -37,15 +37,22 @@ export function abortOnClose (res: Response): AbortSignal {
return controller.signal return controller.signal
} }
/** `GET /healthcheck`: `ok` while Immich answers, else 503. */ /**
export async function healthcheck (_req: Request, res: Response): Promise<void> { * A `GET /healthcheck` handler: `body` while Immich answers, else 503.
if (await accessible()) { */
res.send('ok') export function healthcheckHandler (body: string) {
} else { return async (_req: Request, res: Response): Promise<void> => {
res.status(503).send() if (await accessible()) {
res.send(body)
} else {
res.status(503).send()
}
} }
} }
/** IPP's `GET /healthcheck`: `ok` while Immich answers, else 503. */
export const healthcheck = healthcheckHandler('ok')
/** /**
* Wrap an async route handler so a rejected promise is passed to Express's * Wrap an async route handler so a rejected promise is passed to Express's
* error chain (and on to `errorHandler`). * error chain (and on to `errorHandler`).
+45
View File
@@ -0,0 +1,45 @@
import { describe, it, expect, vi, afterEach } from 'vitest'
import { healthcheck, healthcheckHandler } from '../src/http'
import * as client from '../src/immich/client'
/*
Each service answers its healthcheck with its own word: IPP says `ok` and
the upload service says `upload-ok`. An upload hostname that a reverse proxy
points at IPP's port by mistake then reads `ok`, not `upload-ok`, instead of
passing for a working upload service (GitHub #300).
*/
function response () {
const res = { body: undefined as string | undefined, code: 200 }
return Object.assign(res, {
send (body?: string) { res.body = body; return res },
status (code: number) { res.code = code; return res }
})
}
afterEach(() => vi.restoreAllMocks())
describe('healthcheckHandler', () => {
it('answers with the given word while Immich is reachable', async () => {
vi.spyOn(client, 'accessible').mockResolvedValue(true)
const res = response()
await healthcheckHandler('upload-ok')({} as never, res as never)
expect(res.code).toBe(200)
expect(res.body).toBe('upload-ok')
})
it('answers 503 with no body when Immich is not reachable', async () => {
vi.spyOn(client, 'accessible').mockResolvedValue(false)
const res = response()
await healthcheckHandler('upload-ok')({} as never, res as never)
expect(res.code).toBe(503)
expect(res.body).toBeUndefined()
})
it("is IPP's own healthcheck with `ok`", async () => {
vi.spyOn(client, 'accessible').mockResolvedValue(true)
const res = response()
await healthcheck({} as never, res as never)
expect(res.body).toBe('ok')
})
})
+4 -2
View File
@@ -14,7 +14,7 @@ import {
enforceMinimumImmichVersion, enforceMinimumImmichVersion,
errorHandler, errorHandler,
getKeyTypeFromShare, getKeyTypeFromShare,
healthcheck, healthcheckHandler,
invalidPasswordResponse, invalidPasswordResponse,
isKey, isKey,
KeyType, KeyType,
@@ -75,8 +75,10 @@ function bodyDeadline (ms: number): RequestHandler {
/* /*
[ROUTE] Healthcheck, reachable at the root whatever the mount prefix, so one [ROUTE] Healthcheck, reachable at the root whatever the mount prefix, so one
compose healthcheck fits both routing shapes. compose healthcheck fits both routing shapes. It answers `upload-ok` where
IPP answers `ok`, so the owner can tell which service a route reached.
*/ */
const healthcheck = healthcheckHandler('upload-ok')
app.get(['/healthcheck', '/share/healthcheck'], (_req, res, next) => { app.get(['/healthcheck', '/share/healthcheck'], (_req, res, next) => {
addNoStoreHeaders(res) addNoStoreHeaders(res)
next() next()