#244 Reverse metadata field defaults

This commit is contained in:
Alan Grainger
2026-06-05 11:39:26 +12:00
parent 0a9b20f0a1
commit 0a1f050ab0
5 changed files with 82 additions and 65 deletions
-2
View File
@@ -16,7 +16,6 @@
"sidebar": false "sidebar": false
}, },
"exif": { "exif": {
"enableAll": false,
"dateTimeOriginal": false, "dateTimeOriginal": false,
"fileName": false, "fileName": false,
"dimensions": false, "dimensions": false,
@@ -30,7 +29,6 @@
"focalLength": false "focalLength": false
}, },
"location": { "location": {
"enableAll": false,
"city": false, "city": false,
"state": false, "state": false,
"country": false, "country": false,
+46 -34
View File
@@ -25,7 +25,7 @@ const SHIMS: Shim[] = [
{ name: 'lightGallery', removeIn: 'v3.0', apply: applyLightGalleryShim }, { name: 'lightGallery', removeIn: 'v3.0', apply: applyLightGalleryShim },
{ name: 'topLevelGallery', removeIn: 'v3.0', apply: applyTopLevelGalleryShim }, { name: 'topLevelGallery', removeIn: 'v3.0', apply: applyTopLevelGalleryShim },
{ name: 'descriptionSplit', removeIn: 'v3.0', apply: applyDescriptionSplitShim }, { name: 'descriptionSplit', removeIn: 'v3.0', apply: applyDescriptionSplitShim },
{ name: 'enableAll', removeIn: 'v3.0', apply: applyEnableAllShim } { name: 'metadataEnabled', removeIn: 'v3.0', apply: applyMetadataEnabledShim }
] ]
/** /**
@@ -123,50 +123,62 @@ function applyDescriptionSplitShim (config: Config): void {
} }
/** /**
* SHIM: showMetadata.{exif,location}.enabled -> .enableAll, with per- * SHIM: showMetadata.{exif,location}.enabled removed. Per-field flags are
* field defaults flipped from `true` to `false`. * now the only gate, and they all default to `false`.
* *
* New semantics: `enableAll: true` shows every field in the group; * The 2.3.0 shipped `config.json` had `enabled: false` plus every per-
* `enableAll: false` shows only fields with an explicit per-field `true`. * field flag set to `true` as documentation. Without this shim those
* `true`s would become live opt-ins on upgrade, silently exposing GPS
* coordinates and EXIF data on share pages. The shim rewrites legacy
* configs in memory at startup:
* *
* Two compatibility hazards the shim guards against: * - `enabled: true`: for each known field in the group, if the per-
* (a) Old shipped `config.json` used `enabled: false` with every * field flag is `undefined`, set it to `true` (the old default).
* per-field flag set to `true` as documentation. Under new * Explicit `false` per-field flags are kept, so "all except X"
* semantics those would become live opt-ins. When the legacy * patterns continue to work.
* `enabled` was `false`, the shim zeroes out per-field flags so * - `enabled: false`: clear any per-field flag that is `true`. Under
* the runtime keeps the "nothing visible" behaviour the user had. * the old semantic those flags were dead code (the master switch
* (b) `enabled: true` with selective per-field `false` (e.g. to hide * hid them), so wiping them preserves the "nothing visible"
* GPS while showing the rest of location) is no longer expressible * behaviour the user had.
* because `enableAll: true` overrides per-field flags. The shim *
* can't preserve that without enumerating every other field; we * The field lists below are frozen at v2.x. If new fields are added in
* just log a warning telling the user to rewrite as explicit * future versions, they will not auto-appear for legacy `enabled: true`
* opt-ins. * users - which is the safer privacy default and matches the policy the
* new design is establishing.
*/ */
function applyEnableAllShim (config: Config): void { const LEGACY_EXIF_FIELDS = [
'dateTimeOriginal', 'fileName', 'dimensions', 'fileSize',
'make', 'model', 'lensModel', 'exposureTime', 'iso',
'fNumber', 'focalLength'
]
const LEGACY_LOCATION_FIELDS = ['city', 'state', 'country', 'gps']
function applyMetadataEnabledShim (config: Config): void {
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown> const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
const showMetadata = ipp.showMetadata as Record<string, unknown> | undefined const showMetadata = ipp.showMetadata as Record<string, unknown> | undefined
if (!showMetadata) return if (!showMetadata) return
let migrated = false let migrated = false
for (const groupName of ['exif', 'location']) { const groups: Array<[string, string[]]> = [
['exif', LEGACY_EXIF_FIELDS],
['location', LEGACY_LOCATION_FIELDS]
]
for (const [groupName, fields] of groups) {
const group = showMetadata[groupName] as Record<string, unknown> | undefined const group = showMetadata[groupName] as Record<string, unknown> | undefined
if (!group || typeof group !== 'object') continue if (!group || typeof group !== 'object') continue
if (group.enabled === undefined) continue if (group.enabled === undefined) continue
const legacyEnabled = !!group.enabled const legacyEnabled = !!group.enabled
if (group.enableAll === undefined) {
group.enableAll = legacyEnabled
}
delete group.enabled delete group.enabled
// Hazard (a): zero out per-field flags when the legacy master was if (legacyEnabled) {
// off. Under the old semantic those flags were dead code, so wiping for (const field of fields) {
// them is a no-op behaviour-wise but stops the new semantic from if (group[field] === undefined) group[field] = true
// treating them as live opt-ins. }
if (!legacyEnabled) { } else {
for (const key of Object.keys(group)) { for (const field of fields) {
if (key === 'enableAll') continue if (group[field] === true) group[field] = false
if (typeof group[key] === 'boolean') group[key] = false
} }
} }
@@ -176,10 +188,10 @@ function applyEnableAllShim (config: Config): void {
if (migrated) { if (migrated) {
console.log( console.log(
'[IPP] `ipp.showMetadata.exif.enabled` / `.location.enabled` are ' + '[IPP] `ipp.showMetadata.exif.enabled` / `.location.enabled` are ' +
'deprecated; renamed to `enableAll`. Per-field defaults are now ' + 'deprecated and have been removed. Per-field flags are now the ' +
'`false` and `enableAll: true` overrides them, so any per-field ' + 'only gate (all default `false`). Your legacy config has been ' +
'`false` that used to subtract from an all-on group is now ignored. ' + 'rewritten in memory to preserve current behaviour; please update ' +
'See README to rewrite "show all except X" as explicit opt-ins.' 'your `config.json` to the explicit per-field form. See README.'
) )
} }
} }
+2 -1
View File
@@ -132,7 +132,8 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
metadataConfig: { metadataConfig: {
descriptionInCaption, descriptionInCaption,
descriptionInSidebar, descriptionInSidebar,
sidebarHasContent sidebarHasContent,
locationWebLink: !!getConfigOption('ipp.showMetadata.location.webLink', true)
}, },
groupByDate groupByDate
} }
+8 -16
View File
@@ -85,13 +85,11 @@ const RULES: Record<Group, FieldRule[]> = {
/** /**
* 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 `enableAll` toggle and a set of per-field flags * every field is an explicit per-field opt-in (all default `false`), so
* that all default to `false`. A field appears in the output when either * nothing is sent unless the operator has explicitly turned on the flag.
* the group's `enableAll` is true, OR the field's own flag is true.
* *
* Returns `undefined` when neither group has any visible content, or when * Returns `undefined` when no fields survive gating (so the client knows
* no fields survive gating (so the client knows there's no metadata to * there's no metadata to show).
* 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.
@@ -111,26 +109,20 @@ export function pickExif (asset: Asset): GalleryExif | undefined {
} }
/** /**
* Returns true if a metadata group would render any field for the current * Returns true if a metadata group has at least one per-field flag
* config - either `enableAll` is set, or at least one per-field flag is * explicitly set to `true` in config. Used by the sidebar visibility
* explicitly `true`. Used by the sidebar visibility check. * check.
*/ */
export function metadataGroupActive (group: Group): boolean { export function metadataGroupActive (group: Group): boolean {
if (groupEnableAll(group)) return true
return RULES[group].some(rule => fieldFlag(group, rule.flag)) return RULES[group].some(rule => fieldFlag(group, rule.flag))
} }
function applyRules (group: Group, out: GalleryExif, info: ExifInfo, asset: Asset): void { function applyRules (group: Group, out: GalleryExif, info: ExifInfo, asset: Asset): void {
const enableAll = groupEnableAll(group)
for (const rule of RULES[group]) { for (const rule of RULES[group]) {
if (enableAll || fieldFlag(group, rule.flag)) rule.emit(out, info, asset) if (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 { function fieldFlag (group: Group, flag: string): boolean {
return !!getConfigOption(`ipp.showMetadata.${group}.${flag}`, false) return !!getConfigOption(`ipp.showMetadata.${group}.${flag}`, false)
} }
+25 -11
View File
@@ -37,7 +37,7 @@ For one-off or single-key overrides. See [inline configuration](inline-configura
## How options are organised ## How options are organised
All options live under `ipp.*`. Several groups follow a master-toggle plus per-field-overrides pattern (`ipp.showMetadata.exif`, `ipp.showMetadata.location`): set the group's `enabled: true` to expose the group, then turn individual fields off if you want fewer. All options live under `ipp.*`. The metadata groups (`ipp.showMetadata.exif`, `ipp.showMetadata.location`) are per-field opt-in: every field is off until you explicitly set its flag to `true`. Nothing is automatically exposed - including fields IPP adds in future versions.
You only need to include the keys you're changing. Anything you omit keeps its default. You only need to include the keys you're changing. Anything you omit keeps its default.
@@ -124,14 +124,14 @@ Configured under `ipp.showMetadata`. The lightbox includes a slide-in info sideb
| Option | Type | Description | | Option | Type | Description |
|---------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------| |---------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `description` | `object` | Where to show the description. `{ "caption": bool, "sidebar": bool }`. Both default `false`. See [Description](#description). | | `description` | `object` | Where to show the description. `{ "caption": bool, "sidebar": bool }`. Both default `false`. See [Description](#description). |
| `exif` | `object` | Camera / file EXIF group. Set `enabled: true` to expose any of the per-field flags below. See [EXIF group](#exif-group). | | `exif` | `object` | Camera / file EXIF group. Per-field opt-in flags, all default `false`. See [EXIF group](#exif-group). |
| `location` | `object` | Location group (city / state / country / GPS). Set `enabled: true` to expose any of the per-field flags below. See [Location group](#location-group). | | `location` | `object` | Location group (city / state / country / GPS). Per-field opt-in flags, all default `false`. See [Location group](#location-group). |
Within each group, the master `enabled` toggle controls whether the group's fields are sent at all. Per-field flags default to `true` once the group is enabled, so you can turn off individual fields without renaming or removing them. Every per-field flag defaults to `false`. A field is sent to the client only when its flag is explicitly `true`. There is no master switch - this is deliberate, so that fields IPP adds in future releases don't auto-expose without your action.
IPP only sends a field if **both** the group's `enabled` is true AND the field's flag is true. If Immich itself isn't exposing metadata for the share (the per-share toggle on the Immich side), no metadata is available regardless of these settings. If Immich itself isn't exposing metadata for the share (the per-share toggle on the Immich side), no metadata is available regardless of these settings.
The info sidebar (and its toolbar toggle button) only appear when there is at least one section the operator has opted into - i.e. `description.sidebar`, `exif.enabled`, or `location.enabled` is true. With all three off, the sidebar UI is suppressed. The info sidebar (and its toolbar toggle button) only appear when there is at least one section the operator has opted into - i.e. `description.sidebar` is true, or `exif` / `location` has at least one flag set to `true`. With all three off, the sidebar UI is suppressed.
### Description ### Description
@@ -150,7 +150,6 @@ Under `ipp.showMetadata.exif`.
| Option | Type | Description | | Option | Type | Description |
|---------------------|--------|--------------------------------------------------------------------------| |---------------------|--------|--------------------------------------------------------------------------|
| `enabled` | `bool` | Master switch for the EXIF group. Default `false`. |
| `dateTimeOriginal` | `bool` | Show the date the photo was taken (per EXIF). | | `dateTimeOriginal` | `bool` | Show the date the photo was taken (per EXIF). |
| `fileName` | `bool` | Show the original filename. | | `fileName` | `bool` | Show the original filename. |
| `dimensions` | `bool` | Show width x height and megapixel count. | | `dimensions` | `bool` | Show width x height and megapixel count. |
@@ -169,22 +168,30 @@ Under `ipp.showMetadata.location`.
| Option | Type | Description | | Option | Type | Description |
|------------|--------|----------------------------------------------------------------------| |------------|--------|----------------------------------------------------------------------|
| `enabled` | `bool` | Master switch for the location group. Default `false`. |
| `city` | `bool` | Show city. | | `city` | `bool` | Show city. |
| `state` | `bool` | Show state / region. | | `state` | `bool` | Show state / region. |
| `country` | `bool` | Show country. | | `country` | `bool` | Show country. |
| `gps` | `bool` | Show GPS coordinates. | | `gps` | `bool` | Show GPS coordinates. |
| `webLink` | `bool` | Show an "Open in OpenStreetMap" link below the coordinates. The link is rendered with `rel="noreferrer"` so the share URL is not leaked to the map provider when a viewer clicks it. Has no effect unless `gps` is also true. Default `true`. | | `webLink` | `bool` | Show an "Open in OpenStreetMap" link below the coordinates. The link is rendered with `rel="noreferrer"` so the share URL is not leaked to the map provider when a viewer clicks it. Has no effect unless `gps` is also true. Default `true`. |
A full example showing the description in the sidebar only (not as a lightbox caption), exposing full EXIF, and revealing place names but not the GPS coordinates: A full example showing the description in the sidebar only (not as a lightbox caption), exposing camera EXIF, and revealing place names but not the GPS coordinates:
```json ```json
{ {
"ipp": { "ipp": {
"showMetadata": { "showMetadata": {
"description": { "caption": false, "sidebar": true }, "description": { "caption": false, "sidebar": true },
"exif": { "enabled": true }, "exif": {
"location": { "enabled": true, "gps": false } "dateTimeOriginal": true,
"make": true,
"model": true,
"lensModel": true,
"exposureTime": true,
"iso": true,
"fNumber": true,
"focalLength": true
},
"location": { "city": true, "state": true, "country": true }
} }
} }
} }
@@ -216,3 +223,10 @@ A few config keys have been renamed across versions. Existing configs continue t
| `ipp.groupGalleryByDate` | `ipp.gallery.groupByDate` | | `ipp.groupGalleryByDate` | `ipp.gallery.groupByDate` |
**`showMetadata.description` is now an object.** It used to be a single boolean. A legacy `description: true` migrates to `{ caption: true, sidebar: true }` (and `false` to both `false`). Move to the explicit form to silence the deprecation notice and so you can target the caption vs. the sidebar independently. **`showMetadata.description` is now an object.** It used to be a single boolean. A legacy `description: true` migrates to `{ caption: true, sidebar: true }` (and `false` to both `false`). Move to the explicit form to silence the deprecation notice and so you can target the caption vs. the sidebar independently.
**`showMetadata.{exif,location}.enabled` was removed (v2.4).** Per-field flags are now the only gate, and all default to `false`. The shim preserves behaviour for legacy configs by rewriting them in memory at startup:
- Legacy `enabled: true` defaults every unset per-field flag in the group to `true`, matching the old "everything visible" behaviour. Per-field flags you had explicitly set to `false` (the "all except X" pattern) are kept.
- Legacy `enabled: false` clears any per-field flags that were `true`, matching the old "nothing visible" behaviour and stopping leftover documentation flags from the shipped 2.3 config from becoming live opt-ins.
A deprecation notice is printed at startup. Update your `config.json` to the explicit per-field form to silence it. The shim will be removed in v3.0, and at that point any field IPP has added since v2.3 will need a fresh opt-in.