mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-29 20:15:04 +02:00
Add: author object, author search api, author images #187
This commit is contained in:
parent
979fb70c31
commit
5308801540
15 changed files with 772 additions and 31 deletions
|
@ -7,6 +7,7 @@ const imageType = require('image-type')
|
|||
|
||||
const globals = require('./utils/globals')
|
||||
const { CoverDestination } = require('./utils/constants')
|
||||
const { downloadFile } = require('./utils/fileUtils')
|
||||
|
||||
class CoverController {
|
||||
constructor(db, MetadataPath, AudiobookPath) {
|
||||
|
@ -123,28 +124,13 @@ class CoverController {
|
|||
}
|
||||
}
|
||||
|
||||
async downloadFile(url, filepath) {
|
||||
Logger.debug(`[CoverController] Starting file download to ${filepath}`)
|
||||
const writer = fs.createWriteStream(filepath)
|
||||
const response = await axios({
|
||||
url,
|
||||
method: 'GET',
|
||||
responseType: 'stream'
|
||||
})
|
||||
response.data.pipe(writer)
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on('finish', resolve)
|
||||
writer.on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
async downloadCoverFromUrl(audiobook, url) {
|
||||
try {
|
||||
var { fullPath, relPath } = this.getCoverDirectory(audiobook)
|
||||
await fs.ensureDir(fullPath)
|
||||
|
||||
var temppath = Path.posix.join(fullPath, 'cover')
|
||||
var success = await this.downloadFile(url, temppath).then(() => true).catch((err) => {
|
||||
var success = await downloadFile(url, temppath).then(() => true).catch((err) => {
|
||||
Logger.error(`[CoverController] Download image file failed for "${url}"`, err)
|
||||
return false
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue