Remove old library, folder and librarysettings model

This commit is contained in:
advplyr 2024-08-28 17:26:23 -05:00
parent fd827b2214
commit c45c82306e
11 changed files with 115 additions and 405 deletions

View file

@ -1,38 +0,0 @@
const uuidv4 = require("uuid").v4
class Folder {
constructor(folder = null) {
this.id = null
this.fullPath = null
this.libraryId = null
this.addedAt = null
if (folder) {
this.construct(folder)
}
}
construct(folder) {
this.id = folder.id
this.fullPath = folder.fullPath
this.libraryId = folder.libraryId
this.addedAt = folder.addedAt
}
toJSON() {
return {
id: this.id,
fullPath: this.fullPath,
libraryId: this.libraryId,
addedAt: this.addedAt
}
}
setData(data) {
this.id = data.id || uuidv4()
this.fullPath = data.fullPath
this.libraryId = data.libraryId
this.addedAt = Date.now()
}
}
module.exports = Folder

View file

@ -1,95 +0,0 @@
const Folder = require('./Folder')
const LibrarySettings = require('./settings/LibrarySettings')
const { filePathToPOSIX } = require('../utils/fileUtils')
class Library {
constructor(library = null) {
this.id = null
this.oldLibraryId = null // TODO: Temp
this.name = null
this.folders = []
this.displayOrder = 1
this.icon = 'database'
this.mediaType = 'book' // book, podcast
this.provider = 'google'
this.lastScan = 0
this.lastScanVersion = null
this.lastScanMetadataPrecedence = null
this.settings = null
this.createdAt = null
this.lastUpdate = null
if (library) {
this.construct(library)
}
}
get isPodcast() {
return this.mediaType === 'podcast'
}
get isBook() {
return this.mediaType === 'book'
}
construct(library) {
this.id = library.id
this.oldLibraryId = library.oldLibraryId
this.name = library.name
this.folders = (library.folders || []).map((f) => new Folder(f))
this.displayOrder = library.displayOrder || 1
this.icon = library.icon || 'database'
this.mediaType = library.mediaType
this.provider = library.provider || 'google'
this.settings = new LibrarySettings(library.settings)
if (library.settings === undefined) {
// LibrarySettings added in v2, migrate settings
this.settings.disableWatcher = !!library.disableWatcher
}
this.lastScan = library.lastScan
this.lastScanVersion = library.lastScanVersion
this.lastScanMetadataPrecedence = library.lastScanMetadataPrecedence
this.createdAt = library.createdAt
this.lastUpdate = library.lastUpdate
this.cleanOldValues() // mediaType changed for v2 and icon change for v2.2.2
}
cleanOldValues() {
const availableIcons = ['database', 'audiobookshelf', 'books-1', 'books-2', 'book-1', 'microphone-1', 'microphone-3', 'radio', 'podcast', 'rss', 'headphones', 'music', 'file-picture', 'rocket', 'power', 'star', 'heart']
if (!availableIcons.includes(this.icon)) {
if (this.icon === 'audiobook') this.icon = 'audiobookshelf'
else if (this.icon === 'book') this.icon = 'books-1'
else if (this.icon === 'comic') this.icon = 'file-picture'
else this.icon = 'database'
}
const mediaTypes = ['podcast', 'book', 'video', 'music']
if (!this.mediaType || !mediaTypes.includes(this.mediaType)) {
this.mediaType = 'book'
}
}
toJSON() {
return {
id: this.id,
oldLibraryId: this.oldLibraryId,
name: this.name,
folders: (this.folders || []).map((f) => f.toJSON()),
displayOrder: this.displayOrder,
icon: this.icon,
mediaType: this.mediaType,
provider: this.provider,
settings: this.settings.toJSON(),
lastScan: this.lastScan,
lastScanVersion: this.lastScanVersion,
createdAt: this.createdAt,
lastUpdate: this.lastUpdate
}
}
}
module.exports = Library

View file

@ -1,73 +0,0 @@
const { BookCoverAspectRatio } = require('../../utils/constants')
class LibrarySettings {
constructor(settings) {
this.coverAspectRatio = BookCoverAspectRatio.SQUARE
this.disableWatcher = false
this.skipMatchingMediaWithAsin = false
this.skipMatchingMediaWithIsbn = false
this.autoScanCronExpression = null
this.audiobooksOnly = false
this.epubsAllowScriptedContent = false
this.hideSingleBookSeries = false // Do not show series that only have 1 book
this.onlyShowLaterBooksInContinueSeries = false // Skip showing books that are earlier than the max sequence read
this.metadataPrecedence = ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata']
this.podcastSearchRegion = 'us'
if (settings) {
this.construct(settings)
}
}
construct(settings) {
this.coverAspectRatio = !isNaN(settings.coverAspectRatio) ? settings.coverAspectRatio : BookCoverAspectRatio.SQUARE
this.disableWatcher = !!settings.disableWatcher
this.skipMatchingMediaWithAsin = !!settings.skipMatchingMediaWithAsin
this.skipMatchingMediaWithIsbn = !!settings.skipMatchingMediaWithIsbn
this.autoScanCronExpression = settings.autoScanCronExpression || null
this.audiobooksOnly = !!settings.audiobooksOnly
this.epubsAllowScriptedContent = !!settings.epubsAllowScriptedContent
this.hideSingleBookSeries = !!settings.hideSingleBookSeries
this.onlyShowLaterBooksInContinueSeries = !!settings.onlyShowLaterBooksInContinueSeries
if (settings.metadataPrecedence) {
this.metadataPrecedence = [...settings.metadataPrecedence]
} else {
// Added in v2.4.5
this.metadataPrecedence = ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata']
}
this.podcastSearchRegion = settings.podcastSearchRegion || 'us'
}
toJSON() {
return {
coverAspectRatio: this.coverAspectRatio,
disableWatcher: this.disableWatcher,
skipMatchingMediaWithAsin: this.skipMatchingMediaWithAsin,
skipMatchingMediaWithIsbn: this.skipMatchingMediaWithIsbn,
autoScanCronExpression: this.autoScanCronExpression,
audiobooksOnly: this.audiobooksOnly,
epubsAllowScriptedContent: this.epubsAllowScriptedContent,
hideSingleBookSeries: this.hideSingleBookSeries,
onlyShowLaterBooksInContinueSeries: this.onlyShowLaterBooksInContinueSeries,
metadataPrecedence: [...this.metadataPrecedence],
podcastSearchRegion: this.podcastSearchRegion
}
}
update(payload) {
let hasUpdates = false
for (const key in payload) {
if (key === 'metadataPrecedence') {
if (payload[key] && Array.isArray(payload[key]) && payload[key].join() !== this[key].join()) {
this[key] = payload[key]
hasUpdates = true
}
} else if (this[key] !== payload[key]) {
this[key] = payload[key]
hasUpdates = true
}
}
return hasUpdates
}
}
module.exports = LibrarySettings