Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add album start and end dates for storage template #17188

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

exciton
Copy link

@exciton exciton commented Mar 28, 2025

This adds all the possible date templates (y, m, d, etc) for album createdAt, updatedAt, startDate, and endDate (last two are calculated automatically from album contents) to the Storage Template.

For example the template could look like this:
{{#if album}}{{album-startDate-y}}/{{album-startDate-MM}} - {{album}}{{else}}{{y}}/{{MM}}/{{/if}}/{{filename}}

Description

This change adds 4 dates, and all possible date templates to the Storage template so that it's possible to store albums in a single folder that includes date components.

Without this patch the Storage Template can only use date fields from each asset individually, which puts them in different folders even if they are in the same album (if the album spans more than one day).

Fixes the following feature requests:
#16721
#16843

Fixes # (issue)

How Has This Been Tested?

  • Works with assets without an album
  • Places assets in the same album into the same folder using a template containing album-startDate-y (for year) and album-startDate-MM (for month)

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

This adds all the possible date templates (y, m, d, etc) for album
createdAt, updatedAt, startDate, and endDate (last two are calculated
off automatically from album contents to the storage template.

For example the template could look like this:
{{#if album}}{{album-startDate-y}}/{{album-startDate-MM}} - {{album}}{{else}}{{y}}/{{MM}}/{{/if}}/{{filename}}
@mertalev
Copy link
Contributor

Do you really think the createdAt and updatedAt fields are worth including here? I can't really imagine a use-case for them.

@exciton
Copy link
Author

exciton commented Mar 28, 2025

I can't imagine using updatedAt, but createdAt could be useful - creating an album of photos with no proper timestamps (e.g. scans of old photos), or a compilation of photos - it might be useful to reference the date it was created.

@mertalev
Copy link
Contributor

That still seems pretty niche. I think we can omit both for now. It's easy to add them if there's any demand, not so easy to remove them after they're added.

Copy link
Contributor

@mertalev mertalev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you add tests for this?

@exciton
Copy link
Author

exciton commented Mar 28, 2025

Can add some tests, yes. Will try to find where to add docs too.

@danielcebrian
Copy link

Sounds great your changes, thank you so much!

@alextran1502
Copy link
Contributor

Hello, can you help add examples to the storage template settings?

image

You can find it at web/src/lib/components/admin-page/settings/storage-template/supported-variables-panel.svelte

@exciton
Copy link
Author

exciton commented Mar 30, 2025

@mertalev , @alextran1502 - tests and documentation updated.

@zackpollard zackpollard changed the title Add album create, update, start, end dates to Storage Template feat: add album start and end dates for storage template Mar 31, 2025
@zackpollard
Copy link
Contributor

I'm just wondering in general, how is this supposed to work. You add assets to an album then manually go and re-run the storage migration? These dates are highly variable so the storage template could become out of sync with a single new asset being added to an album, requiring all of the assets to be moved to a different directory, which won't happen automatically currently.

@exciton
Copy link
Author

exciton commented Mar 31, 2025

Yes, that's generally how it would work. I'd recommend to use the start date which won't change so long as only new assets are added to an album.

In my case I have hundreds of old albums to import, so this process really only has to happen once, and will remain in place after import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants