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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@ import { EditorState, Plugin } from "prosemirror-state";
|
||||
import { Decoration, DecorationSet } from "prosemirror-view";
|
||||
import * as React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import Logger from "~/utils/Logger";
|
||||
import FileExtension from "../components/FileExtension";
|
||||
import { recreateTransform } from "./prosemirror-recreate-transform";
|
||||
|
||||
@@ -24,7 +23,8 @@ const uploadPlaceholder = new Plugin({
|
||||
simplifyDiff: true,
|
||||
}).mapping;
|
||||
} catch (err) {
|
||||
Logger.warn("Failed to recreate transform", err);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("Failed to recreate transform: ", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user