From 0a1f050ab0f5442c26113e46ed42bc6396115c79 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Fri, 5 Jun 2026 11:39:26 +1200 Subject: [PATCH] #244 Reverse metadata field defaults --- app/config.json | 2 - app/src/config/migrations.ts | 80 +++++++++++++++++++++--------------- app/src/gallery/builder.ts | 3 +- app/src/gallery/exif.ts | 24 ++++------- docs/configuration.md | 38 +++++++++++------ 5 files changed, 82 insertions(+), 65 deletions(-) diff --git a/app/config.json b/app/config.json index f73867e..914f027 100644 --- a/app/config.json +++ b/app/config.json @@ -16,7 +16,6 @@ "sidebar": false }, "exif": { - "enableAll": false, "dateTimeOriginal": false, "fileName": false, "dimensions": false, @@ -30,7 +29,6 @@ "focalLength": false }, "location": { - "enableAll": false, "city": false, "state": false, "country": false, diff --git a/app/src/config/migrations.ts b/app/src/config/migrations.ts index 54e4557..65b9b84 100644 --- a/app/src/config/migrations.ts +++ b/app/src/config/migrations.ts @@ -25,7 +25,7 @@ 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 } + { name: 'metadataEnabled', removeIn: 'v3.0', apply: applyMetadataEnabledShim } ] /** @@ -123,50 +123,62 @@ function applyDescriptionSplitShim (config: Config): void { } /** - * SHIM: showMetadata.{exif,location}.enabled -> .enableAll, with per- - * field defaults flipped from `true` to `false`. + * SHIM: showMetadata.{exif,location}.enabled removed. Per-field flags are + * now the only gate, and they all default to `false`. * - * New semantics: `enableAll: true` shows every field in the group; - * `enableAll: false` shows only fields with an explicit per-field `true`. + * The 2.3.0 shipped `config.json` had `enabled: false` plus every per- + * 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: - * (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. + * - `enabled: true`: for each known field in the group, if the per- + * field flag is `undefined`, set it to `true` (the old default). + * Explicit `false` per-field flags are kept, so "all except X" + * patterns continue to work. + * - `enabled: false`: clear any per-field flag that is `true`. Under + * the old semantic those flags were dead code (the master switch + * hid them), so wiping them preserves the "nothing visible" + * behaviour the user had. + * + * The field lists below are frozen at v2.x. If new fields are added in + * future versions, they will not auto-appear for legacy `enabled: true` + * 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 const showMetadata = ipp.showMetadata as Record | undefined if (!showMetadata) return 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 | 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 + if (legacyEnabled) { + for (const field of fields) { + if (group[field] === undefined) group[field] = true + } + } else { + for (const field of fields) { + if (group[field] === true) group[field] = false } } @@ -176,10 +188,10 @@ function applyEnableAllShim (config: Config): void { 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.' + 'deprecated and have been removed. Per-field flags are now the ' + + 'only gate (all default `false`). Your legacy config has been ' + + 'rewritten in memory to preserve current behaviour; please update ' + + 'your `config.json` to the explicit per-field form. See README.' ) } } diff --git a/app/src/gallery/builder.ts b/app/src/gallery/builder.ts index 662d155..0fb9bf3 100644 --- a/app/src/gallery/builder.ts +++ b/app/src/gallery/builder.ts @@ -132,7 +132,8 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb metadataConfig: { descriptionInCaption, descriptionInSidebar, - sidebarHasContent + sidebarHasContent, + locationWebLink: !!getConfigOption('ipp.showMetadata.location.webLink', true) }, groupByDate } diff --git a/app/src/gallery/exif.ts b/app/src/gallery/exif.ts index 4b3a740..0e2537a 100644 --- a/app/src/gallery/exif.ts +++ b/app/src/gallery/exif.ts @@ -85,13 +85,11 @@ const RULES: Record = { /** * Build the per-asset metadata sub-object included in the gallery JSON. * Reads `ipp.showMetadata.exif.*` and `ipp.showMetadata.location.*` config: - * each group has a master `enableAll` toggle and a set of per-field flags - * that all default to `false`. A field appears in the output when either - * the group's `enableAll` is true, OR the field's own flag is true. + * every field is an explicit per-field opt-in (all default `false`), so + * nothing is sent unless the operator has explicitly turned on the flag. * - * Returns `undefined` when neither group has any visible content, or when - * no fields survive gating (so the client knows there's no metadata to - * show). + * Returns `undefined` when 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 * 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 - * config - either `enableAll` is set, or at least one per-field flag is - * explicitly `true`. Used by the sidebar visibility check. + * Returns true if a metadata group has at least one per-field flag + * explicitly set to `true` in config. Used by the sidebar visibility + * check. */ export function metadataGroupActive (group: Group): boolean { - 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) + 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 { return !!getConfigOption(`ipp.showMetadata.${group}.${flag}`, false) } diff --git a/docs/configuration.md b/docs/configuration.md index 99bf5e0..1bc3c05 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -37,7 +37,7 @@ For one-off or single-key overrides. See [inline configuration](inline-configura ## 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. @@ -123,15 +123,15 @@ Configured under `ipp.showMetadata`. The lightbox includes a slide-in info sideb | Option | Type | 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). | -| `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). | +| `description` | `object` | Where to show the description. `{ "caption": bool, "sidebar": bool }`. Both default `false`. See [Description](#description). | +| `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). 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 @@ -150,7 +150,6 @@ Under `ipp.showMetadata.exif`. | Option | Type | Description | |---------------------|--------|--------------------------------------------------------------------------| -| `enabled` | `bool` | Master switch for the EXIF group. Default `false`. | | `dateTimeOriginal` | `bool` | Show the date the photo was taken (per EXIF). | | `fileName` | `bool` | Show the original filename. | | `dimensions` | `bool` | Show width x height and megapixel count. | @@ -169,22 +168,30 @@ Under `ipp.showMetadata.location`. | Option | Type | Description | |------------|--------|----------------------------------------------------------------------| -| `enabled` | `bool` | Master switch for the location group. Default `false`. | | `city` | `bool` | Show city. | | `state` | `bool` | Show state / region. | | `country` | `bool` | Show country. | | `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`. | -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 { "ipp": { "showMetadata": { "description": { "caption": false, "sidebar": true }, - "exif": { "enabled": true }, - "location": { "enabled": true, "gps": false } + "exif": { + "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` | **`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.