mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-12 18:35:00 +02: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
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