mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-02 09:14:40 +02:00
Update:Remove image path input from author modal, add API endpoints for uploading and removing author image
This commit is contained in:
parent
290a377ef9
commit
656c81a1fa
4 changed files with 162 additions and 80 deletions
|
@ -10,13 +10,6 @@ class AuthorFinder {
|
|||
this.audnexus = new Audnexus()
|
||||
}
|
||||
|
||||
async downloadImage(url, outputPath) {
|
||||
return downloadFile(url, outputPath).then(() => true).catch((error) => {
|
||||
Logger.error('[AuthorFinder] Failed to download author image', error)
|
||||
return null
|
||||
})
|
||||
}
|
||||
|
||||
findAuthorByASIN(asin, region) {
|
||||
if (!asin) return null
|
||||
return this.audnexus.findAuthorByASIN(asin, region)
|
||||
|
@ -33,28 +26,36 @@ class AuthorFinder {
|
|||
return author
|
||||
}
|
||||
|
||||
/**
|
||||
* Download author image from url and save in authors folder
|
||||
*
|
||||
* @param {string} authorId
|
||||
* @param {string} url
|
||||
* @returns {Promise<{path:string, error:string}>}
|
||||
*/
|
||||
async saveAuthorImage(authorId, url) {
|
||||
var authorDir = Path.join(global.MetadataPath, 'authors')
|
||||
var relAuthorDir = Path.posix.join('/metadata', 'authors')
|
||||
const authorDir = Path.join(global.MetadataPath, 'authors')
|
||||
|
||||
if (!await fs.pathExists(authorDir)) {
|
||||
await fs.ensureDir(authorDir)
|
||||
}
|
||||
|
||||
var imageExtension = url.toLowerCase().split('.').pop()
|
||||
var ext = imageExtension === 'png' ? 'png' : 'jpg'
|
||||
var filename = authorId + '.' + ext
|
||||
var outputPath = Path.posix.join(authorDir, filename)
|
||||
var relPath = Path.posix.join(relAuthorDir, filename)
|
||||
const imageExtension = url.toLowerCase().split('.').pop()
|
||||
const ext = imageExtension === 'png' ? 'png' : 'jpg'
|
||||
const filename = authorId + '.' + ext
|
||||
const outputPath = Path.posix.join(authorDir, filename)
|
||||
|
||||
var success = await this.downloadImage(url, outputPath)
|
||||
if (!success) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
path: outputPath,
|
||||
relPath
|
||||
}
|
||||
return downloadFile(url, outputPath).then(() => {
|
||||
return {
|
||||
path: outputPath
|
||||
}
|
||||
}).catch((err) => {
|
||||
let errorMsg = err.message || 'Unknown error'
|
||||
Logger.error(`[AuthorFinder] Download image file failed for "${url}"`, errorMsg)
|
||||
return {
|
||||
error: errorMsg
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
module.exports = new AuthorFinder()
|
Loading…
Add table
Add a link
Reference in a new issue