mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 06:15:25 -04:00
Inherit web links for Series and bug fixes (#4152)
This commit is contained in:
@@ -12,11 +12,13 @@ using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Helpers;
|
||||
using API.Services;
|
||||
using API.Services.Plus;
|
||||
using API.Services.Tasks.Metadata;
|
||||
using API.SignalR;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nager.ArticleNumber;
|
||||
|
||||
namespace API.Controllers;
|
||||
@@ -48,7 +50,45 @@ public class PersonController : BaseApiController
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<PersonDto>> GetPersonByName(string name)
|
||||
{
|
||||
return Ok(await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId()));
|
||||
var person = await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId());
|
||||
if (person == null) return NotFound();
|
||||
|
||||
person.Roles = (await _unitOfWork.PersonRepository.GetRolesForPersonByName(person.Id, User.GetUserId())).ToList();
|
||||
|
||||
EnrichWithWebLinks(person);
|
||||
|
||||
return Ok(person);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populate <see cref="PersonDto.WebLinks"/> from set ids
|
||||
/// </summary>
|
||||
/// <param name="personDto"></param>
|
||||
/// <remarks><see cref="PersonDto.Roles"/> must be set for this to work</remarks>
|
||||
private static void EnrichWithWebLinks(PersonDto personDto)
|
||||
{
|
||||
if (personDto.Roles == null) return;
|
||||
|
||||
var isCharacter = personDto.Roles.Count == 1 && personDto.Roles.Contains(PersonRole.Character);
|
||||
personDto.WebLinks = [];
|
||||
|
||||
if (personDto.AniListId != 0)
|
||||
{
|
||||
var urlPrefix = isCharacter ? ScrobblingService.AniListCharacterWebsite : ScrobblingService.AniListStaffWebsite;
|
||||
personDto.WebLinks.Add($"{urlPrefix}{personDto.AniListId}");
|
||||
}
|
||||
|
||||
if (personDto.MalId != 0)
|
||||
{
|
||||
var urlPrefix = isCharacter ? ScrobblingService.MalCharacterWebsite : ScrobblingService.MalStaffWebsite;
|
||||
personDto.WebLinks.Add($"{urlPrefix}{personDto.MalId}");
|
||||
}
|
||||
|
||||
// Hardcover currently does not seem to have characters
|
||||
if (!string.IsNullOrEmpty(personDto.HardcoverId) && !isCharacter)
|
||||
{
|
||||
personDto.WebLinks.Add($"{ScrobblingService.HardcoverStaffWebsite}{personDto.HardcoverId}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,12 +152,14 @@ public class PersonController : BaseApiController
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "person-name-unique"));
|
||||
}
|
||||
|
||||
// Update name first, in case it got moved to aliases
|
||||
person.Name = dto.Name.Trim();
|
||||
person.NormalizedName = person.Name.ToNormalized();
|
||||
|
||||
var success = await _personService.UpdatePersonAliasesAsync(person, dto.Aliases);
|
||||
if (!success) return BadRequest(await _localizationService.Translate(User.GetUserId(), "aliases-have-overlap"));
|
||||
|
||||
|
||||
person.Name = dto.Name?.Trim();
|
||||
person.NormalizedName = person.Name.ToNormalized();
|
||||
person.Description = dto.Description ?? string.Empty;
|
||||
person.CoverImageLocked = dto.CoverImageLocked;
|
||||
|
||||
@@ -236,17 +278,18 @@ public class PersonController : BaseApiController
|
||||
/// <summary>
|
||||
/// Ensure the alias is valid to be added. For example, the alias cannot be on another person or be the same as the current person name/alias.
|
||||
/// </summary>
|
||||
/// <param name="personId"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <param name="dto">alias check request</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("valid-alias")]
|
||||
public async Task<ActionResult<bool>> IsValidAlias(int personId, string alias)
|
||||
[HttpPost("valid-alias")]
|
||||
public async Task<ActionResult<bool>> IsValidAlias(PersonAliasCheckDto dto)
|
||||
{
|
||||
var person = await _unitOfWork.PersonRepository.GetPersonById(personId, PersonIncludes.Aliases);
|
||||
var person = await _unitOfWork.PersonRepository.GetPersonById(dto.PersonId, PersonIncludes.Aliases);
|
||||
if (person == null) return NotFound();
|
||||
|
||||
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(alias);
|
||||
return Ok(!existingAlias && person.NormalizedName != alias.ToNormalized());
|
||||
var aliasIsName = dto.Name.ToNormalized() == dto.Alias.ToNormalized();
|
||||
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(dto.Alias);
|
||||
|
||||
return Ok(!existingAlias && !aliasIsName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user