mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-22 06:03:01 +02:00
Use GlobalConnector for Url Search requests
This commit is contained in:
parent
0f0a49f74f
commit
590ccdd09a
@ -67,30 +67,25 @@ public class SearchController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPost("Url")]
|
[HttpPost("Url")]
|
||||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status300MultipleChoices)]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult GetMangaFromUrl([FromBody]string url)
|
public IActionResult GetMangaFromUrl([FromBody]string url)
|
||||||
{
|
{
|
||||||
List<MangaConnector> connectors = context.MangaConnectors.AsEnumerable().Where(c => c.UrlMatchesConnector(url)).ToList();
|
if (context.MangaConnectors.Find("Global") is not { } connector)
|
||||||
if (connectors.Count == 0)
|
return StatusCode(Status500InternalServerError, "Could not find Global Connector.");
|
||||||
return NotFound();
|
|
||||||
else if (connectors.Count > 1)
|
|
||||||
return StatusCode(Status300MultipleChoices);
|
|
||||||
|
|
||||||
if(connectors.First().GetMangaFromUrl(url) is not { } manga)
|
if(connector.GetMangaFromUrl(url) is not { } manga)
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(AddMangaToContext(manga) is { } add)
|
if(AddMangaToContext(manga) is { } add)
|
||||||
return Ok(add);
|
return Ok(add);
|
||||||
return StatusCode(500);
|
return StatusCode(Status500InternalServerError);
|
||||||
}
|
}
|
||||||
catch (DbUpdateException e)
|
catch (DbUpdateException e)
|
||||||
{
|
{
|
||||||
Log.Error(e);
|
Log.Error(e);
|
||||||
return StatusCode(500, e.Message);
|
return StatusCode(Status500InternalServerError, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user