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
This commit is contained in:
mrdth 2022-06-18 17:04:38 +01:00
parent 578bb03404
commit f79b4d44b9
2 changed files with 19 additions and 3 deletions

View File

@ -25,6 +25,9 @@
<ui-text-input-with-label v-model="authorCopy.asin" :disabled="processing" label="ASIN" /> <ui-text-input-with-label v-model="authorCopy.asin" :disabled="processing" label="ASIN" />
</div> </div>
</div> </div>
<div class="p-2" v-show="!author.imagePath">
<ui-text-input-with-label v-model="authorCopy.imageUrl" :disabled="processing" label="Photo URL" />
</div>
<div class="p-2"> <div class="p-2">
<ui-textarea-with-label v-model="authorCopy.description" :disabled="processing" label="Description" :rows="8" /> <ui-textarea-with-label v-model="authorCopy.description" :disabled="processing" label="Description" :rows="8" />
</div> </div>
@ -55,7 +58,8 @@ export default {
authorCopy: { authorCopy: {
name: '', name: '',
asin: '', asin: '',
description: '' description: '',
imageUrl: undefined
}, },
processing: false processing: false
} }
@ -97,7 +101,7 @@ export default {
this.authorCopy.description = this.author.description this.authorCopy.description = this.author.description
}, },
async submitForm() { async submitForm() {
var keysToCheck = ['name', 'asin', 'description'] var keysToCheck = ['name', 'asin', 'description', 'imageUrl']
var updatePayload = {} var updatePayload = {}
keysToCheck.forEach((key) => { keysToCheck.forEach((key) => {
if (this.authorCopy[key] !== this.author[key]) { if (this.authorCopy[key] !== this.author[key]) {
@ -118,6 +122,7 @@ export default {
if (result.updated) { if (result.updated) {
this.$toast.success('Author updated') this.$toast.success('Author updated')
this.show = false this.show = false
this.authorCopy.imageUrl = undefined
} else this.$toast.info('No updates were needed') } else this.$toast.info('No updates were needed')
} }
this.processing = false this.processing = false

View File

@ -72,6 +72,17 @@ class AuthorController {
var authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name var authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name
var hasUpdated = req.author.update(payload) 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 (hasUpdated) {
if (authorNameUpdate) { // Update author name on all books 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)) var itemsWithAuthor = this.db.libraryItems.filter(li => li.mediaType === 'book' && li.media.metadata.hasAuthor(req.author.id))