mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const globals = require('../../utils/globals')
|
|
const FileMetadata = require('../metadata/FileMetadata')
|
|
|
|
class LibraryFile {
|
|
constructor(file) {
|
|
this.ino = null
|
|
this.metadata = null
|
|
this.addedAt = null
|
|
this.updatedAt = null
|
|
|
|
if (file) {
|
|
this.construct(file)
|
|
}
|
|
}
|
|
|
|
construct(file) {
|
|
this.ino = file.ino
|
|
this.metadata = new FileMetadata(file.metadata)
|
|
this.addedAt = file.addedAt
|
|
this.updatedAt = file.updatedAt
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
ino: this.ino,
|
|
metadata: this.metadata.toJSON(),
|
|
addedAt: this.addedAt,
|
|
updatedAt: this.updatedAt,
|
|
fileType: this.fileType
|
|
}
|
|
}
|
|
|
|
get fileType() {
|
|
if (globals.SupportedImageTypes.includes(this.metadata.format)) return 'image'
|
|
if (globals.SupportedAudioTypes.includes(this.metadata.format)) return 'audio'
|
|
if (globals.SupportedEbookTypes.includes(this.metadata.format)) return 'ebook'
|
|
if (globals.TextFileTypes.includes(this.metadata.format)) return 'text'
|
|
if (globals.MetadataFileTypes.includes(this.metadata.format)) return 'metadata'
|
|
return 'unknown'
|
|
}
|
|
}
|
|
module.exports = LibraryFile |