Merge providers API into a single endpoint

This commit is contained in:
mikiher 2025-10-19 10:53:27 +03:00
parent 0a82d6a41b
commit 0a8662d198
2 changed files with 13 additions and 98 deletions

View File

@ -251,107 +251,27 @@ class SearchController {
}
/**
* GET: /api/search/providers/podcasts/covers
* Get available podcast cover metadata providers
* GET: /api/search/providers
* Get all available metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getPodcastCoverProviders(req, res) {
// Podcast covers only use iTunes
const customProviders = await Database.customMetadataProviderModel.findAll({
where: {
mediaType: 'podcast'
}
})
async getAllProviders(req, res) {
const customProviders = await Database.customMetadataProviderModel.findAll()
const providers = [SearchController.formatProvider('itunes'), ...SearchController.mapCustomProviders(customProviders)]
const customBookProviders = customProviders.filter((p) => p.mediaType === 'book')
const customPodcastProviders = customProviders.filter((p) => p.mediaType === 'podcast')
res.json({ providers })
}
/**
* GET: /api/search/providers/books/covers
* Get available book cover metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getBookCoverProviders(req, res) {
// Book covers use all book providers
const customProviders = await Database.customMetadataProviderModel.findAll({
where: {
mediaType: 'book'
}
})
const providers = [SearchController.formatProvider('best'), ...BookFinder.providers.map((p) => SearchController.formatProvider(p)), ...SearchController.mapCustomProviders(customProviders), SearchController.formatProvider('all')]
res.json({ providers })
}
/**
* GET: /api/search/providers/books
* Get available book metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getBookProviders(req, res) {
const customProviders = await Database.customMetadataProviderModel.findAll({
where: {
mediaType: 'book'
}
})
// Filter out cover-only providers
const bookProviders = BookFinder.providers.filter((p) => p !== 'audiobookcovers')
const providers = [...bookProviders.map((p) => SearchController.formatProvider(p)), ...SearchController.mapCustomProviders(customProviders)]
res.json({ providers })
// Build minimized payload with custom providers merged in
const providers = {
books: [...bookProviders.map((p) => SearchController.formatProvider(p)), ...SearchController.mapCustomProviders(customBookProviders)],
booksCovers: [SearchController.formatProvider('best'), ...BookFinder.providers.map((p) => SearchController.formatProvider(p)), ...SearchController.mapCustomProviders(customBookProviders), SearchController.formatProvider('all')],
podcasts: [SearchController.formatProvider('itunes'), ...SearchController.mapCustomProviders(customPodcastProviders)]
}
/**
* GET: /api/search/providers/podcasts
* Get available podcast metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getPodcastProviders(req, res) {
const customProviders = await Database.customMetadataProviderModel.findAll({
where: {
mediaType: 'podcast'
}
})
const providers = [SearchController.formatProvider('itunes'), ...SearchController.mapCustomProviders(customProviders)]
res.json({ providers })
}
/**
* GET: /api/search/providers/authors
* Get available author metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getAuthorProviders(req, res) {
const providers = [SearchController.formatProvider('audnexus')]
res.json({ providers })
}
/**
* GET: /api/search/providers/chapters
* Get available chapter metadata providers
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async getChapterProviders(req, res) {
const providers = [SearchController.formatProvider('audnexus')]
res.json({ providers })
}
}

View File

@ -283,12 +283,7 @@ class ApiRouter {
this.router.get('/search/podcast', SearchController.findPodcasts.bind(this))
this.router.get('/search/authors', SearchController.findAuthor.bind(this))
this.router.get('/search/chapters', SearchController.findChapters.bind(this))
this.router.get('/search/providers/books', SearchController.getBookProviders.bind(this))
this.router.get('/search/providers/books/covers', SearchController.getBookCoverProviders.bind(this))
this.router.get('/search/providers/podcasts', SearchController.getPodcastProviders.bind(this))
this.router.get('/search/providers/podcasts/covers', SearchController.getPodcastCoverProviders.bind(this))
this.router.get('/search/providers/authors', SearchController.getAuthorProviders.bind(this))
this.router.get('/search/providers/chapters', SearchController.getChapterProviders.bind(this))
this.router.get('/search/providers', SearchController.getAllProviders.bind(this))
//
// Cache Routes (Admin and up)