Add:Authors page match authors and display author image

This commit is contained in:
advplyr 2022-03-13 10:35:35 -05:00
parent dad12537b6
commit 30f15d3575
9 changed files with 432 additions and 285 deletions

View file

@ -8,6 +8,7 @@ class CacheManager {
constructor() {
this.CachePath = Path.join(global.MetadataPath, 'cache')
this.CoverCachePath = Path.join(this.CachePath, 'covers')
this.ImageCachePath = Path.join(this.CachePath, 'images')
}
async handleCoverCache(res, libraryItem, options = {}) {
@ -72,5 +73,37 @@ class CacheManager {
})
}
}
async handleAuthorCache(res, author, options = {}) {
const format = options.format || 'webp'
const width = options.width || 400
const height = options.height || null
res.type(`image/${format}`)
var path = Path.join(this.ImageCachePath, `${author.id}_${width}${height ? `x${height}` : ''}`) + '.' + format
// Cache exists
if (await fs.pathExists(path)) {
const r = fs.createReadStream(path)
const ps = new stream.PassThrough()
stream.pipeline(r, ps, (err) => {
if (err) {
console.log(err)
return res.sendStatus(400)
}
})
return ps.pipe(res)
}
// Write cache
await fs.ensureDir(this.ImageCachePath)
let writtenFile = await resizeImage(author.imagePath, path, width, height)
if (!writtenFile) return res.sendStatus(400)
var readStream = fs.createReadStream(writtenFile)
readStream.pipe(res)
}
}
module.exports = CacheManager