Stats Fix & Library Bulk Actions (#3209)
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: Gregory.Open <gregory.open@proton.me> Co-authored-by: Mateusz <mateuszvx8.96@gmail.com> Co-authored-by: majora2007 <kavitareader@gmail.com> Co-authored-by: 無情天 <kofzhanganguo@126.com>
This commit is contained in:
parent
894b49bb76
commit
857e419e4e
77 changed files with 72523 additions and 30914 deletions
|
@ -78,7 +78,6 @@ public class LibraryController : BaseApiController
|
|||
.WithFolders(dto.Folders.Select(x => new FolderPath {Path = x}).Distinct().ToList())
|
||||
.WithFolderWatching(dto.FolderWatching)
|
||||
.WithIncludeInDashboard(dto.IncludeInDashboard)
|
||||
.WithIncludeInRecommended(dto.IncludeInRecommended)
|
||||
.WithManageCollections(dto.ManageCollections)
|
||||
.WithManageReadingLists(dto.ManageReadingLists)
|
||||
.WIthAllowScrobbling(dto.AllowScrobbling)
|
||||
|
@ -302,6 +301,22 @@ public class LibraryController : BaseApiController
|
|||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a bunch of library scans
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("scan-multiple")]
|
||||
public async Task<ActionResult> ScanMultiple(BulkActionDto dto)
|
||||
{
|
||||
foreach (var libraryId in dto.Ids)
|
||||
{
|
||||
await _taskScheduler.ScanLibrary(libraryId, dto.Force ?? false);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scans a given library for file changes. If another scan task is in progress, will reschedule the invocation for 3 hours in future.
|
||||
/// </summary>
|
||||
|
@ -323,6 +338,18 @@ public class LibraryController : BaseApiController
|
|||
return Ok();
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("refresh-metadata-multiple")]
|
||||
public ActionResult RefreshMetadataMultiple(BulkActionDto dto, bool forceColorscape = true)
|
||||
{
|
||||
foreach (var libraryId in dto.Ids)
|
||||
{
|
||||
_taskScheduler.RefreshMetadata(libraryId, dto.Force ?? false, forceColorscape);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("analyze")]
|
||||
public ActionResult Analyze(int libraryId)
|
||||
|
@ -331,6 +358,61 @@ public class LibraryController : BaseApiController
|
|||
return Ok();
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("analyze-multiple")]
|
||||
public ActionResult AnalyzeMultiple(BulkActionDto dto)
|
||||
{
|
||||
foreach (var libraryId in dto.Ids)
|
||||
{
|
||||
_taskScheduler.AnalyzeFilesForLibrary(libraryId, dto.Force ?? false);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Copy the library settings (adv tab + optional type) to a set of other libraries.
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("copy-settings-from")]
|
||||
public async Task<ActionResult> CopySettingsFromLibraryToLibraries(CopySettingsFromLibraryDto dto)
|
||||
{
|
||||
var sourceLibrary = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(dto.SourceLibraryId, LibraryIncludes.ExcludePatterns | LibraryIncludes.FileTypes);
|
||||
if (sourceLibrary == null) return BadRequest("SourceLibraryId must exist");
|
||||
|
||||
var libraries = await _unitOfWork.LibraryRepository.GetLibraryForIdsAsync(dto.TargetLibraryIds, LibraryIncludes.ExcludePatterns | LibraryIncludes.FileTypes | LibraryIncludes.Folders);
|
||||
foreach (var targetLibrary in libraries)
|
||||
{
|
||||
UpdateLibrarySettings(new UpdateLibraryDto()
|
||||
{
|
||||
Folders = targetLibrary.Folders.Select(s => s.Path),
|
||||
Name = targetLibrary.Name,
|
||||
Id = targetLibrary.Id,
|
||||
Type = sourceLibrary.Type,
|
||||
AllowScrobbling = sourceLibrary.AllowScrobbling,
|
||||
ExcludePatterns = sourceLibrary.LibraryExcludePatterns.Select(p => p.Pattern).ToList(),
|
||||
FolderWatching = sourceLibrary.FolderWatching,
|
||||
ManageCollections = sourceLibrary.ManageCollections,
|
||||
FileGroupTypes = sourceLibrary.LibraryFileTypes.Select(t => t.FileTypeGroup).ToList(),
|
||||
IncludeInDashboard = sourceLibrary.IncludeInDashboard,
|
||||
IncludeInSearch = sourceLibrary.IncludeInSearch,
|
||||
ManageReadingLists = sourceLibrary.ManageReadingLists
|
||||
}, targetLibrary, dto.IncludeType);
|
||||
}
|
||||
|
||||
await _unitOfWork.CommitAsync();
|
||||
|
||||
if (sourceLibrary.FolderWatching)
|
||||
{
|
||||
BackgroundJob.Enqueue(() => _libraryWatcher.RestartWatching());
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a valid path, will invoke either a Scan Series or Scan Library. If the folder does not exist within Kavita, the request will be ignored
|
||||
/// </summary>
|
||||
|
@ -474,33 +556,7 @@ public class LibraryController : BaseApiController
|
|||
|
||||
var typeUpdate = library.Type != dto.Type;
|
||||
var folderWatchingUpdate = library.FolderWatching != dto.FolderWatching;
|
||||
library.Type = dto.Type;
|
||||
library.FolderWatching = dto.FolderWatching;
|
||||
library.IncludeInDashboard = dto.IncludeInDashboard;
|
||||
library.IncludeInRecommended = dto.IncludeInRecommended;
|
||||
library.IncludeInSearch = dto.IncludeInSearch;
|
||||
library.ManageCollections = dto.ManageCollections;
|
||||
library.ManageReadingLists = dto.ManageReadingLists;
|
||||
library.AllowScrobbling = dto.AllowScrobbling;
|
||||
library.LibraryFileTypes = dto.FileGroupTypes
|
||||
.Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
library.LibraryExcludePatterns = dto.ExcludePatterns
|
||||
.Distinct()
|
||||
.Select(t => new LibraryExcludePattern() {Pattern = t, LibraryId = library.Id})
|
||||
.ToList();
|
||||
|
||||
// Override Scrobbling for Comic libraries since there are no providers to scrobble to
|
||||
if (library.Type == LibraryType.Comic)
|
||||
{
|
||||
_logger.LogInformation("Overrode Library {Name} to disable scrobbling since there are no providers for Comics", dto.Name.Replace(Environment.NewLine, string.Empty));
|
||||
library.AllowScrobbling = false;
|
||||
}
|
||||
|
||||
|
||||
_unitOfWork.LibraryRepository.Update(library);
|
||||
UpdateLibrarySettings(dto, library);
|
||||
|
||||
if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(userId, "generic-library-update"));
|
||||
|
||||
|
@ -526,6 +582,39 @@ public class LibraryController : BaseApiController
|
|||
|
||||
}
|
||||
|
||||
private void UpdateLibrarySettings(UpdateLibraryDto dto, Library library, bool updateType = true)
|
||||
{
|
||||
if (updateType)
|
||||
{
|
||||
library.Type = dto.Type;
|
||||
}
|
||||
|
||||
library.FolderWatching = dto.FolderWatching;
|
||||
library.IncludeInDashboard = dto.IncludeInDashboard;
|
||||
library.IncludeInSearch = dto.IncludeInSearch;
|
||||
library.ManageCollections = dto.ManageCollections;
|
||||
library.ManageReadingLists = dto.ManageReadingLists;
|
||||
library.AllowScrobbling = dto.AllowScrobbling;
|
||||
library.LibraryFileTypes = dto.FileGroupTypes
|
||||
.Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
library.LibraryExcludePatterns = dto.ExcludePatterns
|
||||
.Distinct()
|
||||
.Select(t => new LibraryExcludePattern() {Pattern = t, LibraryId = library.Id})
|
||||
.ToList();
|
||||
|
||||
// Override Scrobbling for Comic libraries since there are no providers to scrobble to
|
||||
if (library.Type is LibraryType.Comic or LibraryType.ComicVine)
|
||||
{
|
||||
_logger.LogInformation("Overrode Library {Name} to disable scrobbling since there are no providers for Comics", dto.Name.Replace(Environment.NewLine, string.Empty));
|
||||
library.AllowScrobbling = false;
|
||||
}
|
||||
|
||||
_unitOfWork.LibraryRepository.Update(library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the type of the underlying library
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue