fix: localize validation and api messages
This commit is contained in:
@@ -14,16 +14,16 @@ const webhookSchema = z.object({
|
||||
|
||||
export const bunnyWebhookRoutes: FastifyPluginAsync = async (app) => {
|
||||
app.post('/bunny', async (request, reply) => {
|
||||
if (!isBunnyWebhookConfigured()) return reply.code(503).send({ error: 'Bunny webhooks are not configured' });
|
||||
if (!isBunnyWebhookConfigured()) return reply.code(503).send({ error: 'Os webhooks do Bunny não estão configurados.' });
|
||||
const rawBody = (request as typeof request & { rawBody?: Buffer }).rawBody;
|
||||
const signatureHeader = request.headers.signature || request.headers['x-bunny-signature'];
|
||||
const signature = Array.isArray(signatureHeader) ? signatureHeader[0] : signatureHeader;
|
||||
if (!rawBody || !verifyBunnyWebhookSignature(rawBody, signature)) {
|
||||
return reply.code(401).send({ error: 'Invalid Bunny webhook signature' });
|
||||
return reply.code(401).send({ error: 'Assinatura do webhook do Bunny inválida.' });
|
||||
}
|
||||
const input = webhookSchema.parse(request.body);
|
||||
if (input.VideoLibraryId !== config.BUNNY_STREAM_LIBRARY_ID) {
|
||||
return reply.code(400).send({ error: 'Unexpected Bunny video library' });
|
||||
return reply.code(400).send({ error: 'Biblioteca de vídeos Bunny inesperada.' });
|
||||
}
|
||||
const status = bunnyMediaStatus(input.Status);
|
||||
await pool.query(
|
||||
|
||||
Reference in New Issue
Block a user