Fix error when viewing expired link

Fixes #8243

To test:
- create a public link and set the expiry date
- move the expiry date to the past by editing the entry in the database.
- try to view the now expired public link 

@autrui can check if this solves the problem for you?

cc @DeepDiver1975 @karlitschek