Add cache-control headers to attachments.redirect response
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user