mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-24 04:44:57 +02:00
Remove unused old model functions
This commit is contained in:
parent
4a5f534a65
commit
920ddf43d7
16 changed files with 15 additions and 784 deletions
|
@ -1,7 +1,6 @@
|
|||
const uuidv4 = require("uuid").v4
|
||||
const fs = require('../libs/fsExtra')
|
||||
const Path = require('path')
|
||||
const { version } = require('../../package.json')
|
||||
const Logger = require('../Logger')
|
||||
const abmetadataGenerator = require('../utils/generators/abmetadataGenerator')
|
||||
const LibraryFile = require('./files/LibraryFile')
|
||||
|
@ -9,7 +8,7 @@ const Book = require('./mediaTypes/Book')
|
|||
const Podcast = require('./mediaTypes/Podcast')
|
||||
const Video = require('./mediaTypes/Video')
|
||||
const Music = require('./mediaTypes/Music')
|
||||
const { areEquivalent, copyValue, cleanStringForSearch } = require('../utils/index')
|
||||
const { areEquivalent, copyValue } = require('../utils/index')
|
||||
const { filePathToPOSIX, getFileTimestampsWithIno } = require('../utils/fileUtils')
|
||||
|
||||
class LibraryItem {
|
||||
|
@ -180,34 +179,23 @@ class LibraryItem {
|
|||
this.libraryFiles.forEach((lf) => total += lf.metadata.size)
|
||||
return total
|
||||
}
|
||||
get audioFileTotalSize() {
|
||||
let total = 0
|
||||
this.libraryFiles.filter(lf => lf.fileType == 'audio').forEach((lf) => total += lf.metadata.size)
|
||||
return total
|
||||
}
|
||||
get hasAudioFiles() {
|
||||
return this.libraryFiles.some(lf => lf.fileType === 'audio')
|
||||
}
|
||||
get hasMediaEntities() {
|
||||
return this.media.hasMediaEntities
|
||||
}
|
||||
get hasIssues() {
|
||||
if (this.isMissing || this.isInvalid) return true
|
||||
return this.media.hasIssues
|
||||
}
|
||||
|
||||
// Data comes from scandir library item data
|
||||
// TODO: Remove this function. Only used when creating a new podcast now
|
||||
setData(libraryMediaType, payload) {
|
||||
this.id = uuidv4()
|
||||
this.mediaType = libraryMediaType
|
||||
if (libraryMediaType === 'video') {
|
||||
this.media = new Video()
|
||||
} else if (libraryMediaType === 'podcast') {
|
||||
if (libraryMediaType === 'podcast') {
|
||||
this.media = new Podcast()
|
||||
} else if (libraryMediaType === 'book') {
|
||||
this.media = new Book()
|
||||
} else if (libraryMediaType === 'music') {
|
||||
this.media = new Music()
|
||||
} else {
|
||||
Logger.error(`[LibraryItem] setData called with unsupported media type "${libraryMediaType}"`)
|
||||
return
|
||||
}
|
||||
this.media.id = uuidv4()
|
||||
this.media.libraryItemId = this.id
|
||||
|
@ -270,85 +258,13 @@ class LibraryItem {
|
|||
this.updatedAt = Date.now()
|
||||
}
|
||||
|
||||
setInvalid() {
|
||||
this.isInvalid = true
|
||||
this.updatedAt = Date.now()
|
||||
}
|
||||
|
||||
setLastScan() {
|
||||
this.lastScan = Date.now()
|
||||
this.updatedAt = Date.now()
|
||||
this.scanVersion = version
|
||||
}
|
||||
|
||||
// Returns null if file not found, true if file was updated, false if up to date
|
||||
// updates existing LibraryFile, AudioFile, EBookFile's
|
||||
checkFileFound(fileFound) {
|
||||
let hasUpdated = false
|
||||
|
||||
let existingFile = this.libraryFiles.find(lf => lf.ino === fileFound.ino)
|
||||
let mediaFile = null
|
||||
if (!existingFile) {
|
||||
existingFile = this.libraryFiles.find(lf => lf.metadata.path === fileFound.metadata.path)
|
||||
if (existingFile) {
|
||||
// Update media file ino
|
||||
mediaFile = this.media.findFileWithInode(existingFile.ino)
|
||||
if (mediaFile) {
|
||||
mediaFile.ino = fileFound.ino
|
||||
}
|
||||
|
||||
// file inode was updated
|
||||
existingFile.ino = fileFound.ino
|
||||
hasUpdated = true
|
||||
} else {
|
||||
// file not found
|
||||
return null
|
||||
}
|
||||
} else {
|
||||
mediaFile = this.media.findFileWithInode(existingFile.ino)
|
||||
}
|
||||
|
||||
if (existingFile.metadata.path !== fileFound.metadata.path) {
|
||||
existingFile.metadata.path = fileFound.metadata.path
|
||||
existingFile.metadata.relPath = fileFound.metadata.relPath
|
||||
if (mediaFile) {
|
||||
mediaFile.metadata.path = fileFound.metadata.path
|
||||
mediaFile.metadata.relPath = fileFound.metadata.relPath
|
||||
}
|
||||
hasUpdated = true
|
||||
}
|
||||
|
||||
// FileMetadata keys
|
||||
['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size'].forEach((key) => {
|
||||
if (existingFile.metadata[key] !== fileFound.metadata[key]) {
|
||||
// Add modified flag on file data object if exists and was changed
|
||||
if (key === 'mtimeMs' && existingFile.metadata[key]) {
|
||||
fileFound.metadata.wasModified = true
|
||||
}
|
||||
|
||||
existingFile.metadata[key] = fileFound.metadata[key]
|
||||
if (mediaFile) {
|
||||
if (key === 'mtimeMs') mediaFile.metadata.wasModified = true
|
||||
mediaFile.metadata[key] = fileFound.metadata[key]
|
||||
}
|
||||
hasUpdated = true
|
||||
}
|
||||
})
|
||||
|
||||
return hasUpdated
|
||||
}
|
||||
|
||||
searchQuery(query) {
|
||||
query = cleanStringForSearch(query)
|
||||
return this.media.searchQuery(query)
|
||||
}
|
||||
|
||||
getDirectPlayTracklist(episodeId) {
|
||||
return this.media.getDirectPlayTracklist(episodeId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Save metadata.json/metadata.abs file
|
||||
* TODO: Move to new LibraryItem model
|
||||
* @returns {Promise<LibraryFile>} null if not saved
|
||||
*/
|
||||
async saveMetadata() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue