#267 Add minimum Immich version to prevent this issue
This commit is contained in:
+49
-5
@@ -3,6 +3,7 @@ import {
|
||||
Asset,
|
||||
AssetType,
|
||||
ImageSize,
|
||||
ImmichVersion,
|
||||
IncomingShareRequest,
|
||||
KeyType,
|
||||
SharedLink,
|
||||
@@ -287,11 +288,7 @@ async function fetchShareByKey (key: string, password?: string, keyType: KeyType
|
||||
log('Expired link ' + key)
|
||||
} else {
|
||||
if (!Array.isArray(link.assets)) {
|
||||
// Immich can return a shared link with no `assets` array (seen on
|
||||
// 3.0.x INDIVIDUAL shares - see #267). The album path above always
|
||||
// populates `link.assets`, so this only bites non-album shares.
|
||||
// Treat a missing array as empty rather than letting `.filter` of
|
||||
// undefined reject and take the whole process down.
|
||||
// Defensive guard: the returned album should always(?) populate this array
|
||||
log('Shared link ' + key + ' returned no assets array (type ' + link.type + ')')
|
||||
link.assets = []
|
||||
}
|
||||
@@ -589,6 +586,53 @@ export async function accessible () {
|
||||
return !!(await request('/server/ping'))
|
||||
}
|
||||
|
||||
// Minimum Immich server version IPP is compatible with
|
||||
export const MIN_IMMICH_VERSION: ImmichVersion = { major: 2, minor: 0, patch: 0 }
|
||||
|
||||
const formatVersion = (v: ImmichVersion) => `${v.major}.${v.minor}.${v.patch}`
|
||||
|
||||
/**
|
||||
* Fetch the Immich server version from the public `/server/version` endpoint
|
||||
* (no auth required). Returns null if Immich is unreachable or the response
|
||||
* isn't the expected `{ major, minor, patch }` shape.
|
||||
*/
|
||||
export async function getImmichVersion (): Promise<ImmichVersion | null> {
|
||||
const res = await request('/server/version')
|
||||
if (res && typeof res.major === 'number' && typeof res.minor === 'number' && typeof res.patch === 'number') {
|
||||
return { major: res.major, minor: res.minor, patch: res.patch }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* True if `version` is at least MIN_IMMICH_VERSION. A prerelease of the
|
||||
* minimum version (e.g. 3.0.0-beta) counts as supported.
|
||||
*/
|
||||
export function isImmichVersionSupported (version: ImmichVersion): boolean {
|
||||
if (version.major !== MIN_IMMICH_VERSION.major) return version.major > MIN_IMMICH_VERSION.major
|
||||
if (version.minor !== MIN_IMMICH_VERSION.minor) return version.minor > MIN_IMMICH_VERSION.minor
|
||||
return version.patch >= MIN_IMMICH_VERSION.patch
|
||||
}
|
||||
|
||||
/**
|
||||
* Startup guard. If we can positively confirm the Immich server is older than
|
||||
* IPP supports, log and exit rather than silently serving broken album shares.
|
||||
* If the version can't be determined (Immich not yet reachable at boot, or an
|
||||
* unexpected response), log a warning and continue - a transient blip must not
|
||||
* crash-loop the container, and per-request handling still copes.
|
||||
*/
|
||||
export async function enforceMinimumImmichVersion (): Promise<void> {
|
||||
const version = await getImmichVersion()
|
||||
if (!version) {
|
||||
log('Could not determine the Immich server version. Check that Immich is reachable and running ' + formatVersion(MIN_IMMICH_VERSION) + ' or newer.')
|
||||
return
|
||||
}
|
||||
if (!isImmichVersionSupported(version)) {
|
||||
console.error(dayjs().format() + ' FATAL: Immich server is version ' + formatVersion(version) + ', but IPP requires Immich ' + formatVersion(MIN_IMMICH_VERSION) + ' or newer.')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce an unknown `size` parameter from a URL into a valid ImageSize,
|
||||
* defaulting to preview when the input is missing or unrecognised.
|
||||
|
||||
@@ -5,6 +5,7 @@ import express from 'express'
|
||||
import cookieSession from 'cookie-session'
|
||||
import {
|
||||
accessible,
|
||||
enforceMinimumImmichVersion,
|
||||
fetchAssetDetail,
|
||||
getKeyTypeFromShare,
|
||||
getShareByKey,
|
||||
@@ -348,6 +349,10 @@ process.on('SIGTERM', () => {
|
||||
const port = Number(process.env.IPP_PORT) || 3000
|
||||
const server = app.listen(port, () => {
|
||||
console.log(dayjs().format() + ' Server started on port ' + port)
|
||||
// Bail out early if the Immich server is older than IPP supports, rather
|
||||
// than silently serving broken album shares. Unknown/unreachable is
|
||||
// tolerated (logs a warning and continues) - see enforceMinimumImmichVersion.
|
||||
enforceMinimumImmichVersion().catch(e => console.error('Immich version check failed:', e))
|
||||
// Clean up any zip-download staging dirs left behind by a previous
|
||||
// run that crashed before its finally block could run
|
||||
sweepStaleStagingDirs().catch(e => console.error('sweepStaleStagingDirs failed:', e))
|
||||
|
||||
@@ -62,6 +62,15 @@ export interface Asset {
|
||||
needsDetail?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Immich server version as returned by `GET /server/version`.
|
||||
*/
|
||||
export interface ImmichVersion {
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* One entry of `GET /timeline/buckets` - a time bucket (month) and its count.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user