diff --git a/artifacts/docs/consolidate_feature.md b/artifacts/docs/consolidate_feature.md
index c24b348c6..4b0e7c099 100644
--- a/artifacts/docs/consolidate_feature.md
+++ b/artifacts/docs/consolidate_feature.md
@@ -12,6 +12,7 @@ The standard consolidation format is:
- **Batch Consolidation**: Allows selecting multiple books in the library listing to consolidate them all at once.
- **Metadata Synchronization**: When a book is consolidated (or its metadata is updated), ABS ensures that denormalized database fields (Title, Author) are synchronized with the media record.
- **Interactive Indicators**: Books that are not consolidated display a yellow "Not Consolidated" button/badge. For authorized users, this badge acts as a shortcut to trigger the consolidation process directly from the bookshelf.
+- **Interactive Conflict Resolution**: Detects folder collisions and prompts the user to either merge items or rename the target folder.
- **Empty Directory Cleanup**: After moving an item, the feature recursively deletes any parent directories that have become empty.
## How it Works
@@ -26,12 +27,19 @@ The target folder name is generated using the first author listed and the book t
- **Backend API**: The `LibraryItem` model's serialization methods (`toOldJSON`) return the persisted `isNotConsolidated` flag. This maintains perfect parity between the items shown in a filtered listing and the status indicators visible on their cards.
- **Frontend**: Computed properties in `LazyBookCard.vue` and `item/_id/index.vue` rely on the server-provided `isNotConsolidated` property, ensuring consistent behavior across the application.
-### 3. Path Validation
-Before moving any files, the system checks if the destination folder already exists. If it exists and is not the current folder, the operation will fail to prevent overwriting or merging items unintentionally.
+### 3. Path Validation and Conflict Resolution
+Before moving any files, the system checks if the destination folder already exists.
+- **Normal Flow**: If the destination does not exist, the item is moved.
+- **Conflict Detection**: If the destination already exists, the server returns a `409 Conflict` error containing information about the existing path and any library item already located there.
+- **Interactive Resolution**: The frontend catches this conflict and presents a **Consolidation Conflict Dialog**, offering two strategies:
+ - **Merge Contents**: Moves all files from the current item into the existing folder.
+ - **Collision Handling**: If a file with the same name already exists in the destination folder, the incoming file is automatically renamed with a timestamp suffix (e.g., `audio_1708174523.mp3`) to prevent data loss.
+ - **Rename Destination**: Allows the user to provide a custom folder name (e.g., adding " (Digital)" or " (v2)") to avoid the collision.
### 4. File Movement (`handleMoveLibraryItem`)
-- **For Folders**: The entire directory is moved to the new path.
+- **For Folders**: The directory is moved to the new path. If merging, contents are moved individually.
- **For Single Files**: A new directory is created at the destination, and the file is moved into that directory. The item's `isFile` status is updated from `true` to `false`.
+- **Force Merge**: When explicitly requested (after user confirmation), the move operation will bypass the existence check and combine the file contents.
### 5. Cleanup
The system identifies the previous parent directory of the book. If that directory is now empty (and is not a root library folder), it is deleted. This process repeats upwards until it hits a non-empty directory or a library root.
@@ -54,6 +62,12 @@ The system identifies the previous parent directory of the book. If that directo
### Batch Action
1. Select multiple books using the selection tool (or Ctrl+Click/Shift+Click).
2. Click the **Consolidate** option in the batch action bar at the top of the listing.
+3. In the confirmation dialog, you can check **"Merge contents on conflict"** to automatically apply the merge strategy to all items. If unchecked, conflicting items will be skipped and reported in a summary toast.
+
+### Conflict Resolution Dialog (Single Item)
+If the target consolidation folder already exists for a single item, an interactive dialog will appear:
+- **Merge Contents**: Combine all files into the existing folder (renaming on collision).
+- **Rename Destination**: Provide a custom alternative folder name.
## Technical Notes
- **File System**: Requires write permissions on the library directories.
diff --git a/client/components/app/Appbar.vue b/client/components/app/Appbar.vue
index efec2c8a1..f82d48eba 100644
--- a/client/components/app/Appbar.vue
+++ b/client/components/app/Appbar.vue
@@ -273,16 +273,25 @@ export default {
batchConsolidate() {
const payload = {
message: this.$getString('MessageConfirmConsolidate', [this.$getString('MessageItemsSelected', [this.numMediaItemsSelected]), 'Author - Title']),
- callback: (confirmed) => {
+ checkboxLabel: 'Merge contents on conflict',
+ checkboxType: 'checkbox',
+ callback: (confirmed, merge) => {
if (confirmed) {
this.$store.commit('setProcessingBatch', true)
this.$axios
.$post('/api/items/batch/consolidate', {
- libraryItemIds: this.selectedMediaItems.map((i) => i.id)
+ libraryItemIds: this.selectedMediaItems.map((i) => i.id),
+ merge
})
.then((data) => {
- this.$toast.success(this.$strings.ToastBatchConsolidateSuccess)
- if (this.numMediaItemsSelected === 1) {
+ if (data.success) {
+ this.$toast.success(this.$strings.ToastBatchConsolidateSuccess)
+ } else {
+ const numFailed = data.results.filter((r) => !r.success).length
+ this.$toast.warning(`${numFailed} items failed to consolidate. They may already exist or have other errors.`)
+ }
+
+ if (this.numMediaItemsSelected === 1 && data.success) {
this.$router.push(`/item/${this.selectedMediaItems[0].id}`)
}
this.cancelSelectionMode()
diff --git a/client/components/cards/LazyBookCard.vue b/client/components/cards/LazyBookCard.vue
index 068002736..7c40cbac2 100644
--- a/client/components/cards/LazyBookCard.vue
+++ b/client/components/cards/LazyBookCard.vue
@@ -830,7 +830,19 @@ export default {
})
.catch((error) => {
console.error('Failed to consolidate', error)
- this.$toast.error(error.response?.data || this.$strings.ToastConsolidateFailed || 'Consolidate failed')
+ if (error.response?.status === 409) {
+ const data = error.response.data
+ const author = this.mediaMetadata.authorName?.split(',')[0]?.trim() || 'Unknown Author'
+ const title = this.mediaMetadata.title || 'Unknown Title'
+ this.$eventBus.$emit('show-consolidation-conflict', {
+ item: this._libraryItem,
+ path: data.path,
+ folderName: this.$getConsolidatedFolderName(author, title),
+ existingLibraryItemId: data.existingLibraryItemId
+ })
+ } else {
+ this.$toast.error(error.response?.data?.error || error.response?.data || this.$strings.ToastConsolidateFailed || 'Consolidate failed')
+ }
})
.finally(() => {
this.processing = false
diff --git a/client/components/modals/ConsolidationConflictModal.vue b/client/components/modals/ConsolidationConflictModal.vue
new file mode 100644
index 000000000..84d3faa3b
--- /dev/null
+++ b/client/components/modals/ConsolidationConflictModal.vue
@@ -0,0 +1,107 @@
+
+
+
+
+ warning
+
Consolidation Conflict
+
+
+
+
The destination folder already exists:
+
+ {{ folderPath }}
+
+
+ info
+ Another library item is already at this location.
+