fix: show short video durations accurately
This commit is contained in:
@@ -66,7 +66,7 @@ function toVideo(video: BunnyApiVideo): BunnyVideo {
|
|||||||
status: bunnyMediaStatus(video.status),
|
status: bunnyMediaStatus(video.status),
|
||||||
providerStatus: video.status,
|
providerStatus: video.status,
|
||||||
encodeProgress: Math.max(0, Math.min(100, Math.round(video.encodeProgress ?? 0))),
|
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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,14 @@ const toAttachment = (asset: ApiAsset): Attachment => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const toDuration = (seconds: number | null) => {
|
const toDuration = (seconds: number | null) => {
|
||||||
if (!seconds) return '—';
|
if (!seconds || seconds < 1) return '—';
|
||||||
const minutes = Math.round(seconds / 60);
|
const totalSeconds = Math.round(seconds);
|
||||||
return minutes >= 60 ? `${Math.floor(minutes / 60)}h ${minutes % 60}m` : `${minutes}m`;
|
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']) => {
|
const toCourseDuration = (lessons: ApiCourse['lessons']) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user