2022-03-09 02:31:44 +01:00
|
|
|
const BookMetadata = require('../metadata/BookMetadata')
|
|
|
|
const AudioFile = require('../files/AudioFile')
|
|
|
|
const EBookFile = require('../files/EBookFile')
|
|
|
|
|
|
|
|
class Book {
|
|
|
|
constructor(book) {
|
|
|
|
this.metadata = null
|
|
|
|
|
2022-03-10 02:23:17 +01:00
|
|
|
this.coverPath = null
|
|
|
|
this.relCoverPath = null
|
2022-03-09 02:31:44 +01:00
|
|
|
this.tags = []
|
|
|
|
this.audioFiles = []
|
|
|
|
this.ebookFiles = []
|
|
|
|
this.chapters = []
|
|
|
|
|
2022-03-10 02:23:17 +01:00
|
|
|
if (book) {
|
2022-03-09 02:31:44 +01:00
|
|
|
this.construct(book)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(book) {
|
|
|
|
this.metadata = new BookMetadata(book.metadata)
|
2022-03-10 02:23:17 +01:00
|
|
|
this.coverPath = book.coverPath
|
|
|
|
this.relCoverPath = book.relCoverPath
|
2022-03-09 02:31:44 +01:00
|
|
|
this.tags = [...book.tags]
|
|
|
|
this.audioFiles = book.audioFiles.map(f => new AudioFile(f))
|
|
|
|
this.ebookFiles = book.ebookFiles.map(f => new EBookFile(f))
|
|
|
|
this.chapters = book.chapters.map(c => ({ ...c }))
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
metadata: this.metadata.toJSON(),
|
2022-03-10 02:23:17 +01:00
|
|
|
coverPath: this.coverPath,
|
|
|
|
relCoverPath: this.relCoverPath,
|
2022-03-09 02:31:44 +01:00
|
|
|
tags: [...this.tags],
|
|
|
|
audioFiles: this.audioFiles.map(f => f.toJSON()),
|
|
|
|
ebookFiles: this.ebookFiles.map(f => f.toJSON()),
|
|
|
|
chapters: this.chapters.map(c => ({ ...c }))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Book
|