mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-29 14:28:34 +02:00
Add: Login/connection error messages
This commit is contained in:
parent
f5d455feb1
commit
708f399916
6 changed files with 94 additions and 42 deletions
69
Server.js
69
Server.js
|
@ -64,23 +64,28 @@ class Server extends EventEmitter {
|
||||||
async connect(url, token) {
|
async connect(url, token) {
|
||||||
if (this.connected) {
|
if (this.connected) {
|
||||||
console.warn('[SOCKET] Connection already established for ' + this.url)
|
console.warn('[SOCKET] Connection already established for ' + this.url)
|
||||||
return true
|
return { success: true }
|
||||||
}
|
}
|
||||||
if (!url) {
|
if (!url) {
|
||||||
console.error('Invalid url to connect')
|
console.error('Invalid url to connect')
|
||||||
return false
|
return {
|
||||||
|
error: 'Invalid URL'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverUrl = this.getServerUrl(url)
|
var serverUrl = this.getServerUrl(url)
|
||||||
var res = await this.ping(serverUrl)
|
var res = await this.ping(serverUrl)
|
||||||
|
|
||||||
if (!res || !res.success) {
|
if (!res || !res.success) {
|
||||||
//this.setServerUrl(null)
|
return {
|
||||||
return false
|
error: res ? res.error : 'Unknown Error'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var authRes = await this.authorize(serverUrl, token)
|
var authRes = await this.authorize(serverUrl, token)
|
||||||
if (!authRes || !authRes.user) {
|
if (!authRes || authRes.error) {
|
||||||
return false
|
return {
|
||||||
|
error: authRes ? authRes.error : 'Authorization Error'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setServerUrl(serverUrl)
|
this.setServerUrl(serverUrl)
|
||||||
|
@ -88,19 +93,26 @@ class Server extends EventEmitter {
|
||||||
this.setUser(authRes.user)
|
this.setUser(authRes.user)
|
||||||
this.connectSocket()
|
this.connectSocket()
|
||||||
|
|
||||||
return true
|
return { success: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
async check(url) {
|
async check(url) {
|
||||||
var serverUrl = this.getServerUrl(url)
|
var serverUrl = this.getServerUrl(url)
|
||||||
if (!serverUrl) {
|
if (!serverUrl) {
|
||||||
return false
|
return {
|
||||||
|
error: 'Invalid server url'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var res = await this.ping(serverUrl)
|
var res = await this.ping(serverUrl)
|
||||||
if (!res || !res.success) {
|
if (!res || res.error) {
|
||||||
return false
|
return {
|
||||||
|
error: res ? res.error : 'Ping Failed'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
serverUrl
|
||||||
}
|
}
|
||||||
return serverUrl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(url, username, password) {
|
async login(url, username, password) {
|
||||||
|
@ -122,8 +134,16 @@ class Server extends EventEmitter {
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('[Server] Server auth failed', error)
|
console.error('[Server] Server auth failed', error)
|
||||||
|
var errorMsg = null
|
||||||
|
if (error.response) {
|
||||||
|
errorMsg = error.response.data || 'Unknown Error'
|
||||||
|
} else if (error.request) {
|
||||||
|
errorMsg = 'Server did not respond'
|
||||||
|
} else {
|
||||||
|
errorMsg = 'Failed to send request'
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
error: 'Request Failed'
|
error: errorMsg
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -142,7 +162,17 @@ class Server extends EventEmitter {
|
||||||
return res.data
|
return res.data
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('[Server] Server auth failed', error)
|
console.error('[Server] Server auth failed', error)
|
||||||
return false
|
var errorMsg = null
|
||||||
|
if (error.response) {
|
||||||
|
errorMsg = error.response.data || 'Unknown Error'
|
||||||
|
} else if (error.request) {
|
||||||
|
errorMsg = 'Server did not respond'
|
||||||
|
} else {
|
||||||
|
errorMsg = 'Failed to send request'
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
error: errorMsg
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +183,18 @@ class Server extends EventEmitter {
|
||||||
return res.data
|
return res.data
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Server check failed', error)
|
console.error('Server check failed', error)
|
||||||
return false
|
var errorMsg = null
|
||||||
|
if (error.response) {
|
||||||
|
errorMsg = error.response.data || 'Unknown Error'
|
||||||
|
} else if (error.request) {
|
||||||
|
errorMsg = 'Server did not respond'
|
||||||
|
} else {
|
||||||
|
errorMsg = 'Failed to send request'
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: errorMsg
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ android {
|
||||||
applicationId "com.audiobookshelf.app"
|
applicationId "com.audiobookshelf.app"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 44
|
versionCode 45
|
||||||
versionName "0.9.25-beta"
|
versionName "0.9.26-beta"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
aaptOptions {
|
aaptOptions {
|
||||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<Nuxt />
|
<Nuxt />
|
||||||
</div>
|
</div>
|
||||||
<app-audio-player-container ref="streamContainer" />
|
<app-audio-player-container ref="streamContainer" />
|
||||||
<!-- <modals-downloads-modal ref="downloadsModal" @deleteDownload="deleteDownload" /> -->
|
|
||||||
<modals-libraries-modal />
|
<modals-libraries-modal />
|
||||||
<app-side-drawer />
|
<app-side-drawer />
|
||||||
<readers-reader />
|
<readers-reader />
|
||||||
|
@ -14,7 +13,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Capacitor } from '@capacitor/core'
|
import { Capacitor } from '@capacitor/core'
|
||||||
import { Network } from '@capacitor/network'
|
|
||||||
import { AppUpdate } from '@robingenz/capacitor-app-update'
|
import { AppUpdate } from '@robingenz/capacitor-app-update'
|
||||||
import AudioDownloader from '@/plugins/audio-downloader'
|
import AudioDownloader from '@/plugins/audio-downloader'
|
||||||
import StorageManager from '@/plugins/storage-manager'
|
import StorageManager from '@/plugins/storage-manager'
|
||||||
|
@ -276,15 +274,6 @@ export default {
|
||||||
this.$store.commit('setHasStoragePermission', true)
|
this.$store.commit('setHasStoragePermission', true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async setupNetworkListener() {
|
|
||||||
var status = await Network.getStatus()
|
|
||||||
this.$store.commit('setNetworkStatus', status)
|
|
||||||
|
|
||||||
Network.addListener('networkStatusChange', (status) => {
|
|
||||||
console.log('Network status changed', status.connected, status.connectionType)
|
|
||||||
this.$store.commit('setNetworkStatus', status)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
showErrorToast(message) {
|
showErrorToast(message) {
|
||||||
this.$toast.error(message)
|
this.$toast.error(message)
|
||||||
},
|
},
|
||||||
|
@ -333,7 +322,7 @@ export default {
|
||||||
|
|
||||||
if (this.$store.state.isFirstLoad) {
|
if (this.$store.state.isFirstLoad) {
|
||||||
this.$store.commit('setIsFirstLoad', false)
|
this.$store.commit('setIsFirstLoad', false)
|
||||||
await this.setupNetworkListener()
|
await this.$store.dispatch('setupNetworkListener')
|
||||||
this.attemptConnection()
|
this.attemptConnection()
|
||||||
this.checkForUpdate()
|
this.checkForUpdate()
|
||||||
this.initMediaStore()
|
this.initMediaStore()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "audiobookshelf-app",
|
"name": "audiobookshelf-app",
|
||||||
"version": "v0.9.25-beta",
|
"version": "v0.9.26-beta",
|
||||||
"author": "advplyr",
|
"author": "advplyr",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxt --hostname localhost --port 1337",
|
"dev": "nuxt --hostname localhost --port 1337",
|
||||||
|
|
|
@ -97,11 +97,11 @@ export default {
|
||||||
}
|
}
|
||||||
this.processing = true
|
this.processing = true
|
||||||
this.error = null
|
this.error = null
|
||||||
var success = await this.$server.check(this.serverUrl)
|
var response = await this.$server.check(this.serverUrl)
|
||||||
this.processing = false
|
this.processing = false
|
||||||
if (!success) {
|
if (!response || response.error) {
|
||||||
console.error('Server invalid')
|
console.error('Server invalid')
|
||||||
this.error = 'Invalid Server'
|
this.error = response ? response.error : 'Invalid Server'
|
||||||
} else {
|
} else {
|
||||||
this.showAuth = true
|
this.showAuth = true
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,8 @@ export default {
|
||||||
this.redirect()
|
this.redirect()
|
||||||
},
|
},
|
||||||
async init() {
|
async init() {
|
||||||
|
await this.$store.dispatch('setupNetworkListener')
|
||||||
|
|
||||||
if (!this.$server) {
|
if (!this.$server) {
|
||||||
console.error('Invalid server not initialized')
|
console.error('Invalid server not initialized')
|
||||||
return
|
return
|
||||||
|
@ -162,16 +164,18 @@ export default {
|
||||||
this.serverUrl = localServerUrl
|
this.serverUrl = localServerUrl
|
||||||
if (localUserToken) {
|
if (localUserToken) {
|
||||||
this.processing = true
|
this.processing = true
|
||||||
var success = await this.$server.connect(localServerUrl, localUserToken)
|
var response = await this.$server.connect(localServerUrl, localUserToken)
|
||||||
|
if (!response || response.error) {
|
||||||
if (!success && !this.$server.url) {
|
var errorMsg = response ? response.error : 'Unknown Error'
|
||||||
this.processing = false
|
this.processing = false
|
||||||
|
this.error = errorMsg
|
||||||
|
if (!this.$server.url) {
|
||||||
this.serverUrl = null
|
this.serverUrl = null
|
||||||
this.showAuth = false
|
this.showAuth = false
|
||||||
} else if (!success) {
|
|
||||||
console.log('Server connect success')
|
|
||||||
this.processing = false
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log('Server connect success')
|
||||||
this.showAuth = true
|
this.showAuth = true
|
||||||
} else {
|
} else {
|
||||||
this.submit()
|
this.submit()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
import { Network } from '@capacitor/network'
|
||||||
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
streamAudiobook: null,
|
streamAudiobook: null,
|
||||||
|
@ -17,7 +18,8 @@ export const state = () => ({
|
||||||
downloadFolder: null,
|
downloadFolder: null,
|
||||||
|
|
||||||
showSideDrawer: false,
|
showSideDrawer: false,
|
||||||
bookshelfView: 'grid'
|
bookshelfView: 'grid',
|
||||||
|
isNetworkListenerInit: false
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
|
@ -35,7 +37,20 @@ export const getters = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const actions = {}
|
export const actions = {
|
||||||
|
async setupNetworkListener({ state, commit }) {
|
||||||
|
if (state.isNetworkListenerInit) return
|
||||||
|
commit('setNetworkListenerInit', true)
|
||||||
|
|
||||||
|
var status = await Network.getStatus()
|
||||||
|
commit('setNetworkStatus', status)
|
||||||
|
|
||||||
|
Network.addListener('networkStatusChange', (status) => {
|
||||||
|
console.log('Network status changed', status.connected, status.connectionType)
|
||||||
|
commit('setNetworkStatus', status)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
setHasStoragePermission(state, val) {
|
setHasStoragePermission(state, val) {
|
||||||
|
@ -80,6 +95,9 @@ export const mutations = {
|
||||||
setSocketConnected(state, val) {
|
setSocketConnected(state, val) {
|
||||||
state.socketConnected = val
|
state.socketConnected = val
|
||||||
},
|
},
|
||||||
|
setNetworkListenerInit(state, val) {
|
||||||
|
state.isNetworkListenerInit = val
|
||||||
|
},
|
||||||
setNetworkStatus(state, val) {
|
setNetworkStatus(state, val) {
|
||||||
state.networkConnected = val.connected
|
state.networkConnected = val.connected
|
||||||
state.networkConnectionType = val.connectionType
|
state.networkConnectionType = val.connectionType
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue