Update get libraries API call to support updated response payload

This commit is contained in:
advplyr 2022-12-02 17:39:45 -06:00
parent 32dfb3b40a
commit a0faf3f7d4
3 changed files with 18 additions and 11 deletions

View file

@ -138,12 +138,16 @@ class ApiHandler(var ctx:Context) {
val mapper = jacksonMapper
getRequest("/api/libraries", null,null) {
val libraries = mutableListOf<Library>()
if (it.has("value")) {
val array = it.getJSONArray("value")
for (i in 0 until array.length()) {
val library = mapper.readValue<Library>(array.get(i).toString())
libraries.add(library)
var array = JSONArray()
if (it.has("libraries")) { // TODO: Server 2.2.9 changed to this
array = it.getJSONArray("libraries")
} 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)
}

View file

@ -89,9 +89,9 @@ export default {
return
}
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)
return []
return null
})
if (value !== this.lastSearch) {
console.log(`runSearch: New search was made for ${this.lastSearch} - results are from ${value}`)

View file

@ -75,12 +75,15 @@ export const actions = {
return this.$axios
.$get(`/api/libraries`)
.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
if (data.length && (!state.currentLibraryId || !data.find(li => li.id == state.currentLibraryId))) {
commit('setCurrentLibrary', data[0].id)
if (libraries.length && (!state.currentLibraryId || !libraries.find(li => li.id == state.currentLibraryId))) {
commit('setCurrentLibrary', libraries[0].id)
}
commit('set', data)
commit('set', libraries)
commit('setLastLoad', Date.now())
return true
})