mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-04 01:09:40 +00:00
Add: author object, author search api, author images #187
This commit is contained in:
parent
979fb70c31
commit
5308801540
15 changed files with 772 additions and 31 deletions
72
server/objects/Author.js
Normal file
72
server/objects/Author.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
const { getId } = require('../utils/index')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class Author {
|
||||
constructor(author = null) {
|
||||
this.id = null
|
||||
this.name = null
|
||||
this.description = null
|
||||
this.asin = null
|
||||
this.image = null
|
||||
this.imageFullPath = null
|
||||
|
||||
this.createdAt = null
|
||||
this.lastUpdate = null
|
||||
|
||||
if (author) {
|
||||
this.construct(author)
|
||||
}
|
||||
}
|
||||
|
||||
construct(author) {
|
||||
this.id = author.id
|
||||
this.name = author.name
|
||||
this.description = author.description
|
||||
this.asin = author.asin
|
||||
this.image = author.image
|
||||
this.imageFullPath = author.imageFullPath
|
||||
|
||||
this.createdAt = author.createdAt
|
||||
this.lastUpdate = author.lastUpdate
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
asin: this.asin,
|
||||
image: this.image,
|
||||
imageFullPath: this.imageFullPath,
|
||||
createdAt: this.createdAt,
|
||||
lastUpdate: this.lastUpdate
|
||||
}
|
||||
}
|
||||
|
||||
setData(data) {
|
||||
this.id = data.id ? data.id : getId('per')
|
||||
this.name = data.name
|
||||
this.description = data.description
|
||||
this.asin = data.asin || null
|
||||
this.image = data.image || null
|
||||
this.imageFullPath = data.imageFullPath || null
|
||||
this.createdAt = Date.now()
|
||||
this.lastUpdate = Date.now()
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var hasUpdates = false
|
||||
for (const key in payload) {
|
||||
if (this[key] === undefined) continue;
|
||||
if (this[key] !== payload[key]) {
|
||||
hasUpdates = true
|
||||
this[key] = payload[key]
|
||||
}
|
||||
}
|
||||
if (hasUpdates) {
|
||||
this.lastUpdate = Date.now()
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
}
|
||||
module.exports = Author
|
||||
|
|
@ -9,6 +9,7 @@ class Book {
|
|||
this.author = null
|
||||
this.authorFL = null
|
||||
this.authorLF = null
|
||||
this.authors = []
|
||||
this.narrator = null
|
||||
this.series = null
|
||||
this.volumeNumber = null
|
||||
|
|
@ -51,6 +52,7 @@ class Book {
|
|||
this.title = book.title
|
||||
this.subtitle = book.subtitle || null
|
||||
this.author = book.author
|
||||
this.authors = (book.authors || []).map(a => ({ ...a }))
|
||||
this.authorFL = book.authorFL || null
|
||||
this.authorLF = book.authorLF || null
|
||||
this.narrator = book.narrator || book.narrarator || null // Mispelled initially... need to catch those
|
||||
|
|
@ -81,6 +83,7 @@ class Book {
|
|||
title: this.title,
|
||||
subtitle: this.subtitle,
|
||||
author: this.author,
|
||||
authors: this.authors,
|
||||
authorFL: this.authorFL,
|
||||
authorLF: this.authorLF,
|
||||
narrator: this.narrator,
|
||||
|
|
@ -142,6 +145,7 @@ class Book {
|
|||
this.title = data.title || null
|
||||
this.subtitle = data.subtitle || null
|
||||
this.author = data.author || null
|
||||
this.authors = data.authors || []
|
||||
this.narrator = data.narrator || data.narrarator || null
|
||||
this.series = data.series || null
|
||||
this.volumeNumber = data.volumeNumber || null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue