Prep for Hotfix (#2362)

This commit is contained in:
Joe Milazzo 2023-10-29 07:20:19 -05:00 committed by GitHub
parent 0cf760ecd3
commit 30f1cd20a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 252 additions and 72 deletions

View file

@ -412,14 +412,15 @@ public class LibraryController : BaseApiController
[HttpPost("update")]
public async Task<ActionResult> UpdateLibrary(UpdateLibraryDto dto)
{
var userId = User.GetUserId();
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(dto.Id, LibraryIncludes.Folders);
if (library == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "library-doesnt-exist"));
if (library == null) return BadRequest(await _localizationService.Translate(userId, "library-doesnt-exist"));
var newName = dto.Name.Trim();
if (await _unitOfWork.LibraryRepository.LibraryExists(newName) && !library.Name.Equals(newName))
return BadRequest(await _localizationService.Translate(User.GetUserId(), "library-name-exists"));
return BadRequest(await _localizationService.Translate(userId, "library-name-exists"));
var originalFolders = library.Folders.Select(x => x.Path).ToList();
var originalFoldersCount = library.Folders.Count;
library.Name = newName;
library.Folders = dto.Folders.Select(s => new FolderPath() {Path = s}).Distinct().ToList();
@ -445,8 +446,8 @@ public class LibraryController : BaseApiController
_unitOfWork.LibraryRepository.Update(library);
if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-library-update"));
if (originalFolders.Count != dto.Folders.Count() || typeUpdate)
if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(userId, "generic-library-update"));
if (originalFoldersCount != dto.Folders.Count() || typeUpdate)
{
await _libraryWatcher.RestartWatching();
_taskScheduler.ScanLibrary(library.Id);
@ -458,8 +459,9 @@ public class LibraryController : BaseApiController
}
await _eventHub.SendMessageAsync(MessageFactory.LibraryModified,
MessageFactory.LibraryModifiedEvent(library.Id, "update"), false);
await _eventHub.SendMessageAsync(MessageFactory.SideNavUpdate,
MessageFactory.SideNavUpdateEvent(User.GetUserId()), false);
MessageFactory.SideNavUpdateEvent(userId), false);
await _libraryCacheProvider.RemoveByPrefixAsync(CacheKey);