Add config value for cache duration

This commit is contained in:
TomatoCake 2024-06-28 10:17:24 +02:00
parent af6e15b9e5
commit 16f8a1c7ac
3 changed files with 11 additions and 7 deletions

1
package-lock.json generated
View File

@ -30,6 +30,7 @@
"i18next-fs-backend": "^2.1.5", "i18next-fs-backend": "^2.1.5",
"i18next-http-middleware": "^3.3.2", "i18next-http-middleware": "^3.3.2",
"image-size": "^1.0.2", "image-size": "^1.0.2",
"jimp": "^0.22.12",
"json-bigint": "^1.0.0", "json-bigint": "^1.0.0",
"jsonwebtoken": "^9.0.1", "jsonwebtoken": "^9.0.1",
"lambert-server": "^1.2.12", "lambert-server": "^1.2.12",

View File

@ -47,11 +47,9 @@ const resizeSupported = new Set([...sharpSupported, ...jimpSupported]);
export async function ImageProxy(req: Request, res: Response) { export async function ImageProxy(req: Request, res: Response) {
const path = req.originalUrl.split("/").slice(2); const path = req.originalUrl.split("/").slice(2);
const secret = Config.get().security.requestSignature;
// src/api/util/utility/EmbedHandlers.ts getProxyUrl // src/api/util/utility/EmbedHandlers.ts getProxyUrl
const hash = crypto const hash = crypto
.createHmac("sha1", secret) .createHmac("sha1", Config.get().security.requestSignature)
.update(path.slice(1).join("/")) .update(path.slice(1).join("/"))
.digest("base64") .digest("base64")
.replace(/\+/g, "-") .replace(/\+/g, "-")
@ -159,7 +157,10 @@ export async function ImageProxy(req: Request, res: Response) {
} }
res.header("Content-Type", contentType); 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); res.send(resultBuffer);
} }

View File

@ -1,17 +1,17 @@
/* /*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify 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 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 by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@ -25,4 +25,6 @@ export class CdnConfiguration extends EndpointConfiguration {
endpointPublic: string | null = null; endpointPublic: string | null = null;
endpointPrivate: string | null = null; endpointPrivate: string | null = null;
proxyCacheHeaderSeconds: number = 60 * 60 * 24;
} }