2022-03-09 02:31:44 +01:00
|
|
|
const FileMetadata = require('../metadata/FileMetadata')
|
|
|
|
|
|
|
|
class EBookFile {
|
|
|
|
constructor(file) {
|
|
|
|
this.ino = null
|
|
|
|
this.metadata = null
|
|
|
|
this.ebookFormat = null
|
|
|
|
this.addedAt = null
|
2022-03-10 02:23:17 +01:00
|
|
|
this.updatedAt = null
|
2022-03-09 02:31:44 +01:00
|
|
|
|
|
|
|
if (file) {
|
|
|
|
this.construct(file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(file) {
|
|
|
|
this.ino = file.ino
|
2022-03-18 18:37:47 +01:00
|
|
|
this.metadata = new FileMetadata(file.metadata)
|
2022-03-09 02:31:44 +01:00
|
|
|
this.ebookFormat = file.ebookFormat
|
|
|
|
this.addedAt = file.addedAt
|
2022-03-10 02:23:17 +01:00
|
|
|
this.updatedAt = file.updatedAt
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
ino: this.ino,
|
|
|
|
metadata: this.metadata.toJSON(),
|
|
|
|
ebookFormat: this.ebookFormat,
|
|
|
|
addedAt: this.addedAt,
|
2022-03-10 02:23:17 +01:00
|
|
|
updatedAt: this.updatedAt
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-13 19:47:36 +01:00
|
|
|
|
|
|
|
setData(libraryFile) {
|
|
|
|
this.ino = libraryFile.ino
|
|
|
|
this.metadata = libraryFile.metadata.clone()
|
|
|
|
this.ebookFormat = libraryFile.metadata.format
|
|
|
|
this.addedAt = Date.now()
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFromLibraryFile(libraryFile) {
|
|
|
|
var hasUpdated = false
|
|
|
|
|
|
|
|
if (this.metadata.update(libraryFile.metadata)) {
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.ebookFormat !== libraryFile.metadata.format) {
|
|
|
|
this.ebookFormat = libraryFile.metadata.format
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasUpdated
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = EBookFile
|