Add author edit modal & remove from experimental

This commit is contained in:
advplyr 2022-03-14 18:53:49 -05:00
parent deea6702f0
commit 4c2ad3ede5
26 changed files with 344 additions and 131 deletions

View file

@ -152,6 +152,7 @@ class ApiController {
//
this.router.get('/authors/search', AuthorController.search.bind(this))
this.router.get('/authors/:id', AuthorController.middleware.bind(this), AuthorController.findOne.bind(this))
this.router.patch('/authors/:id', AuthorController.middleware.bind(this), AuthorController.update.bind(this))
this.router.post('/authors/:id/match', AuthorController.middleware.bind(this), AuthorController.match.bind(this))
this.router.get('/authors/:id/image', AuthorController.middleware.bind(this), AuthorController.getImage.bind(this))

View file

@ -43,13 +43,21 @@ class CacheManager {
readStream.pipe(res)
}
async purgeCoverCache(libraryItemId) {
purgeCoverCache(libraryItemId) {
return this.purgeEntityCache(libraryItemId, this.CoverCachePath)
}
purgeImageCache(entityId) {
return this.purgeEntityCache(entityId, this.ImageCachePath)
}
async purgeEntityCache(entityId, cachePath) {
// If purgeAll has been called... The cover cache directory no longer exists
await fs.ensureDir(this.CoverCachePath)
return Promise.all((await fs.readdir(this.CoverCachePath)).reduce((promises, file) => {
if (file.startsWith(libraryItemId)) {
await fs.ensureDir(cachePath)
return Promise.all((await fs.readdir(cachePath)).reduce((promises, file) => {
if (file.startsWith(entityId)) {
Logger.debug(`[CacheManager] Going to purge ${file}`);
promises.push(this.removeCache(Path.join(this.CoverCachePath, file)))
promises.push(this.removeCache(Path.join(cachePath, file)))
}
return promises
}, []))

View file

@ -248,6 +248,5 @@ class CoverController {
}
return false
}
}
module.exports = CoverController

View file

@ -8,6 +8,29 @@ class AuthorController {
return res.json(req.author)
}
async update(req, res) {
var payload = req.body
// If updating or removing cover image then clear cache
if (payload.imagePath !== undefined && req.author.imagePath && payload.imagePath !== req.author.imagePath) {
this.cacheManager.purgeImageCache(req.author.id)
if (!payload.imagePath) { // If removing image then remove file
var currentImagePath = req.author.imagePath
await this.coverController.removeFile(currentImagePath)
}
}
var hasUpdated = req.author.update(payload)
if (hasUpdated) {
await this.db.updateEntity('author', req.author)
this.emitter('author_updated', req.author.toJSON())
}
res.json({
author: req.author.toJSON(),
updated: hasUpdated
})
}
async search(req, res) {
var q = (req.query.q || '').toLowerCase()
if (!q) return res.json([])

View file

@ -64,6 +64,21 @@ class Author {
this.updatedAt = Date.now()
}
update(payload) {
var json = this.toJSON()
delete json.id
delete json.addedAt
delete json.updatedAt
var hasUpdates = false
for (const key in json) {
if (payload[key] !== undefined && json[key] != payload[key]) {
this[key] = payload[key]
hasUpdates = true
}
}
return hasUpdates
}
checkNameEquals(name) {
if (!name) return false
return this.name.toLowerCase() == name.toLowerCase().trim()