Repository navigation
[Feature] Full user control over the duplicate counter in the storage template #32386
Closed
bitbalancer
started this conversation in
Feature Request
Replies: 1 comment
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have searched the existing feature requests, both open and closed, to make sure this is not a duplicate request.
The feature
The storage template exists so that administrators can impose their own filename convention instead of Immich's: path layout, date format, element order, separators, all user-defined. The duplicate counter is the single exception.
I would like it brought under the same user control as everything else in the template.
Current behaviour
server/src/services/storage-template.service.tsrenders the template once, then appends the counter inside the existence loop:Four decisions are taken on the user's behalf there, none of them changeable:
++9,+101The request
Make all four user-definable, so the whole filename comes from the template.
A naming convention only helps if it is applied consistently. If a convention uses _ as its element separator, fixed-width counters, and a set element order, a counter in a different format leaves colliding files inconsistent with the rest of the archive.
The current behaviour is correct and collision-safe; this is about configurability rather than a defect.
Proposed mechanism
A
{{dupe}}helper, usable anywhere in the filename portion of the template. Making the counter a template element rather than a settings field is what brings all four aspects under the user's control at once.{{dupe}}+1+2{{dupe prefix="_" pad=2}}_01_02{{dupe prefix="_" pad=3 start=0}}_000_001{{dupe prefix="-" start=2}}-2-3The suffix indicator belongs inside the helper rather than as literal template text. Were it literal —
..._{{dupe}}— every non-colliding file would render a dangling_. Indicator and number have to be suppressed as a unit.Implementation sketch
Render per attempt with the helper bound to the current counter, rather than rendering once and appending:
Binding the helper per render rather than through
handlebar.registerHelperkeeps the counter out of global state. It is also required by the existingstrict: truecompile option, under which an unregistered{{dupe}}would throw at render time.Templates are already compiled and cached in
this._template, so re-rendering on collision is cheap, and collisions are rare.Backward compatibility
If the template contains no
{{dupe}}, keep today's append-+Nbehaviour exactly. Existing instances are unaffected, nothing migrates, and no new admin setting is required. The feature lives entirely in the template string users already edit.The main implementation hazard
The
+Nformat is hard-coded in a second place: the Storage Template Migration job uses it to detect files it has already moved.That check assumes the counter is a trailing annotation, so two things follow:
/^\+\d+$/permanently, for libraries that already contain+Nfiles.Validation
pad0–9,prefixmust not contain/or\Out of scope
Only assets Immich owns via the storage template. External library assets keep their on-disk paths and are unaffected.
Prior art
+Nbehaviour but does not propose changing it.+xin passing; the actual request there is to lowercase file extensions.There are currently no custom Handlebars helpers in the repository, so
{{dupe}}would be the first. The mechanism is standard Handlebars, but it would be a new pattern here.Platform
All reactions