mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-30 14:49:47 +02:00
Update get libraries API call to support updated response payload
This commit is contained in:
parent
32dfb3b40a
commit
a0faf3f7d4
3 changed files with 18 additions and 11 deletions
|
@ -138,12 +138,16 @@ class ApiHandler(var ctx:Context) {
|
||||||
val mapper = jacksonMapper
|
val mapper = jacksonMapper
|
||||||
getRequest("/api/libraries", null,null) {
|
getRequest("/api/libraries", null,null) {
|
||||||
val libraries = mutableListOf<Library>()
|
val libraries = mutableListOf<Library>()
|
||||||
if (it.has("value")) {
|
|
||||||
val array = it.getJSONArray("value")
|
var array = JSONArray()
|
||||||
for (i in 0 until array.length()) {
|
if (it.has("libraries")) { // TODO: Server 2.2.9 changed to this
|
||||||
val library = mapper.readValue<Library>(array.get(i).toString())
|
array = it.getJSONArray("libraries")
|
||||||
libraries.add(library)
|
} else if (it.has("value")) {
|
||||||
}
|
array = it.getJSONArray("value")
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i in 0 until array.length()) {
|
||||||
|
libraries.add(mapper.readValue(array.get(i).toString()))
|
||||||
}
|
}
|
||||||
cb(libraries)
|
cb(libraries)
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,9 +89,9 @@ export default {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.isFetching = true
|
this.isFetching = true
|
||||||
var results = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/search?q=${value}&limit=5`).catch((error) => {
|
const results = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/search?q=${value}&limit=5`).catch((error) => {
|
||||||
console.error('Search error', error)
|
console.error('Search error', error)
|
||||||
return []
|
return null
|
||||||
})
|
})
|
||||||
if (value !== this.lastSearch) {
|
if (value !== this.lastSearch) {
|
||||||
console.log(`runSearch: New search was made for ${this.lastSearch} - results are from ${value}`)
|
console.log(`runSearch: New search was made for ${this.lastSearch} - results are from ${value}`)
|
||||||
|
|
|
@ -75,12 +75,15 @@ export const actions = {
|
||||||
return this.$axios
|
return this.$axios
|
||||||
.$get(`/api/libraries`)
|
.$get(`/api/libraries`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
// TODO: Server release 2.2.9 changed response to an object. Remove after a few releases
|
||||||
|
const libraries = data.libraries || data
|
||||||
|
|
||||||
// Set current library if not already set or was not returned in results
|
// Set current library if not already set or was not returned in results
|
||||||
if (data.length && (!state.currentLibraryId || !data.find(li => li.id == state.currentLibraryId))) {
|
if (libraries.length && (!state.currentLibraryId || !libraries.find(li => li.id == state.currentLibraryId))) {
|
||||||
commit('setCurrentLibrary', data[0].id)
|
commit('setCurrentLibrary', libraries[0].id)
|
||||||
}
|
}
|
||||||
|
|
||||||
commit('set', data)
|
commit('set', libraries)
|
||||||
commit('setLastLoad', Date.now())
|
commit('setLastLoad', Date.now())
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue