From e18bb7663090f21bacabad4596252dafd78bd2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 4 Sep 2026 15:54:15 -0300 Subject: [PATCH] fix: show short video durations accurately --- server/src/providers/bunny.ts | 2 +- services/db.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/src/providers/bunny.ts b/server/src/providers/bunny.ts index 5f5e6fd..b7f8c0a 100644 --- a/server/src/providers/bunny.ts +++ b/server/src/providers/bunny.ts @@ -66,7 +66,7 @@ function toVideo(video: BunnyApiVideo): BunnyVideo { status: bunnyMediaStatus(video.status), providerStatus: video.status, encodeProgress: Math.max(0, Math.min(100, Math.round(video.encodeProgress ?? 0))), - durationSeconds: typeof video.length === 'number' && video.length > 0 ? Math.round(video.length) : null, + durationSeconds: typeof video.length === 'number' && video.length > 0 ? Math.max(1, Math.round(video.length)) : null, }; } diff --git a/services/db.ts b/services/db.ts index c36fd28..4b7ce8f 100644 --- a/services/db.ts +++ b/services/db.ts @@ -59,9 +59,14 @@ const toAttachment = (asset: ApiAsset): Attachment => ({ }); const toDuration = (seconds: number | null) => { - if (!seconds) return '—'; - const minutes = Math.round(seconds / 60); - return minutes >= 60 ? `${Math.floor(minutes / 60)}h ${minutes % 60}m` : `${minutes}m`; + if (!seconds || seconds < 1) return '—'; + const totalSeconds = Math.round(seconds); + const hours = Math.floor(totalSeconds / 3600); + const minutes = Math.floor((totalSeconds % 3600) / 60); + const remainingSeconds = totalSeconds % 60; + if (hours) return `${hours}h ${String(minutes).padStart(2, '0')}min`; + if (minutes) return `${minutes}min`; + return `${remainingSeconds}s`; }; const toCourseDuration = (lessons: ApiCourse['lessons']) => {