Skip to content

fix: correct edited shared link expiration time#22466

Closed
tskoyo wants to merge 4 commits intoimmich-app:mainfrom
tskoyo:fix/edit-share-link-expiration-time
Closed

fix: correct edited shared link expiration time#22466
tskoyo wants to merge 4 commits intoimmich-app:mainfrom
tskoyo:fix/edit-share-link-expiration-time

Conversation

@tskoyo
Copy link

@tskoyo tskoyo commented Sep 28, 2025

Description

When user wants to create a shared link and sets the link to expire in 1 day (for example), it wouldn't work when user wants to visit the /shared-links page.

Fixes # (issue)

How Has This Been Tested?

  • Open a photo
  • Create share link
  • Set expire after some time
  • Go to /shared-links
  • Open the shared link details
  • You should see Expire in now

Screenshots (if appropriate)

Checklist:

  • [x ] 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)
  • [ x] 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/)

Please describe to which degree, if any, an LLM was used in creating this pull request.

...

Copy link
Member

@danieldietzler danieldietzler left a comment

Choose a reason for hiding this comment

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

Have you tested this? From only looking at the code I don't think this will work. Also, just in general this seems like the wrong approach to me. IMO the expected behavior of that dropdown should be to show the option originally selected when creating the shared link, not the closest option to whatever time is remaining

@tskoyo
Copy link
Author

tskoyo commented Sep 29, 2025

@danieldietzler , I tested it. When you create a new shared link, the expiration information is stored in the expiresAt column of the shared_link table, using the format YYYY-MM-DD HH:MM.sss.

However, it’s not straightforward to show the originally selected expiration option, since it’s stored as a specific timestamp. For example, if you set the expiration to 6 hours and check back after 2 hours, the remaining time would be 4 hours. So, some calculation is needed to display the correct expiration time.

@danieldietzler
Copy link
Member

Right. I don't understand how you can deduct the original expiration interval from that timestamp, unless you also look at when that shared link was created. You don't do that

const expiresAt = DateTime.fromISO(editingLink?.expiresAt);

const now = DateTime.now();
const remainingMs = expiresAt.toMillis() - now.toMillis();
Copy link
Contributor

Choose a reason for hiding this comment

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

Here instead of using now.toMillis() can we use createdAt column?
also expiresAt - createdAt is not exactly 7 days (it's 10-20 seconds less than 7 days). add 30s-1m to expiresAt and now your old logic works.

Copy link
Member

Choose a reason for hiding this comment

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

Tbh I feel like any frontend change here is kind of not ideal. I am wondering if we should just store the interval in the database, instead of/in addition to expiresAt. I'll bring it up in the team

albumId = editingLink.album?.id;
assetIds = editingLink.assets.map(({ id }) => id);

const expiresAt = editingLink.expiresAt ? DateTime.fromISO(editingLink.expiresAt) : DateTime.fromMillis(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'd be nicer to encapsulate all this new logic in a function like initialExpirationOption to help organize the code

@benmccann benmccann changed the title Fix edited shared link expiration time value fix: correct edited shared link expiration time Oct 6, 2025
@benmccann
Copy link
Collaborator

This PR looks to be targeting similar functionality as #22274

@danieldietzler
Copy link
Member

Closing per Ben's comment. If it does actually fix a different issue, let us know and we can re-open

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.

4 participants