New data model authors routes

This commit is contained in:
advplyr 2022-03-13 06:42:43 -05:00
parent 65df377a49
commit dad12537b6
6 changed files with 102 additions and 65 deletions

View file

@ -31,6 +31,27 @@ class AuthorFinder {
return author
}
async saveAuthorImage(authorId, url) {
var authorDir = this.AuthorPath
var relAuthorDir = Path.posix.join('/metadata', 'authors')
await fs.ensureDir(authorDir)
var imageExtension = url.toLowerCase().split('.').pop()
var ext = imageExtension === 'png' ? 'png' : 'jpg'
var filename = authorId + '.' + ext
var outputPath = Path.posix.join(authorDir, filename)
var relPath = Path.posix.join(relAuthorDir, filename)
var success = await this.downloadImage(url, outputPath)
if (!success) {
return null
}
return {
path: outputPath,
relPath
}
}
async createAuthor(payload) {
if (!payload || !payload.name) return null