Skip to content

Commit

Permalink
Add config value for cache duration
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Jun 28, 2024
1 parent af6e15b commit 16f8a1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/api/middlewares/ImageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ const resizeSupported = new Set([...sharpSupported, ...jimpSupported]);
export async function ImageProxy(req: Request, res: Response) {
const path = req.originalUrl.split("/").slice(2);

const secret = Config.get().security.requestSignature;

// src/api/util/utility/EmbedHandlers.ts getProxyUrl
const hash = crypto
.createHmac("sha1", secret)
.createHmac("sha1", Config.get().security.requestSignature)
.update(path.slice(1).join("/"))
.digest("base64")
.replace(/\+/g, "-")
Expand Down Expand Up @@ -159,7 +157,10 @@ export async function ImageProxy(req: Request, res: Response) {
}

res.header("Content-Type", contentType);
res.setHeader("Cache-Control", "public, max-age=" + 1000 * 60 * 60 * 24);
res.setHeader(
"Cache-Control",
"public, max-age=" + Config.get().cdn.proxyCacheHeaderSeconds,
);

res.send(resultBuffer);
}
8 changes: 5 additions & 3 deletions src/util/config/types/CdnConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand All @@ -25,4 +25,6 @@ export class CdnConfiguration extends EndpointConfiguration {

endpointPublic: string | null = null;
endpointPrivate: string | null = null;

proxyCacheHeaderSeconds: number = 60 * 60 * 24;
}

0 comments on commit 16f8a1c

Please sign in to comment.