mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-21 11:24:53 +02:00
Library update migrate to use book mediaType, disable editing mediaType, set icon instead of media category
This commit is contained in:
parent
6a06ba4327
commit
a9b9e23f46
6 changed files with 81 additions and 43 deletions
|
@ -7,8 +7,7 @@ class Library {
|
|||
this.name = null
|
||||
this.folders = []
|
||||
this.displayOrder = 1
|
||||
this.icon = 'database'
|
||||
this.mediaCategory = 'default' // default, podcast, book, audiobook, comic
|
||||
this.icon = 'database' // database, podcast, book, audiobook, comic
|
||||
this.mediaType = 'book' // book, podcast
|
||||
this.provider = 'google'
|
||||
this.disableWatcher = false
|
||||
|
@ -33,30 +32,24 @@ class Library {
|
|||
this.folders = (library.folders || []).map(f => new Folder(f))
|
||||
this.displayOrder = library.displayOrder || 1
|
||||
this.icon = library.icon || 'database'
|
||||
this.mediaCategory = library.mediaCategory || library.mediaType || 'default' // mediaCategory used to be mediaType
|
||||
this.mediaType = library.mediaType
|
||||
this.provider = library.provider || 'google'
|
||||
this.disableWatcher = !!library.disableWatcher
|
||||
|
||||
this.createdAt = library.createdAt
|
||||
this.lastUpdate = library.lastUpdate
|
||||
this.cleanOldValues() // mediaCategory and mediaType were changed for v2
|
||||
this.cleanOldValues() // mediaType changed for v2
|
||||
}
|
||||
|
||||
cleanOldValues() {
|
||||
if (this.mediaCategory.endsWith('s')) {
|
||||
this.mediaCategory = this.mediaCategory.slice(0, -1)
|
||||
}
|
||||
var availableCategories = ['default', 'audiobook', 'book', 'comic', 'podcast']
|
||||
if (!availableCategories.includes(this.mediaCategory)) {
|
||||
this.mediaCategory = 'default'
|
||||
}
|
||||
if (!availableCategories.includes(this.icon)) {
|
||||
this.icon = this.mediaCategory
|
||||
var availableIcons = ['database', 'audiobook', 'book', 'comic', 'podcast']
|
||||
if (!availableIcons.includes(this.icon)) {
|
||||
if (this.icon === 'default') this.icon = 'database'
|
||||
else if (this.icon.endsWith('s') && availableIcons.includes(this.icon.slice(0, -1))) this.icon = this.icon.slice(0, -1)
|
||||
else this.icon = 'database'
|
||||
}
|
||||
if (!this.mediaType || (this.mediaType !== 'podcast' && this.mediaType !== 'book')) {
|
||||
if (this.mediaCategory === 'podcast') this.mediaType = 'podcast'
|
||||
else this.mediaType = 'book'
|
||||
this.mediaType = 'book'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +60,6 @@ class Library {
|
|||
folders: (this.folders || []).map(f => f.toJSON()),
|
||||
displayOrder: this.displayOrder,
|
||||
icon: this.icon,
|
||||
mediaCategory: this.mediaCategory,
|
||||
mediaType: this.mediaType,
|
||||
provider: this.provider,
|
||||
disableWatcher: this.disableWatcher,
|
||||
|
@ -95,7 +87,6 @@ class Library {
|
|||
}
|
||||
this.displayOrder = data.displayOrder || 1
|
||||
this.icon = data.icon || 'database'
|
||||
this.mediaCategory = data.mediaCategory || 'default'
|
||||
this.mediaType = data.mediaType || 'book'
|
||||
this.disableWatcher = !!data.disableWatcher
|
||||
this.createdAt = Date.now()
|
||||
|
@ -105,7 +96,7 @@ class Library {
|
|||
update(payload) {
|
||||
var hasUpdates = false
|
||||
|
||||
var keysToCheck = ['name', 'provider', 'mediaCategory', 'mediaType', 'icon']
|
||||
var keysToCheck = ['name', 'provider', 'mediaType', 'icon']
|
||||
keysToCheck.forEach((key) => {
|
||||
if (payload[key] && payload[key] !== this[key]) {
|
||||
this[key] = payload[key]
|
||||
|
|
|
@ -10,6 +10,7 @@ const Logger = require('../Logger')
|
|||
const LegacyAudiobook = require('../objects/legacy/Audiobook')
|
||||
const UserAudiobookData = require('../objects/legacy/UserAudiobookData')
|
||||
|
||||
const Library = require('../objects/Library')
|
||||
const LibraryItem = require('../objects/LibraryItem')
|
||||
const Book = require('../objects/mediaTypes/Book')
|
||||
|
||||
|
@ -384,6 +385,25 @@ function cleanSessionObj(db, userListeningSession) {
|
|||
async function migrateUserData(db) {
|
||||
Logger.info(`==== Starting User migration ====`)
|
||||
|
||||
// Libraries with previous mediaType of "podcast" moved to "book"
|
||||
// because migrating those items to podcast objects will be a nightmare
|
||||
// users will need to create a new library for podcasts
|
||||
var availableIcons = ['database', 'audiobook', 'book', 'comic', 'podcast']
|
||||
const libraries = await db.librariesDb.select((result) => (result.mediaType != 'book' || !availableIcons.includes(result.icon)))
|
||||
.then((results) => results.data.map(lib => new Library(lib)))
|
||||
if (!libraries.length) {
|
||||
Logger.info('[dbMigration] No libraries found needing migration')
|
||||
} else {
|
||||
for (const library of libraries) {
|
||||
Logger.info(`>> Migrating library "${library.name}" with media type "${library.mediaType}"`)
|
||||
await db.librariesDb.update((record) => record.id === library.id, () => library).then(() => true).catch((error) => {
|
||||
Logger.error(`[dbMigration] Update library failed: ${error}`)
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const userObjects = await db.usersDb.select((result) => result.audiobooks != undefined).then((results) => results.data)
|
||||
if (!userObjects.length) {
|
||||
Logger.warn('[dbMigration] No users found needing migration')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue