mirror of
https://github.com/documenso/documenso.git
synced 2026-08-25 15:52:29 +10:00
fix: brand logo caching (#2699)
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { getTeamSettings } from '@documenso/lib/server-only/team/get-team-settings';
|
||||
import { sha256 } from '@documenso/lib/universal/crypto';
|
||||
import { getFileServerSide } from '@documenso/lib/universal/upload/get-file.server';
|
||||
import { loadLogo } from '@documenso/lib/utils/images/logo';
|
||||
|
||||
import type { Route } from './+types/branding.logo.team.$teamId';
|
||||
|
||||
export async function loader({ params }: Route.LoaderArgs) {
|
||||
const CACHE_CONTROL = 'public, max-age=0, stale-while-revalidate=86400';
|
||||
|
||||
export async function loader({ params, request }: Route.LoaderArgs) {
|
||||
const teamId = Number(params.teamId);
|
||||
|
||||
if (teamId === 0 || Number.isNaN(teamId)) {
|
||||
@@ -41,6 +44,18 @@ export async function loader({ params }: Route.LoaderArgs) {
|
||||
);
|
||||
}
|
||||
|
||||
const etag = `"${Buffer.from(sha256(settings.brandingLogo)).toString('hex')}"`;
|
||||
|
||||
if (request.headers.get('If-None-Match') === etag) {
|
||||
return new Response(null, {
|
||||
status: 304,
|
||||
headers: {
|
||||
ETag: etag,
|
||||
'Cache-Control': CACHE_CONTROL,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const file = await getFileServerSide(JSON.parse(settings.brandingLogo)).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
@@ -61,8 +76,8 @@ export async function loader({ params }: Route.LoaderArgs) {
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
'Content-Length': content.length.toString(),
|
||||
// Stale while revalidate for 1 hours to 24 hours
|
||||
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=86400',
|
||||
'Cache-Control': CACHE_CONTROL,
|
||||
ETag: etag,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user