diff --git a/client/components/modals/authors/EditModal.vue b/client/components/modals/authors/EditModal.vue index 3657bc85..84c20399 100644 --- a/client/components/modals/authors/EditModal.vue +++ b/client/components/modals/authors/EditModal.vue @@ -25,6 +25,9 @@ +
+ +
@@ -43,19 +46,13 @@ + \ No newline at end of file diff --git a/server/controllers/AuthorController.js b/server/controllers/AuthorController.js index 71ca67cf..419f2477 100644 --- a/server/controllers/AuthorController.js +++ b/server/controllers/AuthorController.js @@ -63,15 +63,27 @@ class AuthorController { // 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.coverManager.removeFile(currentImagePath) + } else if (payload.imagePath.startsWith('http')) { // Check if image path is a url + var imageData = await this.authorFinder.saveAuthorImage(req.author.id, payload.imagePath) + if (imageData) { + req.author.imagePath = imageData.path + req.author.relImagePath = imageData.relPath + hasUpdated = hasUpdated || true; + } else { + req.author.imagePath = null + req.author.relImagePath = null + } } } var authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name var hasUpdated = req.author.update(payload) + if (hasUpdated) { if (authorNameUpdate) { // Update author name on all books var itemsWithAuthor = this.db.libraryItems.filter(li => li.mediaType === 'book' && li.media.metadata.hasAuthor(req.author.id)) diff --git a/server/finders/AuthorFinder.js b/server/finders/AuthorFinder.js index 04308012..aac7150c 100644 --- a/server/finders/AuthorFinder.js +++ b/server/finders/AuthorFinder.js @@ -4,6 +4,7 @@ const Path = require('path') const Audnexus = require('../providers/Audnexus') const { downloadFile } = require('../utils/fileUtils') +const filePerms = require('../utils/filePerms') class AuthorFinder { constructor() { @@ -38,7 +39,11 @@ class AuthorFinder { async saveAuthorImage(authorId, url) { var authorDir = this.AuthorPath var relAuthorDir = Path.posix.join('/metadata', 'authors') - await fs.ensureDir(authorDir) + + if (!await fs.pathExists(authorDir)) { + await fs.ensureDir(authorDir) + await filePerms.setDefault(authorDir) + } var imageExtension = url.toLowerCase().split('.').pop() var ext = imageExtension === 'png' ? 'png' : 'jpg'