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