Removing remaining legacy objects, remove njodb error for fileExists

This commit is contained in:
advplyr 2022-04-10 10:05:05 -05:00
parent 99e2ea228d
commit c60807f998
15 changed files with 18 additions and 2602 deletions

View file

@ -1,7 +1,6 @@
const fs = require('fs-extra')
const Logger = require('../Logger')
const Path = require('path')
const Author = require('../objects/legacy/Author')
const Audnexus = require('../providers/Audnexus')
const { downloadFile } = require('../utils/fileUtils')
@ -51,80 +50,5 @@ class AuthorFinder {
relPath
}
}
async createAuthor(payload) {
if (!payload || !payload.name) return null
var authorDir = Path.posix.join(this.AuthorPath, payload.name)
var relAuthorDir = Path.posix.join('/metadata', 'authors', payload.name)
if (payload.image && payload.image.startsWith('http')) {
await fs.ensureDir(authorDir)
var imageExtension = payload.image.toLowerCase().split('.').pop()
var ext = imageExtension === 'png' ? 'png' : 'jpg'
var filename = 'photo.' + ext
var outputPath = Path.posix.join(authorDir, filename)
var relPath = Path.posix.join(relAuthorDir, filename)
var success = await this.downloadImage(payload.image, outputPath)
if (!success) {
await fs.rmdir(authorDir).catch((error) => {
Logger.error(`[AuthorFinder] Failed to remove author dir`, authorDir, error)
})
payload.image = null
payload.imageFullPath = null
} else {
payload.image = relPath
payload.imageFullPath = outputPath
}
} else {
payload.image = null
payload.imageFullPath = null
}
var author = new Author()
author.setData(payload)
return author
}
async getAuthorByName(name, options = {}) {
var authorData = await this.findAuthorByName(name, options)
if (!authorData) return null
var authorDir = Path.posix.join(this.AuthorPath, authorData.name)
var relAuthorDir = Path.posix.join('/metadata', 'authors', authorData.name)
if (authorData.image) {
await fs.ensureDir(authorDir)
var imageExtension = authorData.image.toLowerCase().split('.').pop()
var ext = imageExtension === 'png' ? 'png' : 'jpg'
var filename = 'photo.' + ext
var outputPath = Path.posix.join(authorDir, filename)
var relPath = Path.posix.join(relAuthorDir, filename)
var success = await this.downloadImage(authorData.image, outputPath)
if (!success) {
await fs.rmdir(authorDir).catch((error) => {
Logger.error(`[AuthorFinder] Failed to remove author dir`, authorDir, error)
})
authorData.image = null
authorData.imageFullPath = null
} else {
authorData.image = relPath
authorData.imageFullPath = outputPath
}
} else {
authorData.image = null
authorData.imageFullPath = null
}
var author = new Author()
author.setData(authorData)
return author
}
}
module.exports = AuthorFinder