Cleanup Amelia's PR.

Return instantly when downloading a cover from Kavita+ that isn't better.
This commit is contained in:
Joseph Milazzo 2025-05-09 17:08:11 -05:00
parent 19d2e20f24
commit d0b4ad6257
8 changed files with 39 additions and 24 deletions

View file

@ -56,8 +56,7 @@ public class PersonController : BaseApiController
[HttpGet("search")]
public async Task<ActionResult<List<PersonDto>>> SearchPeople([FromQuery] string queryString)
{
var people = await _unitOfWork.PersonRepository.SearchPeople(queryString);
return Ok(people.Select(person => _mapper.Map<PersonDto>(person)).ToList());
return Ok(await _unitOfWork.PersonRepository.SearchPeople(queryString));
}
/// <summary>
@ -96,7 +95,7 @@ public class PersonController : BaseApiController
public async Task<ActionResult<PersonDto>> UpdatePerson(UpdatePersonDto dto)
{
// This needs to get all people and update them equally
var person = await _unitOfWork.PersonRepository.GetPersonById(dto.Id);
var person = await _unitOfWork.PersonRepository.GetPersonById(dto.Id, PersonIncludes.Aliases);
if (person == null) return BadRequest(_localizationService.Translate(User.GetUserId(), "person-doesnt-exist"));
if (string.IsNullOrEmpty(dto.Name)) return BadRequest(await _localizationService.Translate(User.GetUserId(), "person-name-required"));
@ -215,17 +214,20 @@ public class PersonController : BaseApiController
return Ok(_mapper.Map<PersonDto>(dst));
}
[HttpGet("alias/{personId}/{alias}")]
/// <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>
/// <returns></returns>
[HttpGet("valid-alias")]
public async Task<ActionResult<bool>> IsValidAlias(int personId, string alias)
{
// Remove and just check against the passed value?
var person = await _unitOfWork.PersonRepository.GetPersonById(personId);
var person = await _unitOfWork.PersonRepository.GetPersonById(personId, PersonIncludes.Aliases);
if (person == null) return NotFound();
var other = await _unitOfWork.PersonRepository.GetPersonByNameOrAliasAsync(alias);
if (other == null) return Ok(true);
return Ok(other.Id == person.Id);
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(alias);
return Ok(!existingAlias && person.NormalizedName != alias.ToNormalized());
}

View file

@ -37,16 +37,16 @@ public interface IPersonRepository
void Update(Person person);
Task<IList<Person>> GetAllPeople(PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId, PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<PersonDto>> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId, PersonIncludes includes = PersonIncludes.None);
Task<IList<PersonDto>> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.None);
Task RemoveAllPeopleNoLongerAssociated();
Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(int userId, List<int>? libraryIds = null, PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(int userId, List<int>? libraryIds = null, PersonIncludes includes = PersonIncludes.None);
Task<string?> GetCoverImageAsync(int personId);
Task<string?> GetCoverImageByNameAsync(string name);
Task<IEnumerable<PersonRole>> GetRolesForPersonByName(int personId, int userId);
Task<PagedList<BrowsePersonDto>> GetAllWritersAndSeriesCount(int userId, UserParams userParams);
Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.Aliases);
Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.None);
Task<PersonDto?> GetPersonDtoByName(string name, int userId, PersonIncludes includes = PersonIncludes.Aliases);
/// <summary>
/// Returns a person matched on normalized name or alias
@ -68,7 +68,9 @@ public interface IPersonRepository
Task<IList<Person>> GetPeopleByNames(List<string> normalizedNames, PersonIncludes includes = PersonIncludes.Aliases);
Task<Person?> GetPersonByAniListId(int aniListId, PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<Person>> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases);
Task<IList<PersonDto>> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases);
Task<bool> AnyAliasExist(string alias);
}
public class PersonRepository : IPersonRepository
@ -222,7 +224,7 @@ public class PersonRepository : IPersonRepository
return await PagedList<BrowsePersonDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
}
public async Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.Aliases)
public async Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.None)
{
return await _context.Person.Where(p => p.Id == personId)
.Includes(includes)
@ -305,7 +307,7 @@ public class PersonRepository : IPersonRepository
.FirstOrDefaultAsync();
}
public async Task<IList<Person>> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases)
public async Task<IList<PersonDto>> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases)
{
searchQuery = searchQuery.ToNormalized();
@ -313,9 +315,17 @@ public class PersonRepository : IPersonRepository
.Includes(includes)
.Where(p => EF.Functions.Like(p.Name, $"%{searchQuery}%")
|| p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
.ToListAsync();
}
public async Task<bool> AnyAliasExist(string alias)
{
return await _context.PersonAlias.AnyAsync(pa => pa.NormalizedAlias == alias.ToNormalized());
}
public async Task<IList<Person>> GetAllPeople(PersonIncludes includes = PersonIncludes.Aliases)
{
return await _context.Person

View file

@ -654,7 +654,10 @@ public class ExternalMetadataService : IExternalMetadataService
mapping.Staff.Name = mapping.PreferredName;
if (existingPeopleDictionary.ContainsKey(mapping.PreferredName.ToNormalized()))
{
continue;
}
if (existingPeopleDictionary.TryGetValue(mapping.AlternativeName.ToNormalized(), out var person))
{
@ -665,8 +668,6 @@ public class ExternalMetadataService : IExternalMetadataService
if (modified)
{
// Can I do this? Is this safe? Am I commiting other stuff to early
// Tests do fail without
await _unitOfWork.CommitAsync();
}

View file

@ -579,7 +579,7 @@ public class CoverDbService : ICoverDbService
else
{
_directoryService.DeleteFiles([tempFullPath]);
series.CoverImage = Path.GetFileName(existingPath);
return;
}
}
catch (Exception ex)

View file

@ -59,7 +59,9 @@ export class PersonService {
}
isValidAlias(personId: number, alias: string) {
return this.httpClient.get<boolean>(this.baseUrl + `person/alias/${personId}/${alias}`);
return this.httpClient.get<boolean>(this.baseUrl + `person/valid-alias?personId=${personId}&alias=${alias}`, TextResonse).pipe(
map(valid => valid + '' === 'true')
);
}
mergePerson(destId: number, srcId: number) {

View file

@ -189,7 +189,7 @@ export class EditPersonModalComponent implements OnInit {
return null;
}
return { 'inValidAlias': {'alias': name} } as ValidationErrors;
return { 'invalidAlias': {'alias': name} } as ValidationErrors;
}));
}
}

View file

@ -79,7 +79,7 @@ export class MergePersonModalComponent implements OnInit {
}));
};
this.typeAheadSettings.trackByIdentityFn = (index, value) => value.name + (value.id + '');
this.typeAheadSettings.trackByIdentityFn = (index, value) => `${value.name}_${value.id}`;
}
updatePerson(people: Person[]) {

View file

@ -2269,7 +2269,7 @@
"save": "{{common.save}}",
"download-coversdb": "Download from CoversDB",
"aliases-label": "Edit aliases",
"alias-overlap": "This alias already points towards another person, consider merging them.",
"alias-overlap": "This alias already points towards another person or is the name of this person, consider merging them.",
"aliases-tooltip": "When a series is tagged with an alias of a person, the person is assigned rather than creating a new person. When deleting an alias, you'll have to rescan the series for the change to be picked up."
},