mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 17:54:54 +02:00
Remove old User object with old MediaProgress & AudioBookmark
This commit is contained in:
parent
27b3a44147
commit
bb1a72269a
5 changed files with 19 additions and 569 deletions
|
@ -1289,10 +1289,9 @@ async function handleOldUsers(ctx) {
|
|||
const usersNew = await ctx.userModel.findAll({
|
||||
include: ctx.models.mediaProgress
|
||||
})
|
||||
const users = usersNew.map((u) => ctx.userModel.getOldUser(u))
|
||||
|
||||
let usersUpdated = 0
|
||||
for (const user of users) {
|
||||
for (const user of usersNew) {
|
||||
let hasUpdates = false
|
||||
if (user.bookmarks?.length) {
|
||||
user.bookmarks = user.bookmarks
|
||||
|
@ -1305,21 +1304,31 @@ async function handleOldUsers(ctx) {
|
|||
return bm
|
||||
})
|
||||
.filter((bm) => bm.libraryItemId)
|
||||
if (hasUpdates) {
|
||||
user.changed('bookmarks', true)
|
||||
}
|
||||
}
|
||||
|
||||
const librariesAccessible = user.permissions?.librariesAccessible || []
|
||||
|
||||
// Convert old library ids to new library ids
|
||||
if (user.librariesAccessible?.length) {
|
||||
user.librariesAccessible = user.librariesAccessible
|
||||
if (librariesAccessible.length) {
|
||||
user.permissions.librariesAccessible = librariesAccessible
|
||||
.map((lid) => {
|
||||
if (!lid.startsWith('lib_') && lid !== 'main') return lid // Already not an old library id so dont change
|
||||
hasUpdates = true
|
||||
return oldDbIdMap.libraries[lid]
|
||||
})
|
||||
.filter((lid) => lid)
|
||||
if (hasUpdates) {
|
||||
user.changed('permissions', true)
|
||||
}
|
||||
}
|
||||
|
||||
if (user.seriesHideFromContinueListening?.length) {
|
||||
user.seriesHideFromContinueListening = user.seriesHideFromContinueListening
|
||||
const seriesHideFromContinueListening = user.extraData?.seriesHideFromContinueListening || []
|
||||
|
||||
if (seriesHideFromContinueListening.length) {
|
||||
user.extraData.seriesHideFromContinueListening = seriesHideFromContinueListening
|
||||
.map((seriesId) => {
|
||||
if (seriesId.startsWith('se_')) {
|
||||
hasUpdates = true
|
||||
|
@ -1328,10 +1337,13 @@ async function handleOldUsers(ctx) {
|
|||
return seriesId
|
||||
})
|
||||
.filter((se) => se)
|
||||
if (hasUpdates) {
|
||||
user.changed('extraData', true)
|
||||
}
|
||||
}
|
||||
|
||||
if (hasUpdates) {
|
||||
await ctx.models.user.updateFromOld(user)
|
||||
await user.save()
|
||||
usersUpdated++
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue