feat: delete lesson videos from Bunny

This commit is contained in:
Cauê Faleiros
2026-09-04 15:18:10 -03:00
parent 1a79fa447b
commit 66671f65c3
4 changed files with 45 additions and 5 deletions

View File

@@ -114,6 +114,10 @@ export async function getBunnyVideo(videoId: string) {
return toVideo(await response.json() as BunnyApiVideo);
}
export async function deleteBunnyVideo(videoId: string) {
await bunnyRequest(`/videos/${encodeURIComponent(videoId)}`, { method: 'DELETE' });
}
export function signedBunnyEmbedUrl(videoId: string, validitySeconds = config.BUNNY_EMBED_TOKEN_TTL_SECONDS) {
const { libraryId, embedTokenKey } = getBunnyConfiguration();
const expires = Math.floor(Date.now() / 1000) + validitySeconds;

View File

@@ -6,6 +6,7 @@ import {
BunnyConfigurationError,
BunnyRequestError,
createBunnyVideo,
deleteBunnyVideo,
getBunnyVideo,
isBunnyConfigured,
uploadBunnyVideo,
@@ -123,4 +124,15 @@ export const mediaRoutes: FastifyPluginAsync = async (app) => {
return providerError(reply, error);
}
});
app.delete('/bunny/videos/:videoId', manageAccess, async (request, reply) => {
const { videoId } = videoParamsSchema.parse(request.params);
try {
await deleteBunnyVideo(videoId);
await recordAudit({ actorId: request.user.id, action: 'media.video.deleted', subjectType: 'video', subjectId: videoId, ipAddress: request.ip });
return reply.code(204).send();
} catch (error) {
return providerError(reply, error);
}
});
};