Update photo url input to photo path/url to be consistent with item covers

This commit is contained in:
advplyr 2022-06-18 12:05:30 -05:00
parent f79b4d44b9
commit 35ab4cb2fe
3 changed files with 22 additions and 23 deletions

View File

@ -25,8 +25,8 @@
<ui-text-input-with-label v-model="authorCopy.asin" :disabled="processing" label="ASIN" />
</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 class="p-2">
<ui-text-input-with-label v-model="authorCopy.imagePath" :disabled="processing" label="Photo Path/URL" />
</div>
<div class="p-2">
<ui-textarea-with-label v-model="authorCopy.description" :disabled="processing" label="Description" :rows="8" />
@ -46,20 +46,13 @@
<script>
export default {
// props: {
// value: Boolean,
// author: {
// type: Object,
// default: () => {}
// }
// },
data() {
return {
authorCopy: {
name: '',
asin: '',
description: '',
imageUrl: undefined
imagePath: ''
},
processing: false
}
@ -99,9 +92,10 @@ export default {
this.authorCopy.name = this.author.name
this.authorCopy.asin = this.author.asin
this.authorCopy.description = this.author.description
this.authorCopy.imagePath = this.author.imagePath
},
async submitForm() {
var keysToCheck = ['name', 'asin', 'description', 'imageUrl']
var keysToCheck = ['name', 'asin', 'description', 'imagePath']
var updatePayload = {}
keysToCheck.forEach((key) => {
if (this.authorCopy[key] !== this.author[key]) {
@ -122,7 +116,6 @@ 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

View File

@ -63,9 +63,20 @@ 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
}
}
}
@ -73,16 +84,6 @@ class AuthorController {
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))

View File

@ -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'