feat: add library-wide consolidation status update tool and improve consolidation robustness

This commit is contained in:
Tiberiu Ichim 2026-02-15 21:23:34 +02:00
parent 2c77f1fc5a
commit c2693e2460
8 changed files with 118 additions and 11 deletions

View file

@ -1374,6 +1374,39 @@ class LibraryController {
})
}
/**
* POST: /api/libraries/:id/update-consolidation
* Update isNotConsolidated flag for all items in library
*
* @param {LibraryControllerRequest} req
* @param {Response} res
*/
async updateConsolidationStatus(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to update consolidation status`)
return res.sendStatus(403)
}
const items = await Database.libraryItemModel.findAllExpandedWhere({
libraryId: req.library.id
})
let updatedCount = 0
for (const item of items) {
const isNotConsolidated = item.checkIsNotConsolidated()
if (item.isNotConsolidated !== isNotConsolidated) {
item.isNotConsolidated = isNotConsolidated
await item.save()
updatedCount++
}
}
Logger.info(`[LibraryController] Updated consolidation status for ${updatedCount} items in library "${req.library.name}"`)
res.json({
updated: updatedCount
})
}
/**
* GET: /api/libraries/:id/podcast-titles
*

View file

@ -58,19 +58,22 @@ async function handleMoveLibraryItem(libraryItem, targetLibrary, targetFolder, n
// Check if destination already exists
const destinationExists = await fs.pathExists(newPath)
if (destinationExists) {
const isSamePath = oldPath === newPath
if (destinationExists && !isSamePath) {
throw new Error(`Destination already exists: ${newPath}`)
}
try {
Watcher.addIgnoreDir(oldPath)
Watcher.addIgnoreDir(newPath)
if (!isSamePath) Watcher.addIgnoreDir(newPath)
const oldRelPath = libraryItem.relPath
// Move files on disk
Logger.info(`[LibraryItemController] Moving item "${libraryItem.media.title}" from "${oldPath}" to "${newPath}"`)
await fs.move(oldPath, newPath)
if (!isSamePath) {
Logger.info(`[LibraryItemController] Moving item "${libraryItem.media.title}" from "${oldPath}" to "${newPath}"`)
await fs.move(oldPath, newPath)
}
// Update database within a transaction
const transaction = await Database.sequelize.transaction()
@ -276,7 +279,7 @@ async function handleMoveLibraryItem(libraryItem, targetLibrary, targetFolder, n
throw error
} finally {
Watcher.removeIgnoreDir(oldPath)
Watcher.removeIgnoreDir(newPath)
if (typeof isSamePath !== 'undefined' && !isSamePath) Watcher.removeIgnoreDir(newPath)
}
}