From f79b4d44b93b85fa2f9b05db9149f2167d5a1af9 Mon Sep 17 00:00:00 2001 From: mrdth Date: Sat, 18 Jun 2022 17:04:38 +0100 Subject: [PATCH 1/2] Fetch author photo from external URL Add a new text field 'Photo URL' on the author edit modal, if there is no existing image for an author. When submitted, the image is saved from the URL provided --- client/components/modals/authors/EditModal.vue | 11 ++++++++--- server/controllers/AuthorController.js | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/components/modals/authors/EditModal.vue b/client/components/modals/authors/EditModal.vue index 3657bc85..4b222904 100644 --- a/client/components/modals/authors/EditModal.vue +++ b/client/components/modals/authors/EditModal.vue @@ -25,6 +25,9 @@ +
+ +
@@ -55,7 +58,8 @@ export default { authorCopy: { name: '', asin: '', - description: '' + description: '', + imageUrl: undefined }, processing: false } @@ -97,7 +101,7 @@ export default { this.authorCopy.description = this.author.description }, async submitForm() { - var keysToCheck = ['name', 'asin', 'description'] + var keysToCheck = ['name', 'asin', 'description', 'imageUrl'] var updatePayload = {} keysToCheck.forEach((key) => { if (this.authorCopy[key] !== this.author[key]) { @@ -118,6 +122,7 @@ export default { if (result.updated) { this.$toast.success('Author updated') this.show = false + this.authorCopy.imageUrl = undefined } else this.$toast.info('No updates were needed') } this.processing = false @@ -167,4 +172,4 @@ export default { mounted() {}, beforeDestroy() {} } - + \ No newline at end of file diff --git a/server/controllers/AuthorController.js b/server/controllers/AuthorController.js index 71ca67cf..97082ca2 100644 --- a/server/controllers/AuthorController.js +++ b/server/controllers/AuthorController.js @@ -72,6 +72,17 @@ class AuthorController { var authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name var hasUpdated = req.author.update(payload) + + // Fetch author image from remote URL if no current image exists + if (payload.imageUrl !== undefined && !req.author.imagePath) { + var imageData = await this.authorFinder.saveAuthorImage(req.author.id, payload.imageUrl) + if (imageData) { + req.author.imagePath = imageData.path + req.author.relImagePath = imageData.relPath + hasUpdated = hasUpdated || true; + } + } + 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)) From 35ab4cb2fe30d08395de647716b412bb08127af1 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 18 Jun 2022 12:05:30 -0500 Subject: [PATCH 2/2] Update photo url input to photo path/url to be consistent with item covers --- .../components/modals/authors/EditModal.vue | 17 +++++---------- server/controllers/AuthorController.js | 21 ++++++++++--------- server/finders/AuthorFinder.js | 7 ++++++- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/client/components/modals/authors/EditModal.vue b/client/components/modals/authors/EditModal.vue index 4b222904..84c20399 100644 --- a/client/components/modals/authors/EditModal.vue +++ b/client/components/modals/authors/EditModal.vue @@ -25,8 +25,8 @@ -
- +
+
@@ -46,20 +46,13 @@