From 07432cc26c260d592744d1079ddb270a07d5bc05 Mon Sep 17 00:00:00 2001 From: Aemon Cao Date: Sat, 7 Jun 2025 15:12:08 +0800 Subject: [PATCH] Optimize time string conversion and add processing for invalid time --- .../components/modals/podcast/ViewEpisode.vue | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/client/components/modals/podcast/ViewEpisode.vue b/client/components/modals/podcast/ViewEpisode.vue index 794758e1f..f5fa69387 100644 --- a/client/components/modals/podcast/ViewEpisode.vue +++ b/client/components/modals/podcast/ViewEpisode.vue @@ -100,20 +100,31 @@ export default { methods: { timeStringToSeconds(timeStr) { const parts = timeStr.split(':').map(Number) - let seconds = 0 + let hours = 0, + minutes = 0, + seconds = 0 if (parts.length === 3) { - seconds = parts[0] * 3600 + parts[1] * 60 + parts[2] + ;[hours, minutes, seconds] = parts } else if (parts.length === 2) { - seconds = parts[0] * 60 + parts[1] + ;[minutes, seconds] = parts + } else { + return null } - return seconds + if (minutes >= 60 || seconds >= 60 || hours < 0 || minutes < 0 || seconds < 0) { + return null + } + + return hours * 3600 + minutes * 60 + seconds }, linkifyTimestamps(htmlString) { const timeRegex = /\b((\d{1,2}:)?\d{1,2}:\d{2})\b/g return htmlString.replace(timeRegex, (match) => { - const totalSeconds = this.timeStringToSeconds(match) - return `${match}` + const totalSeconds = timeStringToSeconds(match) + if (totalSeconds !== null) { + return `${match}` + } + return match }) }, handleDescriptionClick(e) {