mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-04 01:09:40 +00:00
Update:Matching authors uses the ASIN if set #572, Fix:Purge author image cache when updating author
This commit is contained in:
parent
eaa383b6d8
commit
f78d287b59
7 changed files with 43 additions and 79 deletions
|
|
@ -107,11 +107,16 @@ class AuthorController {
|
|||
}
|
||||
|
||||
async match(req, res) {
|
||||
var authorData = await this.authorFinder.findAuthorByName(req.body.q)
|
||||
var authorData = null
|
||||
if (req.body.asin) {
|
||||
authorData = await this.authorFinder.findAuthorByASIN(req.body.asin)
|
||||
} else {
|
||||
authorData = await this.authorFinder.findAuthorByName(req.body.q)
|
||||
}
|
||||
if (!authorData) {
|
||||
return res.status(404).send('Author not found')
|
||||
}
|
||||
Logger.debug(`[AuthorController] match author with "${req.body.q}"`, authorData)
|
||||
Logger.debug(`[AuthorController] match author with "${req.body.q || req.body.asin}"`, authorData)
|
||||
|
||||
var hasUpdates = false
|
||||
if (authorData.asin && req.author.asin !== authorData.asin) {
|
||||
|
|
@ -121,6 +126,8 @@ class AuthorController {
|
|||
|
||||
// Only updates image if there was no image before or the author ASIN was updated
|
||||
if (authorData.image && (!req.author.imagePath || hasUpdates)) {
|
||||
this.cacheManager.purgeImageCache(req.author.id)
|
||||
|
||||
var imageData = await this.authorFinder.saveAuthorImage(req.author.id, authorData.image)
|
||||
if (imageData) {
|
||||
req.author.imagePath = imageData.path
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ class AuthorFinder {
|
|||
})
|
||||
}
|
||||
|
||||
findAuthorByASIN(asin) {
|
||||
if (!asin) return null
|
||||
return this.audnexus.findAuthorByASIN(asin)
|
||||
}
|
||||
|
||||
async findAuthorByName(name, options = {}) {
|
||||
if (!name) return null
|
||||
const maxLevenshtein = !isNaN(options.maxLevenshtein) ? Number(options.maxLevenshtein) : 3
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Author {
|
|||
imagePath: this.imagePath,
|
||||
relImagePath: this.relImagePath,
|
||||
addedAt: this.addedAt,
|
||||
lastUpdate: this.updatedAt
|
||||
updatedAt: this.updatedAt
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,19 @@ class Audnexus {
|
|||
})
|
||||
}
|
||||
|
||||
async findAuthorByASIN(asin) {
|
||||
var author = await this.authorRequest(asin)
|
||||
if (!author) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
asin: author.asin,
|
||||
description: author.description,
|
||||
image: author.image,
|
||||
name: author.name
|
||||
}
|
||||
}
|
||||
|
||||
async findAuthorByName(name, maxLevenshtein = 3) {
|
||||
Logger.debug(`[Audnexus] Looking up author by name ${name}`)
|
||||
var asins = await this.authorASINsRequest(name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue