Skip to content

PRO-6706: optional pretty URLs for PDFs (files, not images)#5352

Open
boutell wants to merge 6 commits intomainfrom
pro-6706
Open

PRO-6706: optional pretty URLs for PDFs (files, not images)#5352
boutell wants to merge 6 commits intomainfrom
pro-6706

Conversation

@boutell
Copy link
Member

@boutell boutell commented Mar 10, 2026

A simple and effective implementation. Optional because there is a performance tradeoff but this is a reasonably performant solution. I don't think we should implement it for images, because it would hurt performance more significantly, and RA agrees that's not important. People care much more for PDFs because they are pages, of a sort, and people see that URL.

@boutell boutell requested a review from BoDonkey March 10, 2026 21:17
} catch (e) {
return send502(e);
}
for (const header of [ 'content-type', 'etag', 'last-modified', 'content-disposition', 'cache-control' ]) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the set of useful headers I can proxy through without causing any problems if the original is gzip encoded.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think eslint --fix did this.

for (const file of files) {
if (self.options.prettyUrls) {
const { extension } = file.attachment;
file._url = `${req.baseUrl}${self.options.prettyUrlDir}/${file.slug.replace(self.options.slugPrefix || '', '')}.${extension}`;
Copy link
Member Author

@boutell boutell Mar 10, 2026

Choose a reason for hiding this comment

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

The slugPrefix isn't "pretty" (/files/file-name is not as nice as /files/name)
Slug without prefix is still unique among pieces of this type.

Copy link
Contributor

@myovchev myovchev Mar 11, 2026

Choose a reason for hiding this comment

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

This will blow up static builds.

const baseUrl = self.apos.url.getBaseUrl(req, { prefix: true })

The Base URL should respect:

  • prefix
  • static base URL if set
  • etc - all rules applied by the single source of truth now above

if prefix shouldn't be respected, prefix: false can be passed.
Even with that, static build should be also validated, because

  • we expect relative URLs when getting metadata
  • and single base URL for the attachments
  • I doubt this will be included in the attachments metadata at all
  • We ignore the files and images modules metadata when processing "used" attachments, but files can register these URLs as "literal content" I guess, which can save the day
  • If we do that, static build will have duplicated (different paths) files, but this is expected and the right thing to do

if (self.options.prettyUrls) {
const { extension } = file.attachment;
file._url = `${req.baseUrl}${self.options.prettyUrlDir}/${file.slug.replace(self.options.slugPrefix || '', '')}.${extension}`;
file.attachment._prettyUrl = file._url;
Copy link
Member Author

Choose a reason for hiding this comment

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

A hint to .url() for later

}
return {
get: {
async [`${self.options.prettyUrlDir}/*`](req, res) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Implements /files/pretty-name-here.pdf

Copy link
Contributor

@BoDonkey BoDonkey left a comment

Choose a reason for hiding this comment

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

I;m not sure if my comment will show up or not. I was commenting on Miro's point and asking if the helper utility should be used instead of req.baseUrl

@boutell boutell requested review from BoDonkey and myovchev March 11, 2026 17:12
@boutell
Copy link
Member Author

boutell commented Mar 11, 2026

I made the change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants