mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-14 07:49:37 +00:00
Fix:Shares not working with timeouts longer than 23 days #3164
This commit is contained in:
parent
ee53086444
commit
88693d73bd
3 changed files with 64 additions and 10 deletions
|
|
@ -66,6 +66,11 @@ module.exports.getId = (prepend = '') => {
|
|||
return _id
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} seconds
|
||||
* @returns {string}
|
||||
*/
|
||||
function elapsedPretty(seconds) {
|
||||
if (seconds > 0 && seconds < 1) {
|
||||
return `${Math.floor(seconds * 1000)} ms`
|
||||
|
|
@ -73,16 +78,27 @@ function elapsedPretty(seconds) {
|
|||
if (seconds < 60) {
|
||||
return `${Math.floor(seconds)} sec`
|
||||
}
|
||||
var minutes = Math.floor(seconds / 60)
|
||||
let minutes = Math.floor(seconds / 60)
|
||||
if (minutes < 70) {
|
||||
return `${minutes} min`
|
||||
}
|
||||
var hours = Math.floor(minutes / 60)
|
||||
let hours = Math.floor(minutes / 60)
|
||||
minutes -= hours * 60
|
||||
if (!minutes) {
|
||||
return `${hours} hr`
|
||||
|
||||
let days = Math.floor(hours / 24)
|
||||
hours -= days * 24
|
||||
|
||||
const timeParts = []
|
||||
if (days) {
|
||||
timeParts.push(`${days} d`)
|
||||
}
|
||||
return `${hours} hr ${minutes} min`
|
||||
if (hours || (days && minutes)) {
|
||||
timeParts.push(`${hours} hr`)
|
||||
}
|
||||
if (minutes) {
|
||||
timeParts.push(`${minutes} min`)
|
||||
}
|
||||
return timeParts.join(' ')
|
||||
}
|
||||
module.exports.elapsedPretty = elapsedPretty
|
||||
|
||||
|
|
|
|||
36
server/utils/longTimeout.js
Normal file
36
server/utils/longTimeout.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Handle timeouts greater than 32-bit signed integer
|
||||
*/
|
||||
class LongTimeout {
|
||||
constructor() {
|
||||
this.timeout = 0
|
||||
this.timer = null
|
||||
}
|
||||
|
||||
clear() {
|
||||
clearTimeout(this.timer)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {number} timeout
|
||||
*/
|
||||
set(fn, timeout) {
|
||||
const maxValue = 2147483647
|
||||
|
||||
const handleTimeout = () => {
|
||||
if (this.timeout > 0) {
|
||||
let delay = Math.min(this.timeout, maxValue)
|
||||
this.timeout = this.timeout - delay
|
||||
this.timer = setTimeout(handleTimeout, delay)
|
||||
return
|
||||
}
|
||||
fn()
|
||||
}
|
||||
|
||||
this.timeout = timeout
|
||||
handleTimeout()
|
||||
}
|
||||
}
|
||||
module.exports = LongTimeout
|
||||
Loading…
Add table
Add a link
Reference in a new issue