#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
+46 -34
View File
@@ -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<string, unknown>
const showMetadata = ipp.showMetadata as Record<string, unknown> | 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<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
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.'
)
}
}
+2 -1
View File
@@ -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
}
+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.
* 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)
}