mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 07:09:53 +02:00
Fix unnecessary download thread, fix load audiobooks having different uri
This commit is contained in:
parent
5a025b3a03
commit
cd3277a5f9
6 changed files with 37 additions and 19 deletions
14
Server.js
14
Server.js
|
@ -28,8 +28,13 @@ class Server extends EventEmitter {
|
|||
|
||||
getServerUrl(url) {
|
||||
if (!url) return null
|
||||
var urlObject = new URL(url)
|
||||
return `${urlObject.protocol}//${urlObject.hostname}:${urlObject.port}`
|
||||
try {
|
||||
var urlObject = new URL(url)
|
||||
return `${urlObject.protocol}//${urlObject.hostname}:${urlObject.port}`
|
||||
} catch (error) {
|
||||
console.error('Invalid URL', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
setUser(user) {
|
||||
|
@ -82,6 +87,9 @@ class Server extends EventEmitter {
|
|||
|
||||
async check(url) {
|
||||
var serverUrl = this.getServerUrl(url)
|
||||
if (!serverUrl) {
|
||||
return false
|
||||
}
|
||||
var res = await this.ping(serverUrl)
|
||||
if (!res || !res.success) {
|
||||
return false
|
||||
|
@ -134,7 +142,7 @@ class Server extends EventEmitter {
|
|||
ping(url) {
|
||||
var pingUrl = url + '/ping'
|
||||
console.log('[Server] Check server', pingUrl)
|
||||
return axios.get(pingUrl).then((res) => {
|
||||
return axios.get(pingUrl, { timeout: 1000 }).then((res) => {
|
||||
return res.data
|
||||
}).catch(error => {
|
||||
console.error('Server check failed', error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue