Client: Use new server providers API

This commit is contained in:
mikiher 2025-10-15 09:52:15 +03:00
parent 1da3ab7fdc
commit ce4ff4f894
10 changed files with 90 additions and 124 deletions

View File

@ -88,7 +88,7 @@ export default {
}, },
providers() { providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.bookProviders
}, },
libraryProvider() { libraryProvider() {
return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google' return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google'

View File

@ -133,8 +133,8 @@ export default {
} }
}, },
providers() { providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders if (this.isPodcast) return this.$store.state.scanners.podcastCoverProviders
return [{ text: 'Best', value: 'best' }, ...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders, { text: 'All', value: 'all' }] return this.$store.state.scanners.bookCoverProviders
}, },
searchTitleLabel() { searchTitleLabel() {
if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN

View File

@ -319,7 +319,7 @@ export default {
}, },
providers() { providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.bookProviders
}, },
searchTitleLabel() { searchTitleLabel() {
if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN

View File

@ -74,7 +74,7 @@ export default {
}, },
providers() { providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.bookProviders
} }
}, },
methods: { methods: {

View File

@ -136,7 +136,7 @@ export default {
}, },
providers() { providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.bookProviders
}, },
maskAsFinishedWhenItems() { maskAsFinishedWhenItems() {
return [ return [

View File

@ -371,11 +371,25 @@ export default {
}, },
customMetadataProviderAdded(provider) { customMetadataProviderAdded(provider) {
if (!provider?.id) return if (!provider?.id) return
this.$store.commit('scanners/addCustomMetadataProvider', provider) // Refetch the appropriate provider types
if (provider.mediaType === 'book') {
this.$store.dispatch('scanners/fetchBookProviders')
this.$store.dispatch('scanners/fetchBookCoverProviders')
} else if (provider.mediaType === 'podcast') {
this.$store.dispatch('scanners/fetchPodcastProviders')
this.$store.dispatch('scanners/fetchPodcastCoverProviders')
}
}, },
customMetadataProviderRemoved(provider) { customMetadataProviderRemoved(provider) {
if (!provider?.id) return if (!provider?.id) return
this.$store.commit('scanners/removeCustomMetadataProvider', provider) // Refetch the appropriate provider types
if (provider.mediaType === 'book') {
this.$store.dispatch('scanners/fetchBookProviders')
this.$store.dispatch('scanners/fetchBookCoverProviders')
} else if (provider.mediaType === 'podcast') {
this.$store.dispatch('scanners/fetchPodcastProviders')
this.$store.dispatch('scanners/fetchPodcastCoverProviders')
}
}, },
initializeSocket() { initializeSocket() {
if (this.$root.socket) { if (this.$root.socket) {
@ -612,6 +626,12 @@ export default {
this.$store.dispatch('libraries/load') this.$store.dispatch('libraries/load')
// Fetch metadata providers
this.$store.dispatch('scanners/fetchBookProviders')
this.$store.dispatch('scanners/fetchBookCoverProviders')
this.$store.dispatch('scanners/fetchPodcastProviders')
this.$store.dispatch('scanners/fetchPodcastCoverProviders')
this.initLocalStorage() this.initLocalStorage()
this.checkVersionUpdate() this.checkVersionUpdate()

View File

@ -247,7 +247,8 @@ export default {
return this.$store.state.serverSettings return this.$store.state.serverSettings
}, },
providers() { providers() {
return this.$store.state.scanners.providers // Use book cover providers for the cover provider dropdown
return this.$store.state.scanners.bookCoverProviders || []
}, },
dateFormats() { dateFormats() {
return this.$store.state.globals.dateFormats return this.$store.state.globals.dateFormats

View File

@ -155,7 +155,7 @@ export default {
}, },
providers() { providers() {
if (this.selectedLibraryIsPodcast) return this.$store.state.scanners.podcastProviders if (this.selectedLibraryIsPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.bookProviders
}, },
canFetchMetadata() { canFetchMetadata() {
return !this.selectedLibraryIsPodcast && this.fetchMetadata.enabled return !this.selectedLibraryIsPodcast && this.fetchMetadata.enabled

View File

@ -131,8 +131,6 @@ export const actions = {
commit('setLibraryIssues', issues) commit('setLibraryIssues', issues)
commit('setLibraryFilterData', filterData) commit('setLibraryFilterData', filterData)
commit('setNumUserPlaylists', numUserPlaylists) commit('setNumUserPlaylists', numUserPlaylists)
commit('scanners/setCustomMetadataProviders', customMetadataProviders, { root: true })
commit('setCurrentLibrary', { id: libraryId }) commit('setCurrentLibrary', { id: libraryId })
return data return data
}) })

View File

@ -1,126 +1,73 @@
export const state = () => ({ export const state = () => ({
providers: [ bookProviders: [],
{ podcastProviders: [],
text: 'Google Books', bookCoverProviders: [],
value: 'google' podcastCoverProviders: []
},
{
text: 'Open Library',
value: 'openlibrary'
},
{
text: 'iTunes',
value: 'itunes'
},
{
text: 'Audible.com',
value: 'audible'
},
{
text: 'Audible.ca',
value: 'audible.ca'
},
{
text: 'Audible.co.uk',
value: 'audible.uk'
},
{
text: 'Audible.com.au',
value: 'audible.au'
},
{
text: 'Audible.fr',
value: 'audible.fr'
},
{
text: 'Audible.de',
value: 'audible.de'
},
{
text: 'Audible.co.jp',
value: 'audible.jp'
},
{
text: 'Audible.it',
value: 'audible.it'
},
{
text: 'Audible.co.in',
value: 'audible.in'
},
{
text: 'Audible.es',
value: 'audible.es'
},
{
text: 'FantLab.ru',
value: 'fantlab'
}
],
podcastProviders: [
{
text: 'iTunes',
value: 'itunes'
}
],
coverOnlyProviders: [
{
text: 'AudiobookCovers.com',
value: 'audiobookcovers'
}
]
}) })
export const getters = { export const getters = {
checkBookProviderExists: state => (providerValue) => { checkBookProviderExists: (state) => (providerValue) => {
return state.providers.some(p => p.value === providerValue) return state.bookProviders.some((p) => p.value === providerValue)
}, },
checkPodcastProviderExists: state => (providerValue) => { checkPodcastProviderExists: (state) => (providerValue) => {
return state.podcastProviders.some(p => p.value === providerValue) return state.podcastProviders.some((p) => p.value === providerValue)
} }
} }
export const actions = {} export const actions = {
async fetchBookProviders({ commit }) {
try {
const response = await this.$axios.$get('/api/search/providers/books')
if (response?.providers) {
commit('setBookProviders', response.providers)
}
} catch (error) {
console.error('Failed to fetch book providers', error)
}
},
async fetchPodcastProviders({ commit }) {
try {
const response = await this.$axios.$get('/api/search/providers/podcasts')
if (response?.providers) {
commit('setPodcastProviders', response.providers)
}
} catch (error) {
console.error('Failed to fetch podcast providers', error)
}
},
async fetchBookCoverProviders({ commit }) {
try {
const response = await this.$axios.$get('/api/search/providers/books/covers')
if (response?.providers) {
commit('setBookCoverProviders', response.providers)
}
} catch (error) {
console.error('Failed to fetch book cover providers', error)
}
},
async fetchPodcastCoverProviders({ commit }) {
try {
const response = await this.$axios.$get('/api/search/providers/podcasts/covers')
if (response?.providers) {
commit('setPodcastCoverProviders', response.providers)
}
} catch (error) {
console.error('Failed to fetch podcast cover providers', error)
}
}
}
export const mutations = { export const mutations = {
addCustomMetadataProvider(state, provider) { setBookProviders(state, providers) {
if (provider.mediaType === 'book') { state.bookProviders = providers
if (state.providers.some(p => p.value === provider.slug)) return
state.providers.push({
text: provider.name,
value: provider.slug
})
} else {
if (state.podcastProviders.some(p => p.value === provider.slug)) return
state.podcastProviders.push({
text: provider.name,
value: provider.slug
})
}
}, },
removeCustomMetadataProvider(state, provider) { setPodcastProviders(state, providers) {
if (provider.mediaType === 'book') { state.podcastProviders = providers
state.providers = state.providers.filter(p => p.value !== provider.slug)
} else {
state.podcastProviders = state.podcastProviders.filter(p => p.value !== provider.slug)
}
}, },
setCustomMetadataProviders(state, providers) { setBookCoverProviders(state, providers) {
if (!providers?.length) return state.bookCoverProviders = providers
},
const mediaType = providers[0].mediaType setPodcastCoverProviders(state, providers) {
if (mediaType === 'book') { state.podcastCoverProviders = providers
// clear previous values, and add new values to the end
state.providers = state.providers.filter((p) => !p.value.startsWith('custom-'))
state.providers = [
...state.providers,
...providers.map((p) => ({
text: p.name,
value: p.slug
}))
]
} else {
// Podcast providers not supported yet
}
} }
} }