mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-08 00:54:33 +01:00
Added error handling; Made querystring helper
This commit is contained in:
parent
e5579b2c33
commit
d9c9289d65
@ -65,8 +65,10 @@
|
||||
|
||||
<script>
|
||||
import Path from 'path'
|
||||
import apiRequestHelpers from '@/mixins/apiRequestHelpers'
|
||||
|
||||
export default {
|
||||
mixins: [apiRequestHelpers],
|
||||
props: {
|
||||
item: {
|
||||
type: Object,
|
||||
@ -132,27 +134,36 @@ export default {
|
||||
}
|
||||
|
||||
this.isFetchingMetadata = true
|
||||
this.error = ''
|
||||
|
||||
try {
|
||||
const searchQueryString = `title=${this.itemData.title}&author=${this.itemData.author}&provider=${this.provider}`
|
||||
const searchQueryString = this.buildQuerystring({
|
||||
title: this.itemData.title,
|
||||
author: this.itemData.author,
|
||||
provider: this.provider
|
||||
})
|
||||
const [bestCandidate, ..._rest] = await this.$axios.$get(`/api/search/books?${searchQueryString}`)
|
||||
|
||||
this.itemData = {
|
||||
...this.itemData,
|
||||
title: bestCandidate?.title,
|
||||
author: bestCandidate?.author,
|
||||
series: (bestCandidate?.series || [])[0]?.series
|
||||
if (bestCandidate) {
|
||||
this.itemData = {
|
||||
...this.itemData,
|
||||
title: bestCandidate?.title,
|
||||
author: bestCandidate?.author,
|
||||
series: (bestCandidate?.series || [])[0]?.series
|
||||
}
|
||||
} else {
|
||||
this.error = this.$strings.ErrorUploadFetchMetadataNoResults
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed', e)
|
||||
// TODO: do something with the error?
|
||||
this.error = this.$strings.ErrorUploadFetchMetadataAPI
|
||||
} finally {
|
||||
this.isFetchingMetadata = false
|
||||
}
|
||||
},
|
||||
getData() {
|
||||
if (!this.itemData.title) {
|
||||
this.error = 'Must have a title'
|
||||
this.error = this.$strings.ErrorUploadLacksTitle
|
||||
return null
|
||||
}
|
||||
this.error = ''
|
||||
|
12
client/mixins/apiRequestHelpers.js
Normal file
12
client/mixins/apiRequestHelpers.js
Normal file
@ -0,0 +1,12 @@
|
||||
export default {
|
||||
methods: {
|
||||
buildQuerystring(obj, opts = { includePrefix: false }) {
|
||||
let querystring = Object
|
||||
.entries(obj)
|
||||
.map(([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`)
|
||||
.join('&')
|
||||
|
||||
return (opts.includePrefix ? '?' : '').concat(querystring)
|
||||
}
|
||||
}
|
||||
}
|
@ -87,6 +87,9 @@
|
||||
"ButtonUserEdit": "Edit user {0}",
|
||||
"ButtonViewAll": "View All",
|
||||
"ButtonYes": "Yes",
|
||||
"ErrorUploadFetchMetadataAPI": "Error fetching metadata",
|
||||
"ErrorUploadFetchMetadataNoResults": "Could not fetch metadata - try updating title and/or author",
|
||||
"ErrorUploadLacksTitle": "Must have a title",
|
||||
"HeaderAccount": "Account",
|
||||
"HeaderAdvanced": "Advanced",
|
||||
"HeaderAppriseNotificationSettings": "Apprise Notification Settings",
|
||||
|
Loading…
Reference in New Issue
Block a user