mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-18 13:52:02 +02:00
Optimize time string conversion and add processing for invalid time
This commit is contained in:
parent
5e73e6745c
commit
07432cc26c
@ -100,20 +100,31 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
timeStringToSeconds(timeStr) {
|
timeStringToSeconds(timeStr) {
|
||||||
const parts = timeStr.split(':').map(Number)
|
const parts = timeStr.split(':').map(Number)
|
||||||
let seconds = 0
|
let hours = 0,
|
||||||
|
minutes = 0,
|
||||||
|
seconds = 0
|
||||||
if (parts.length === 3) {
|
if (parts.length === 3) {
|
||||||
seconds = parts[0] * 3600 + parts[1] * 60 + parts[2]
|
;[hours, minutes, seconds] = parts
|
||||||
} else if (parts.length === 2) {
|
} 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) {
|
linkifyTimestamps(htmlString) {
|
||||||
const timeRegex = /\b((\d{1,2}:)?\d{1,2}:\d{2})\b/g
|
const timeRegex = /\b((\d{1,2}:)?\d{1,2}:\d{2})\b/g
|
||||||
|
|
||||||
return htmlString.replace(timeRegex, (match) => {
|
return htmlString.replace(timeRegex, (match) => {
|
||||||
const totalSeconds = this.timeStringToSeconds(match)
|
const totalSeconds = timeStringToSeconds(match)
|
||||||
|
if (totalSeconds !== null) {
|
||||||
return `<a href="#" class="timestamp-link" data-time-seconds="${totalSeconds}">${match}</a>`
|
return `<a href="#" class="timestamp-link" data-time-seconds="${totalSeconds}">${match}</a>`
|
||||||
|
}
|
||||||
|
return match
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleDescriptionClick(e) {
|
handleDescriptionClick(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user