check if previews are disabled before anything else

This commit is contained in:
Hazelnoot 2025-05-28 13:31:24 -04:00
parent b1876bf06e
commit f4107b1c2b

View file

@ -123,6 +123,16 @@ export class UrlPreviewService {
request: FastifyRequest<PreviewRoute>,
reply: FastifyReply,
): Promise<void> {
if (!this.meta.urlPreviewEnabled) {
return reply.code(403).send({
error: {
message: 'URL preview is disabled',
code: 'URL_PREVIEW_DISABLED',
id: '58b36e13-d2f5-0323-b0c6-76aa9dabefb8',
},
});
}
const url = request.query.url;
if (typeof url !== 'string' || !URL.canParse(url)) {
reply.code(400);
@ -135,16 +145,6 @@ export class UrlPreviewService {
return;
}
if (!this.meta.urlPreviewEnabled) {
return reply.code(403).send({
error: {
message: 'URL preview is disabled',
code: 'URL_PREVIEW_DISABLED',
id: '58b36e13-d2f5-0323-b0c6-76aa9dabefb8',
},
});
}
// Check rate limit
const auth = await this.authenticate(request);
if (!await this.checkRateLimit(auth, reply)) {