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

@ -63,9 +63,20 @@ class AuthorController {
// If updating or removing cover image then clear cache // If updating or removing cover image then clear cache
if (payload.imagePath !== undefined && req.author.imagePath && payload.imagePath !== req.author.imagePath) { if (payload.imagePath !== undefined && req.author.imagePath && payload.imagePath !== req.author.imagePath) {
this.cacheManager.purgeImageCache(req.author.id) this.cacheManager.purgeImageCache(req.author.id)
if (!payload.imagePath) { // If removing image then remove file if (!payload.imagePath) { // If removing image then remove file
var currentImagePath = req.author.imagePath var currentImagePath = req.author.imagePath
await this.coverManager.removeFile(currentImagePath) 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) 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))

View File

@ -4,6 +4,7 @@ const Path = require('path')
const Audnexus = require('../providers/Audnexus') const Audnexus = require('../providers/Audnexus')
const { downloadFile } = require('../utils/fileUtils') const { downloadFile } = require('../utils/fileUtils')
const filePerms = require('../utils/filePerms')
class AuthorFinder { class AuthorFinder {
constructor() { constructor() {
@ -38,7 +39,11 @@ class AuthorFinder {
async saveAuthorImage(authorId, url) { async saveAuthorImage(authorId, url) {
var authorDir = this.AuthorPath var authorDir = this.AuthorPath
var relAuthorDir = Path.posix.join('/metadata', 'authors') 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 imageExtension = url.toLowerCase().split('.').pop()
var ext = imageExtension === 'png' ? 'png' : 'jpg' var ext = imageExtension === 'png' ? 'png' : 'jpg'