mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-03-04 15:09:44 +00:00
2.8 KiB
2.8 KiB
Consolidate Single File Books Specification
Overview
The "Consolidate" feature is being expanded to support books that are currently single files (e.g., .m4b, .mp3) located directly in the root of a library folder. When consolidated, these files will be moved into a newly created folder named according to the Author - Title convention.
Implementation Details
Server-Side Changes
1. handleMoveLibraryItem Helper
Modified the internal helper to handle the case where a single file is being moved to a new "folder" name.
- Logic: If
libraryItem.isFileis true AND anewItemFolderNameis provided:- Create the target directory:
Path.join(targetFolder.path, newItemFolderName). - Move the file into this new directory.
- Update the
libraryItem.isFilestatus tofalse. - Update the
libraryItem.pathto the new directory path.
- Create the target directory:
2. LibraryItemController.consolidate
- Removed the restriction that blocked consolidation for items where
isFileis true. - Consolidation is now permitted for any library item of type
book.
3. LibraryItemController.batchConsolidate
- Updated the batch processing loop to allow processing of items where
isFileis true.
4. LibraryItem Model
Added a beforeSave hook to the LibraryItem model to ensure that:
- Metadata Sync: Denormalized fields (
title,titleIgnorePrefix,authorNamesFirstLast,authorNamesLastFirst) are automatically synchronized from the linkedmediaobject (Book or Podcast) before saving. - Status Recalculation: The
isNotConsolidatedflag is recalculated whenever the item is saved, using the latest metadata and path. This ensures that features like "Match" or manual metadata updates immediately reflect the correct consolidation status in the library listings.
Client-Side Changes
1. LazyBookCard.vue
- Updated the context menu logic to show the "Consolidate" option for single-file books.
- Removed the
!this.isFilecheck in themoreMenuItemscomputed property.
2. item/_id/index.vue (Book View Page)
- Updated the primary action button for consolidation to be visible even for single-file books.
- Removed the
!isFilecheck in the template.
Verification
- Scenario 1 (Single File Consolidation): Navigate to a book that is a single M4b file in the library root. Click "Consolidate". The file should be moved into a folder named
Author - Title, and the UI should update showing the book is now consolidated. The database entry should reflectisFile: false. - Scenario 2 (Metadata Update Recalculation): Navigate to a folder-based book that is currently marked as "Consolidated". Manually rename the title in the "Edit" modal. Upon saving, the "Not Consolidated" indicator should appear because the folder name no longer matches the
Author - Titleconvention based on the new metadata.