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() {
|
get signedUrl() {
|
||||||
return FileStorage.getSignedUrl(this.key);
|
return FileStorage.getSignedUrl(this.key);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import AttachmentHelper from "@server/models/helpers/AttachmentHelper";
|
|||||||
import { authorize } from "@server/policies";
|
import { authorize } from "@server/policies";
|
||||||
import { presentAttachment } from "@server/presenters";
|
import { presentAttachment } from "@server/presenters";
|
||||||
import FileStorage from "@server/storage/files";
|
import FileStorage from "@server/storage/files";
|
||||||
|
import BaseStorage from "@server/storage/files/BaseStorage";
|
||||||
import { APIContext } from "@server/types";
|
import { APIContext } from "@server/types";
|
||||||
import { RateLimiterStrategy } from "@server/utils/RateLimiter";
|
import { RateLimiterStrategy } from "@server/utils/RateLimiter";
|
||||||
import { assertIn } from "@server/validation";
|
import { assertIn } from "@server/validation";
|
||||||
@@ -171,8 +172,13 @@ const handleAttachmentsRedirect = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (attachment.isPrivate) {
|
if (attachment.isPrivate) {
|
||||||
|
ctx.set(
|
||||||
|
"Cache-Control",
|
||||||
|
`max-age=${BaseStorage.defaultSignedUrlExpires}, immutable`
|
||||||
|
);
|
||||||
ctx.redirect(await attachment.signedUrl);
|
ctx.redirect(await attachment.signedUrl);
|
||||||
} else {
|
} else {
|
||||||
|
ctx.set("Cache-Control", `max-age=604800, immutable`);
|
||||||
ctx.redirect(attachment.canonicalUrl);
|
ctx.redirect(attachment.canonicalUrl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { EditorState, Plugin } from "prosemirror-state";
|
|||||||
import { Decoration, DecorationSet } from "prosemirror-view";
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import Logger from "~/utils/Logger";
|
|
||||||
import FileExtension from "../components/FileExtension";
|
import FileExtension from "../components/FileExtension";
|
||||||
import { recreateTransform } from "./prosemirror-recreate-transform";
|
import { recreateTransform } from "./prosemirror-recreate-transform";
|
||||||
|
|
||||||
@@ -24,7 +23,8 @@ const uploadPlaceholder = new Plugin({
|
|||||||
simplifyDiff: true,
|
simplifyDiff: true,
|
||||||
}).mapping;
|
}).mapping;
|
||||||
} catch (err) {
|
} 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