Cleanup Amelia's PR.
Return instantly when downloading a cover from Kavita+ that isn't better.
This commit is contained in:
parent
19d2e20f24
commit
d0b4ad6257
8 changed files with 39 additions and 24 deletions
|
|
@ -56,8 +56,7 @@ public class PersonController : BaseApiController
|
||||||
[HttpGet("search")]
|
[HttpGet("search")]
|
||||||
public async Task<ActionResult<List<PersonDto>>> SearchPeople([FromQuery] string queryString)
|
public async Task<ActionResult<List<PersonDto>>> SearchPeople([FromQuery] string queryString)
|
||||||
{
|
{
|
||||||
var people = await _unitOfWork.PersonRepository.SearchPeople(queryString);
|
return Ok(await _unitOfWork.PersonRepository.SearchPeople(queryString));
|
||||||
return Ok(people.Select(person => _mapper.Map<PersonDto>(person)).ToList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -96,7 +95,7 @@ public class PersonController : BaseApiController
|
||||||
public async Task<ActionResult<PersonDto>> UpdatePerson(UpdatePersonDto dto)
|
public async Task<ActionResult<PersonDto>> UpdatePerson(UpdatePersonDto dto)
|
||||||
{
|
{
|
||||||
// This needs to get all people and update them equally
|
// 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 (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"));
|
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));
|
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)
|
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, PersonIncludes.Aliases);
|
||||||
var person = await _unitOfWork.PersonRepository.GetPersonById(personId);
|
|
||||||
if (person == null) return NotFound();
|
if (person == null) return NotFound();
|
||||||
|
|
||||||
var other = await _unitOfWork.PersonRepository.GetPersonByNameOrAliasAsync(alias);
|
var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(alias);
|
||||||
if (other == null) return Ok(true);
|
return Ok(!existingAlias && person.NormalizedName != alias.ToNormalized());
|
||||||
|
|
||||||
return Ok(other.Id == person.Id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,16 @@ public interface IPersonRepository
|
||||||
void Update(Person person);
|
void Update(Person person);
|
||||||
|
|
||||||
Task<IList<Person>> GetAllPeople(PersonIncludes includes = PersonIncludes.Aliases);
|
Task<IList<Person>> GetAllPeople(PersonIncludes includes = PersonIncludes.Aliases);
|
||||||
Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId, 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.Aliases);
|
Task<IList<PersonDto>> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.None);
|
||||||
Task RemoveAllPeopleNoLongerAssociated();
|
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?> GetCoverImageAsync(int personId);
|
||||||
Task<string?> GetCoverImageByNameAsync(string name);
|
Task<string?> GetCoverImageByNameAsync(string name);
|
||||||
Task<IEnumerable<PersonRole>> GetRolesForPersonByName(int personId, int userId);
|
Task<IEnumerable<PersonRole>> GetRolesForPersonByName(int personId, int userId);
|
||||||
Task<PagedList<BrowsePersonDto>> GetAllWritersAndSeriesCount(int userId, UserParams userParams);
|
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);
|
Task<PersonDto?> GetPersonDtoByName(string name, int userId, PersonIncludes includes = PersonIncludes.Aliases);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a person matched on normalized name or alias
|
/// 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<IList<Person>> GetPeopleByNames(List<string> normalizedNames, PersonIncludes includes = PersonIncludes.Aliases);
|
||||||
Task<Person?> GetPersonByAniListId(int aniListId, 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
|
public class PersonRepository : IPersonRepository
|
||||||
|
|
@ -222,7 +224,7 @@ public class PersonRepository : IPersonRepository
|
||||||
return await PagedList<BrowsePersonDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
|
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)
|
return await _context.Person.Where(p => p.Id == personId)
|
||||||
.Includes(includes)
|
.Includes(includes)
|
||||||
|
|
@ -305,7 +307,7 @@ public class PersonRepository : IPersonRepository
|
||||||
.FirstOrDefaultAsync();
|
.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();
|
searchQuery = searchQuery.ToNormalized();
|
||||||
|
|
||||||
|
|
@ -313,9 +315,17 @@ public class PersonRepository : IPersonRepository
|
||||||
.Includes(includes)
|
.Includes(includes)
|
||||||
.Where(p => EF.Functions.Like(p.Name, $"%{searchQuery}%")
|
.Where(p => EF.Functions.Like(p.Name, $"%{searchQuery}%")
|
||||||
|| p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
|
|| p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
|
||||||
|
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
|
||||||
.ToListAsync();
|
.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)
|
public async Task<IList<Person>> GetAllPeople(PersonIncludes includes = PersonIncludes.Aliases)
|
||||||
{
|
{
|
||||||
return await _context.Person
|
return await _context.Person
|
||||||
|
|
|
||||||
|
|
@ -654,7 +654,10 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
mapping.Staff.Name = mapping.PreferredName;
|
mapping.Staff.Name = mapping.PreferredName;
|
||||||
|
|
||||||
if (existingPeopleDictionary.ContainsKey(mapping.PreferredName.ToNormalized()))
|
if (existingPeopleDictionary.ContainsKey(mapping.PreferredName.ToNormalized()))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (existingPeopleDictionary.TryGetValue(mapping.AlternativeName.ToNormalized(), out var person))
|
if (existingPeopleDictionary.TryGetValue(mapping.AlternativeName.ToNormalized(), out var person))
|
||||||
{
|
{
|
||||||
|
|
@ -665,8 +668,6 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
|
|
||||||
if (modified)
|
if (modified)
|
||||||
{
|
{
|
||||||
// Can I do this? Is this safe? Am I commiting other stuff to early
|
|
||||||
// Tests do fail without
|
|
||||||
await _unitOfWork.CommitAsync();
|
await _unitOfWork.CommitAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -579,7 +579,7 @@ public class CoverDbService : ICoverDbService
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_directoryService.DeleteFiles([tempFullPath]);
|
_directoryService.DeleteFiles([tempFullPath]);
|
||||||
series.CoverImage = Path.GetFileName(existingPath);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,9 @@ export class PersonService {
|
||||||
}
|
}
|
||||||
|
|
||||||
isValidAlias(personId: number, alias: string) {
|
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) {
|
mergePerson(destId: number, srcId: number) {
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ export class EditPersonModalComponent implements OnInit {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { 'inValidAlias': {'alias': name} } as ValidationErrors;
|
return { 'invalidAlias': {'alias': name} } as ValidationErrors;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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[]) {
|
updatePerson(people: Person[]) {
|
||||||
|
|
|
||||||
|
|
@ -2269,7 +2269,7 @@
|
||||||
"save": "{{common.save}}",
|
"save": "{{common.save}}",
|
||||||
"download-coversdb": "Download from CoversDB",
|
"download-coversdb": "Download from CoversDB",
|
||||||
"aliases-label": "Edit aliases",
|
"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."
|
"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."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue