#244 Reverse metadata field defaults

This commit is contained in:
Alan Grainger
2026-06-05 10:50:16 +12:00
parent 2390d0eb74
commit 7799fa71c9
11 changed files with 246 additions and 107 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ app/
text.ts escapeHtml + toString narrowing text.ts escapeHtml + toString narrowing
view/ Preact SSR templates (.tsx) view/ Preact SSR templates (.tsx)
shared/types.ts Types shared between server SSR and client (GalleryItem, etc.) shared/types.ts Types shared between server SSR and client (GalleryItem, etc.)
client/ Client gallery, virtualization, lightbox, sidebar client/ Client gallery, virtualisation, lightbox, sidebar
public/ Static assets served as-is public/ Static assets served as-is
photoswipe/ Vendored PhotoSwipe v5 photoswipe/ Vendored PhotoSwipe v5
thumbhash/, fonts/, images/ thumbhash/, fonts/, images/
+1 -1
View File
@@ -84,7 +84,7 @@ Check the container console output for any error messages.
docker-compose up -d docker-compose up -d
``` ```
6. Set the "External domain" in your Immich **Server Settings** to be whatever domain you use to publicly serve Immich Public Proxy: 5. Set the "External domain" in your Immich **Server Settings** to be whatever domain you use to publicly serve Immich Public Proxy:
<img src="docs/server-settings.png" width="400" height="182"> <img src="docs/server-settings.png" width="400" height="182">
+18 -19
View File
@@ -5,7 +5,7 @@
"Access-Control-Allow-Origin": "*" "Access-Control-Allow-Origin": "*"
}, },
"downloadOriginalPhoto": true, "downloadOriginalPhoto": true,
"downloadedFilename": 2, "downloadedFilename": 0,
"allowDownloadAll": 0, "allowDownloadAll": 0,
"downloadFromImmichConcurrencyLimit": 20, "downloadFromImmichConcurrencyLimit": 20,
"allowSlugLinks": true, "allowSlugLinks": true,
@@ -16,26 +16,25 @@
"sidebar": false "sidebar": false
}, },
"exif": { "exif": {
"enabled": false, "enableAll": false,
"dateTimeOriginal": true, "dateTimeOriginal": false,
"fileName": true, "fileName": false,
"dimensions": true, "dimensions": false,
"fileSize": true, "fileSize": false,
"make": true, "make": false,
"model": true, "model": false,
"lensModel": true, "lensModel": false,
"exposureTime": true, "exposureTime": false,
"iso": true, "iso": false,
"fNumber": true, "fNumber": false,
"focalLength": true "focalLength": false
}, },
"location": { "location": {
"enabled": false, "enableAll": false,
"city": true, "city": false,
"state": true, "state": false,
"country": true, "country": false,
"gps": true, "gps": false
"webLink": true
} }
}, },
"customInvalidResponse": false, "customInvalidResponse": false,
+1 -1
View File
@@ -11,7 +11,7 @@ import type { InitParams } from '../shared/types.js'
import { state } from './state.js' import { state } from './state.js'
import { setupToolbar } from './selection.js' import { setupToolbar } from './selection.js'
import { initLightbox, openLightbox } from './lightbox.js' import { initLightbox, openLightbox } from './lightbox.js'
import { computeLayoutAndRender, onScroll } from './virtualization.js' import { computeLayoutAndRender, onScroll } from './virtualisation.js'
function readInitParams (): InitParams { function readInitParams (): InitParams {
const el = document.getElementById('ipp-init') const el = document.getElementById('ipp-init')
+2 -2
View File
@@ -1,6 +1,6 @@
// Justified-rows + square-grid layout, with optional month grouping. Pure // Justified-rows + square-grid layout, with optional month grouping. Pure
// geometry: takes a container width, returns positions for every tile and // geometry: takes a container width, returns positions for every tile and
// every header. Called by virtualization on first render and on resize. // every header. Called by virtualisation on first render and on resize.
import { import {
state, state,
@@ -26,7 +26,7 @@ export interface LayoutResult {
* for the gallery at the given container width. * for the gallery at the given container width.
* *
* Reads `state.items` and `state.groupByDate`. Output is pure data - the * Reads `state.items` and `state.groupByDate`. Output is pure data - the
* caller (virtualization) is responsible for actually placing DOM nodes * caller (virtualisation) is responsible for actually placing DOM nodes
* according to the returned positions. * according to the returned positions.
* *
* Switches between a mobile square grid (under MOBILE_BREAKPOINT) and the * Switches between a mobile square grid (under MOBILE_BREAKPOINT) and the
+1 -1
View File
@@ -15,7 +15,7 @@ function onThumbError (this: HTMLImageElement) {
} }
// Cache of decoded thumbhash → PNG data URL. Same thumbhash on multiple // Cache of decoded thumbhash → PNG data URL. Same thumbhash on multiple
// tile-creations (revisits during virtualization) reuses the same URL. // tile-creations (revisits during virtualisation) reuses the same URL.
const thumbhashCache = new Map<string, string | null>() const thumbhashCache = new Map<string, string | null>()
function decodeThumbhash (base64: string): string | null { function decodeThumbhash (base64: string): string | null {
+100 -22
View File
@@ -1,28 +1,46 @@
// Backward-compatability shims that map legacy `config.json` key shapes /*
// onto their current locations. Each one only fills in values the user Backward-compatibility shims that map legacy `config.json` key shapes
// hasn't explicitly set on the new path, and prints a one-time deprecation onto their current locations. Each shim mutates the in-memory config
// warning to the startup log. only - the on-disk file is never touched, so read-only mounts are safe.
//
// Delete in v3.0. CONVENTION for keeping this file pruneable:
1. Every shim function starts its JSDoc with a `SHIM:` marker line.
To list all current shims: grep -rn 'SHIM:' app/src
2. Every shim is registered in `SHIMS` below with the version it
should be deleted in. When that version comes up, remove the
function, its registry entry, and any tests for it.
3. Each shim should be self-contained and side-effect-free beyond
mutating the passed-in config. No imports from app code.
*/
type Config = Record<string, unknown> type Config = Record<string, unknown>
interface Shim {
name: string
removeIn: string
apply: (config: Config) => void
}
const SHIMS: Shim[] = [
{ name: 'lightGallery', removeIn: 'v3.0', apply: applyLightGalleryShim },
{ name: 'topLevelGallery', removeIn: 'v3.0', apply: applyTopLevelGalleryShim },
{ name: 'descriptionSplit', removeIn: 'v3.0', apply: applyDescriptionSplitShim },
{ name: 'enableAll', removeIn: 'v3.0', apply: applyEnableAllShim }
]
/** /**
* Apply every supported legacy-config shim to `config` in place. * Apply every registered legacy-config shim to `config` in place.
* Called from `loadConfig()` after reading the file or env JSON. * Called from `loadConfig()` after reading the file or env JSON.
*/ */
export function applyMigrations (config: Config): void { export function applyMigrations (config: Config): void {
applyLightGalleryShim(config) for (const shim of SHIMS) shim.apply(config)
applyTopLevelGalleryShim(config)
applyDescriptionSplitShim(config)
} }
/** /**
* 1.x users with a legacy `lightGallery.*` config section. * SHIM: lightGallery -> ipp.lightbox (1.x users with a legacy
* Maps `lightGallery.controls`, `lightGallery.download`, and * `lightGallery.*` config section). Maps `lightGallery.controls`,
* `lightGallery.mobileSettings.controls` onto `ipp.lightbox.*`. * `lightGallery.download`, and `lightGallery.mobileSettings.controls`
* * onto `ipp.lightbox.*`.
* Delete in v3.0.
*/ */
function applyLightGalleryShim (config: Config): void { function applyLightGalleryShim (config: Config): void {
if (!config.lightGallery || typeof config.lightGallery !== 'object') return if (!config.lightGallery || typeof config.lightGallery !== 'object') return
@@ -49,11 +67,10 @@ function applyLightGalleryShim (config: Config): void {
} }
/** /**
* Gallery-related keys that used to live directly on `ipp` now live under * SHIM: top-level ipp.* gallery keys -> ipp.gallery.*. Gallery-related
* `ipp.gallery`. Maps legacy keys forward, only filling in fields the user * keys that used to live directly on `ipp` now live under `ipp.gallery`.
* hasn't already set on the new path. * Maps legacy keys forward, only filling in fields the user hasn't
* * already set on the new path.
* Delete in v3.0.
*/ */
function applyTopLevelGalleryShim (config: Config): void { function applyTopLevelGalleryShim (config: Config): void {
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown> const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
@@ -82,13 +99,12 @@ function applyTopLevelGalleryShim (config: Config): void {
} }
/** /**
* SHIM: showMetadata.description boolean -> { caption, sidebar } object.
* `ipp.showMetadata.description` used to be a single boolean controlling * `ipp.showMetadata.description` used to be a single boolean controlling
* both the lightbox caption and (later) the sidebar. It is now an object * both the lightbox caption and (later) the sidebar. It is now an object
* with separate `caption` and `sidebar` flags. A legacy boolean value is * with separate `caption` and `sidebar` flags. A legacy boolean value is
* migrated to `{ caption: <bool>, sidebar: <bool> }` so existing configs * migrated to `{ caption: <bool>, sidebar: <bool> }` so existing configs
* continue to render description in both places. * continue to render description in both places.
*
* Delete in v3.0.
*/ */
function applyDescriptionSplitShim (config: Config): void { function applyDescriptionSplitShim (config: Config): void {
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown> const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
@@ -105,3 +121,65 @@ function applyDescriptionSplitShim (config: Config): void {
'independently. See README.' 'independently. See README.'
) )
} }
/**
* SHIM: showMetadata.{exif,location}.enabled -> .enableAll, with per-
* field defaults flipped from `true` to `false`.
*
* New semantics: `enableAll: true` shows every field in the group;
* `enableAll: false` shows only fields with an explicit per-field `true`.
*
* Two compatibility hazards the shim guards against:
* (a) Old shipped `config.json` used `enabled: false` with every
* per-field flag set to `true` as documentation. Under new
* semantics those would become live opt-ins. When the legacy
* `enabled` was `false`, the shim zeroes out per-field flags so
* the runtime keeps the "nothing visible" behaviour the user had.
* (b) `enabled: true` with selective per-field `false` (e.g. to hide
* GPS while showing the rest of location) is no longer expressible
* because `enableAll: true` overrides per-field flags. The shim
* can't preserve that without enumerating every other field; we
* just log a warning telling the user to rewrite as explicit
* opt-ins.
*/
function applyEnableAllShim (config: Config): void {
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
const showMetadata = ipp.showMetadata as Record<string, unknown> | undefined
if (!showMetadata) return
let migrated = false
for (const groupName of ['exif', 'location']) {
const group = showMetadata[groupName] as Record<string, unknown> | undefined
if (!group || typeof group !== 'object') continue
if (group.enabled === undefined) continue
const legacyEnabled = !!group.enabled
if (group.enableAll === undefined) {
group.enableAll = legacyEnabled
}
delete group.enabled
// Hazard (a): zero out per-field flags when the legacy master was
// off. Under the old semantic those flags were dead code, so wiping
// them is a no-op behaviour-wise but stops the new semantic from
// treating them as live opt-ins.
if (!legacyEnabled) {
for (const key of Object.keys(group)) {
if (key === 'enableAll') continue
if (typeof group[key] === 'boolean') group[key] = false
}
}
migrated = true
}
if (migrated) {
console.log(
'[IPP] `ipp.showMetadata.exif.enabled` / `.location.enabled` are ' +
'deprecated; renamed to `enableAll`. Per-field defaults are now ' +
'`false` and `enableAll: true` overrides them, so any per-field ' +
'`false` that used to subtract from an all-on group is now ignored. ' +
'See README to rewrite "show all except X" as explicit opt-ins.'
)
}
}
+3 -7
View File
@@ -14,7 +14,7 @@ import { h } from 'preact'
import { renderPage } from '../view/render' import { renderPage } from '../view/render'
import { Gallery, GalleryItem, GalleryProps } from '../view/gallery' import { Gallery, GalleryItem, GalleryProps } from '../view/gallery'
import { getFilename } from './filename' import { getFilename } from './filename'
import { pickExif } from './exif' import { metadataGroupActive, pickExif } from './exif'
/** /**
* Render a gallery page for a given SharedLink. * Render a gallery page for a given SharedLink.
@@ -39,10 +39,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
// `metadataConfig` in the init JSON. // `metadataConfig` in the init JSON.
const descriptionInCaption = !!getConfigOption('ipp.showMetadata.description.caption', false) const descriptionInCaption = !!getConfigOption('ipp.showMetadata.description.caption', false)
const descriptionInSidebar = !!getConfigOption('ipp.showMetadata.description.sidebar', false) const descriptionInSidebar = !!getConfigOption('ipp.showMetadata.description.sidebar', false)
const exifGroupEnabled = !!getConfigOption('ipp.showMetadata.exif.enabled', false) const sidebarHasContent = descriptionInSidebar || metadataGroupActive('exif') || metadataGroupActive('location')
const locationGroupEnabled = !!getConfigOption('ipp.showMetadata.location.enabled', false)
const locationWebLink = locationGroupEnabled && !!getConfigOption('ipp.showMetadata.location.webLink', true)
const sidebarHasContent = descriptionInSidebar || exifGroupEnabled || locationGroupEnabled
// Build structured items in parallel // Build structured items in parallel
const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => { const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
@@ -135,8 +132,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
metadataConfig: { metadataConfig: {
descriptionInCaption, descriptionInCaption,
descriptionInSidebar, descriptionInSidebar,
sidebarHasContent, sidebarHasContent
locationWebLink
}, },
groupByDate groupByDate
} }
+113 -47
View File
@@ -1,16 +1,97 @@
import { Asset } from '../types' import { Asset, ExifInfo } from '../types'
import { GalleryExif } from '../shared/types' import { GalleryExif } from '../shared/types'
import { getConfigOption } from '../config/access' import { getConfigOption } from '../config/access'
type Group = 'exif' | 'location'
interface FieldRule {
// Config flag name, relative to the group (e.g. 'gps' -> ipp.showMetadata.location.gps)
flag: string
// Copies values from the Immich-side ExifInfo (+ asset for fileName) onto
// the gallery-side GalleryExif if they're present and non-empty.
emit: (out: GalleryExif, info: ExifInfo, asset: Asset) => void
}
/**
* Trivial copy: `out[key] = info[key]` when present. Used for fields where
* the config flag, source key, and output key all match.
*/
function copy (key: keyof ExifInfo & keyof GalleryExif): FieldRule {
return {
flag: key,
emit: (out, info) => {
const value = info[key]
if (value != null && value !== '') (out as Record<string, unknown>)[key] = value
}
}
}
/*
Fields whose config flag, ExifInfo key, and GalleryExif key are all the
same string. `copy` handles the whole if/copy dance for each. Fields
that need special handling (fileName, dimensions, fileSize, gps) appear
inline in the `*_RULES` arrays below.
*/
const EXIF_FIELDS = [
'dateTimeOriginal', 'make', 'model', 'lensModel',
'exposureTime', 'iso', 'fNumber', 'focalLength'
] as const
const LOCATION_FIELDS = ['city', 'state', 'country'] as const
const EXIF_RULES: FieldRule[] = [
...EXIF_FIELDS.map(copy),
{
flag: 'fileName',
emit: (out, _info, asset) => {
if (asset.originalFileName) out.fileName = asset.originalFileName
}
},
{
flag: 'dimensions',
emit: (out, info) => {
if (info.exifImageWidth && info.exifImageHeight) {
out.width = info.exifImageWidth
out.height = info.exifImageHeight
}
}
},
{
flag: 'fileSize',
emit: (out, info) => {
if (info.fileSizeInByte) out.fileSizeInByte = info.fileSizeInByte
}
}
]
const LOCATION_RULES: FieldRule[] = [
...LOCATION_FIELDS.map(copy),
{
flag: 'gps',
emit: (out, info) => {
if (info.latitude != null && info.longitude != null) {
out.latitude = info.latitude
out.longitude = info.longitude
}
}
}
]
const RULES: Record<Group, FieldRule[]> = {
exif: EXIF_RULES,
location: LOCATION_RULES
}
/** /**
* Build the per-asset metadata sub-object included in the gallery JSON. * Build the per-asset metadata sub-object included in the gallery JSON.
* Reads `ipp.showMetadata.exif.*` and `ipp.showMetadata.location.*` config: * Reads `ipp.showMetadata.exif.*` and `ipp.showMetadata.location.*` config:
* each group has a master `enabled` toggle, and within each group the * each group has a master `enableAll` toggle and a set of per-field flags
* per-field flags default to `true`. A field appears in the output only * that all default to `false`. A field appears in the output when either
* when both the group is enabled AND the field's own flag is true. * the group's `enableAll` is true, OR the field's own flag is true.
* *
* Returns `undefined` when neither group is enabled, or when no fields * Returns `undefined` when neither group has any visible content, or when
* survive gating (so the client knows there's no metadata to show). * no fields survive gating (so the client knows there's no metadata to
* show).
* *
* The server never sends Immich values that the operator hasn't opted in * The server never sends Immich values that the operator hasn't opted in
* to via config; the client just renders what's present. * to via config; the client just renders what's present.
@@ -19,52 +100,37 @@ export function pickExif (asset: Asset): GalleryExif | undefined {
const exifInfo = asset?.exifInfo const exifInfo = asset?.exifInfo
if (!exifInfo) return undefined if (!exifInfo) return undefined
const exifEnabled = !!getConfigOption('ipp.showMetadata.exif.enabled', false) const exifActive = metadataGroupActive('exif')
const locationEnabled = !!getConfigOption('ipp.showMetadata.location.enabled', false) const locationActive = metadataGroupActive('location')
if (!exifEnabled && !locationEnabled) return undefined if (!exifActive && !locationActive) return undefined
const out: GalleryExif = {} const out: GalleryExif = {}
if (exifActive) applyRules('exif', out, exifInfo, asset)
if (exifEnabled) { if (locationActive) applyRules('location', out, exifInfo, asset)
if (allow('exif.dateTimeOriginal') && exifInfo.dateTimeOriginal) {
out.dateTimeOriginal = exifInfo.dateTimeOriginal
}
if (allow('exif.fileName') && asset.originalFileName) {
out.fileName = asset.originalFileName
}
if (allow('exif.dimensions') && exifInfo.exifImageWidth && exifInfo.exifImageHeight) {
out.width = exifInfo.exifImageWidth
out.height = exifInfo.exifImageHeight
}
if (allow('exif.fileSize') && exifInfo.fileSizeInByte) {
out.fileSizeInByte = exifInfo.fileSizeInByte
}
if (allow('exif.make') && exifInfo.make) out.make = exifInfo.make
if (allow('exif.model') && exifInfo.model) out.model = exifInfo.model
if (allow('exif.lensModel') && exifInfo.lensModel) out.lensModel = exifInfo.lensModel
if (allow('exif.exposureTime') && exifInfo.exposureTime) out.exposureTime = exifInfo.exposureTime
if (allow('exif.iso') && exifInfo.iso) out.iso = exifInfo.iso
if (allow('exif.fNumber') && exifInfo.fNumber) out.fNumber = exifInfo.fNumber
if (allow('exif.focalLength') && exifInfo.focalLength) out.focalLength = exifInfo.focalLength
}
if (locationEnabled) {
if (allow('location.city') && exifInfo.city) out.city = exifInfo.city
if (allow('location.state') && exifInfo.state) out.state = exifInfo.state
if (allow('location.country') && exifInfo.country) out.country = exifInfo.country
if (allow('location.gps') && exifInfo.latitude != null && exifInfo.longitude != null) {
out.latitude = exifInfo.latitude
out.longitude = exifInfo.longitude
}
}
return Object.keys(out).length ? out : undefined return Object.keys(out).length ? out : undefined
} }
/** /**
* Per-field gate. Defaults to `true` so that turning on a group exposes * Returns true if a metadata group would render any field for the current
* every field unless the operator explicitly opts out of one. * config - either `enableAll` is set, or at least one per-field flag is
* explicitly `true`. Used by the sidebar visibility check.
*/ */
function allow (field: string): boolean { export function metadataGroupActive (group: Group): boolean {
return !!getConfigOption(`ipp.showMetadata.${field}`, true) if (groupEnableAll(group)) return true
return RULES[group].some(rule => fieldFlag(group, rule.flag))
}
function applyRules (group: Group, out: GalleryExif, info: ExifInfo, asset: Asset): void {
const enableAll = groupEnableAll(group)
for (const rule of RULES[group]) {
if (enableAll || fieldFlag(group, rule.flag)) rule.emit(out, info, asset)
}
}
function groupEnableAll (group: Group): boolean {
return !!getConfigOption(`ipp.showMetadata.${group}.enableAll`, false)
}
function fieldFlag (group: Group, flag: string): boolean {
return !!getConfigOption(`ipp.showMetadata.${group}.${flag}`, false)
} }
+5 -5
View File
@@ -6,10 +6,10 @@
/** /**
* Per-asset EXIF / location metadata shown in the info sidebar. Each field * Per-asset EXIF / location metadata shown in the info sidebar. Each field
* is optional - the server only includes a field if both the group is * is optional - the server only includes a field when either the group's
* enabled (`ipp.showMetadata.exif.enabled` or `.location.enabled`) and the * `enableAll` is true (`ipp.showMetadata.exif.enableAll` /
* per-field flag is true. Strings are plain text (the client uses * `.location.enableAll`) or the field's own per-field flag is true.
* `textContent`, not `innerHTML`). * Strings are plain text (the client uses `textContent`, not `innerHTML`).
*/ */
export interface GalleryExif { export interface GalleryExif {
dateTimeOriginal?: string // ISO date string; client formats with Intl.DateTimeFormat dateTimeOriginal?: string // ISO date string; client formats with Intl.DateTimeFormat
@@ -45,7 +45,7 @@ export interface GalleryItem {
description?: string description?: string
downloadFilename: string downloadFilename: string
// Display dimensions after EXIF orientation correction; needed for the // Display dimensions after EXIF orientation correction; needed for the
// pre-computed justified-rows layout that virtualization depends on. // pre-computed justified-rows layout that virtualisation depends on.
width?: number width?: number
height?: number height?: number
// Base64-encoded thumbhash for an optional blur placeholder behind each tile // Base64-encoded thumbhash for an optional blur placeholder behind each tile
+1 -1
View File
@@ -83,7 +83,7 @@ export function Gallery (props: GalleryProps) {
{props.description && ( {props.description && (
<p id="album-description">{props.description}</p> <p id="album-description">{props.description}</p>
)} )}
{/* Container is intentionally empty - web.js's virtualization manager {/* Container is intentionally empty - web.js's virtualisation manager
populates it with only the tiles within the viewport buffer. */} populates it with only the tiles within the viewport buffer. */}
<div id="gallery"></div> <div id="gallery"></div>
{props.showDownload && ( {props.showDownload && (