Add cache-control headers to attachments.redirect response

This commit is contained in:
Tom Moor
2023-09-25 21:30:57 -04:00
parent b1ddf417be
commit 9e810387c0
3 changed files with 9 additions and 3 deletions

View File

@@ -108,7 +108,7 @@ class Attachment extends IdModel {
}
/**
* Get a signed URL with the default expirt to download the attachment from storage.
* Get a signed URL with the default expiry to download the attachment from storage.
*/
get signedUrl() {
return FileStorage.getSignedUrl(this.key);

View File

@@ -13,6 +13,7 @@ import AttachmentHelper from "@server/models/helpers/AttachmentHelper";
import { authorize } from "@server/policies";
import { presentAttachment } from "@server/presenters";
import FileStorage from "@server/storage/files";
import BaseStorage from "@server/storage/files/BaseStorage";
import { APIContext } from "@server/types";
import { RateLimiterStrategy } from "@server/utils/RateLimiter";
import { assertIn } from "@server/validation";
@@ -171,8 +172,13 @@ const handleAttachmentsRedirect = async (
});
if (attachment.isPrivate) {
ctx.set(
"Cache-Control",
`max-age=${BaseStorage.defaultSignedUrlExpires}, immutable`
);
ctx.redirect(await attachment.signedUrl);
} else {
ctx.set("Cache-Control", `max-age=604800, immutable`);
ctx.redirect(attachment.canonicalUrl);
}
};