Fix unnecessary download thread, fix load audiobooks having different uri

This commit is contained in:
advplyr 2021-10-18 19:40:05 -05:00
parent 5a025b3a03
commit cd3277a5f9
6 changed files with 37 additions and 19 deletions

View file

@ -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)