Support deleting multiple volumes, fixes #3737

The UI doesn't seem to update while the VolumeDeleteEvent is send out
This commit is contained in:
Amelia 2025-04-16 21:24:47 +02:00
parent 4c3dd48147
commit 48e6b5a080
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
6 changed files with 79 additions and 8 deletions

View file

@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using API.Constants;
using API.Data;
using API.Data.Repositories;
using API.DTOs;
@ -54,4 +56,29 @@ public class VolumeController : BaseApiController
return Ok(false);
}
[Authorize(Policy = "RequireAdminRole")]
[HttpPost("multiple")]
public async Task<ActionResult<bool>> DeleteMultipleVolumes(int[] volumesIds)
{
var volumes = (await _unitOfWork.VolumeRepository.GetVolumesById(volumesIds)).ToList();
if (volumes.Count != volumesIds.Length)
{
return BadRequest(_localizationService.Translate(User.GetUserId(), "volume-doesnt-exist"));
}
_unitOfWork.VolumeRepository.Remove(volumes);
if (!await _unitOfWork.CommitAsync())
{
return Ok(false);
}
foreach (var volume in volumes)
{
await _eventHub.SendMessageAsync(MessageFactory.VolumeRemoved, MessageFactory.VolumeRemovedEvent(volume.Id, volume.SeriesId), false);
}
return Ok(true);
}
}

View file

@ -35,6 +35,7 @@ public interface IVolumeRepository
void Add(Volume volume);
void Update(Volume volume);
void Remove(Volume volume);
void Remove(IList<Volume> volumes);
Task<IList<MangaFile>> GetFilesForVolume(int volumeId);
Task<string?> GetVolumeCoverImageAsync(int volumeId);
Task<IList<int>> GetChapterIdsByVolumeIds(IReadOnlyList<int> volumeIds);
@ -43,6 +44,7 @@ public interface IVolumeRepository
Task<VolumeDto?> GetVolumeDtoAsync(int volumeId, int userId);
Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(IList<int> seriesIds, bool includeChapters = false);
Task<IEnumerable<Volume>> GetVolumes(int seriesId);
Task<IEnumerable<Volume>> GetVolumesById(IList<int> volumeIds, VolumeIncludes includes = VolumeIncludes.None);
Task<Volume?> GetVolumeByIdAsync(int volumeId);
Task<IList<Volume>> GetAllWithCoversInDifferentEncoding(EncodeFormat encodeFormat);
Task<IEnumerable<string>> GetCoverImagesForLockedVolumesAsync();
@ -72,6 +74,10 @@ public class VolumeRepository : IVolumeRepository
{
_context.Volume.Remove(volume);
}
public void Remove(IList<Volume> volumes)
{
_context.Volume.RemoveRange(volumes);
}
/// <summary>
/// Returns a list of non-tracked files for a given volume.
@ -180,6 +186,15 @@ public class VolumeRepository : IVolumeRepository
.OrderBy(vol => vol.MinNumber)
.ToListAsync();
}
public async Task<IEnumerable<Volume>> GetVolumesById(IList<int> volumeIds, VolumeIncludes includes = VolumeIncludes.None)
{
return await _context.Volume
.Where(vol => volumeIds.Contains(vol.Id))
.Includes(includes)
.AsSplitQuery()
.OrderBy(vol => vol.MinNumber)
.ToListAsync();
}
/// <summary>
/// Returns a single volume with Chapter and Files

View file

@ -472,8 +472,18 @@ export class ActionService {
});
}
async deleteMultipleVolumes(volumes: Array<Volume>, callback?: BooleanActionCallback) {
if (!await this.confirmService.confirm(translate('toasts.confirm-delete-multiple-volumes', {count: volumes.length}))) return;
this.volumeService.deleteMultipleVolumes(volumes.map(v => v.id)).subscribe((success) => {
if (callback) {
callback(success);
}
})
}
async deleteMultipleChapters(seriesId: number, chapterIds: Array<Chapter>, callback?: BooleanActionCallback) {
if (!await this.confirmService.confirm(translate('toasts.confirm-delete-multiple-chapters'))) return;
if (!await this.confirmService.confirm(translate('toasts.confirm-delete-multiple-chapters', {count: chapterIds.length}))) return;
this.chapterService.deleteMultipleChapters(seriesId, chapterIds.map(c => c.id)).subscribe(() => {
if (callback) {

View file

@ -21,6 +21,10 @@ export class VolumeService {
return this.httpClient.delete<boolean>(this.baseUrl + 'volume?volumeId=' + volumeId);
}
deleteMultipleVolumes(volumeIds: number[]) {
return this.httpClient.post<boolean>(this.baseUrl + "volume/multiple", volumeIds)
}
updateVolume(volume: any) {
return this.httpClient.post(this.baseUrl + 'volume/update', volume, TextResonse);
}

View file

@ -353,11 +353,25 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {
this.cdRef.markForCheck();
break;
case Action.Delete:
if (chapters.length > 0) {
await this.actionService.deleteMultipleChapters(seriesId, chapters, () => {
// No need to update the page as the backend will spam volume/chapter deletions
this.bulkSelectionService.deselectAll();
this.cdRef.markForCheck();
});
// It's not possible to select both chapters and volumes
break;
}
if (selectedVolumeIds.length > 0) {
await this.actionService.deleteMultipleVolumes(selectedVolumeIds, () => {
// No need to update the page as the backend will spam volume deletions
this.bulkSelectionService.deselectAll();
this.cdRef.markForCheck();
});
}
break;
}
}

View file

@ -2628,6 +2628,7 @@
"alert-long-running": "This is a long running process. Please give it the time to complete before invoking again.",
"confirm-delete-multiple-series": "Are you sure you want to delete {{count}} series? It will not modify files on disk.",
"confirm-delete-multiple-chapters": "Are you sure you want to delete {{count}} chapter/volumes? It will not modify files on disk.",
"confirm-delete-multiple-volumes": "Are you sure you want to delete {{count}} volumes? It will not modify files on disk.",
"confirm-delete-series": "Are you sure you want to delete this series? It will not modify files on disk.",
"confirm-delete-chapter": "Are you sure you want to delete this chapter? It will not modify files on disk.",
"confirm-delete-volume": "Are you sure you want to delete this volume? It will not modify files on disk.",