feat: make media cleanup best-effort with warning summaries and enforce video/workspace management access

This commit is contained in:
Yusuf İpek
2026-02-25 18:59:02 +03:00
parent 9ce033d306
commit 76d37d02e5
11 changed files with 444 additions and 251 deletions
+64
View File
@@ -0,0 +1,64 @@
import type { BunnyCleanupResult } from '@/lib/bunny-stream-cleanup';
import type { R2CleanupResult } from '@/lib/r2-cleanup';
interface CleanupWarningSummary {
attempted: number;
failed: number;
}
export interface CleanupWarnings {
bunny?: CleanupWarningSummary;
r2?: CleanupWarningSummary;
}
export function buildCleanupWarnings(input: {
bunny?: BunnyCleanupResult;
r2?: R2CleanupResult;
}): CleanupWarnings | undefined {
const warnings: CleanupWarnings = {};
if (input.bunny && input.bunny.failed > 0) {
warnings.bunny = {
attempted: input.bunny.attempted,
failed: input.bunny.failed,
};
}
if (input.r2 && input.r2.failed > 0) {
warnings.r2 = {
attempted: input.r2.attempted,
failed: input.r2.failed,
};
}
return Object.keys(warnings).length > 0 ? warnings : undefined;
}
export function logCleanupWarnings(
context: { entityType: string; entityId: string },
input: { bunny?: BunnyCleanupResult; r2?: R2CleanupResult }
): void {
if (input.bunny && input.bunny.failed > 0) {
console.error('External cleanup warning', {
entityType: context.entityType,
entityId: context.entityId,
provider: 'bunny',
operation: 'delete',
attempted: input.bunny.attempted,
failed: input.bunny.failed,
failedIds: input.bunny.failedIds.slice(0, 10),
});
}
if (input.r2 && input.r2.failed > 0) {
console.error('External cleanup warning', {
entityType: context.entityType,
entityId: context.entityId,
provider: 'r2',
operation: 'delete',
attempted: input.r2.attempted,
failed: input.r2.failed,
failedKeys: input.r2.failedKeys.slice(0, 10),
});
}
}