mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-12 06:27:54 +02:00
Add API
This commit is contained in:
63
API/Controllers/ConnectorController.cs
Normal file
63
API/Controllers/ConnectorController.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using API.Schema;
|
||||
using API.Schema.Jobs;
|
||||
using API.Schema.MangaConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class ConnectorController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all available Connectors (Scanlation-Sites)
|
||||
/// </summary>
|
||||
/// <returns>Array of MangaConnector</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<MangaConnector[]>(Status200OK)]
|
||||
public IActionResult GetConnectors()
|
||||
{
|
||||
MangaConnector[] connectors = context.MangaConnectors.ToArray();
|
||||
return Ok(connectors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initiate a search for a Manga on all Connectors
|
||||
/// </summary>
|
||||
/// <param name="name">Name/Title of the Manga</param>
|
||||
/// <returns>Array of Manga</returns>
|
||||
[HttpPost("SearchManga")]
|
||||
[ProducesResponseType<Manga[]>(Status500InternalServerError)]
|
||||
public IActionResult SearchMangaGlobal(string name)
|
||||
{
|
||||
List<Manga> allManga = new List<Manga>();
|
||||
foreach (MangaConnector contextMangaConnector in context.MangaConnectors)
|
||||
{
|
||||
allManga.AddRange(contextMangaConnector.GetManga(name));
|
||||
}
|
||||
return Ok(allManga.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initiate a search for a Manga on a specific Connector
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-Connector-ID</param>
|
||||
/// <param name="name">Name/Title of the Manga</param>
|
||||
/// <returns>Manga</returns>
|
||||
[HttpPost("{id}/SearchManga")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||
[ProducesResponseType<ProblemResponse>(Status404NotFound)]
|
||||
public IActionResult SearchManga(string id, [FromBody]string name)
|
||||
{
|
||||
MangaConnector? connector = context.MangaConnectors.Find(id);
|
||||
if (connector is null)
|
||||
return NotFound(new ProblemResponse("Connector not found."));
|
||||
Manga[] manga = connector.GetManga(name);
|
||||
return Ok(manga);
|
||||
}
|
||||
}
|
200
API/Controllers/JobController.cs
Normal file
200
API/Controllers/JobController.cs
Normal file
@ -0,0 +1,200 @@
|
||||
using API.Schema;
|
||||
using API.Schema.Jobs;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{version:apiVersion}/[controller]")]
|
||||
public class JobController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns Jobs with requested Job-IDs
|
||||
/// </summary>
|
||||
/// <param name="ids">Array of Job-IDs</param>
|
||||
/// <returns>Array of Jobs</returns>
|
||||
[HttpPost("WithIDs")]
|
||||
[ProducesResponseType<Job[]>(Status200OK)]
|
||||
public IActionResult GetJobs([FromBody] string[] ids)
|
||||
{
|
||||
Job[] ret = context.Jobs.Where(job => ids.Contains(job.JobId)).ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all due Jobs (NextExecution > CurrentTime)
|
||||
/// </summary>
|
||||
/// <returns>Array of Jobs</returns>
|
||||
[HttpGet("Due")]
|
||||
[ProducesResponseType<Job[]>(Status200OK)]
|
||||
public IActionResult GetDueJobs()
|
||||
{
|
||||
DateTime now = DateTime.Now.ToUniversalTime();
|
||||
Job[] dueJobs = context.Jobs.Where(job => job.NextExecution < now && job.state < JobState.Running).ToArray();
|
||||
return Ok(dueJobs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Jobs in requested State
|
||||
/// </summary>
|
||||
/// <param name="state">Requested Job-State</param>
|
||||
/// <returns>Array of Jobs</returns>
|
||||
[HttpGet("State/{state}")]
|
||||
[ProducesResponseType<Job[]>(Status200OK)]
|
||||
public IActionResult GetJobsInState(JobState state)
|
||||
{
|
||||
Job[] jobsInState = context.Jobs.Where(job => job.state == state).ToArray();
|
||||
return Ok(jobsInState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Jobs of requested Type
|
||||
/// </summary>
|
||||
/// <param name="type">Requested Job-Type</param>
|
||||
/// <returns>Array of Jobs</returns>
|
||||
[HttpPost("Type/{type}")]
|
||||
[ProducesResponseType<Job[]>(Status200OK)]
|
||||
public IActionResult GetJobsOfType(JobType type)
|
||||
{
|
||||
Job[] jobsOfType = context.Jobs.Where(job => job.JobType == type).ToArray();
|
||||
return Ok(jobsOfType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Job with ID
|
||||
/// </summary>
|
||||
/// <param name="id">Job-ID</param>
|
||||
/// <returns>Job</returns>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType<Job>(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetJob(string id)
|
||||
{
|
||||
Job? ret = context.Jobs.Find(id);
|
||||
return (ret is not null) switch
|
||||
{
|
||||
true => Ok(ret),
|
||||
false => NotFound()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the State of a Job
|
||||
/// </summary>
|
||||
/// <param name="id">Job-ID</param>
|
||||
/// <param name="state">New State</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("{id}/Status")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType<string>(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult UpdateJobStatus(string id, [FromBody]JobState state)
|
||||
{
|
||||
try
|
||||
{
|
||||
Job? ret = context.Jobs.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
ret.state = state;
|
||||
context.Update(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Job
|
||||
/// </summary>
|
||||
/// <param name="job">Job</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult CreateJob([FromBody]Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Jobs.Add(job);
|
||||
context.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Job with ID
|
||||
/// </summary>
|
||||
/// <param name="id">Job-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult DeleteJob(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Job? ret = context.Jobs.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
context.Remove(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the Job with the requested ID
|
||||
/// </summary>
|
||||
/// <param name="id">Job-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPost("{id}/Start")]
|
||||
[ProducesResponseType(Status202Accepted)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult StartJob(string id)
|
||||
{
|
||||
Job? ret = context.Jobs.Find(id);
|
||||
if (ret is null)
|
||||
return NotFound();
|
||||
ret.NextExecution = DateTime.UnixEpoch;
|
||||
try
|
||||
{
|
||||
context.Update(ret);
|
||||
context.SaveChanges();
|
||||
return Accepted();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("{id}/Stop")]
|
||||
public IActionResult StopJob(string id)
|
||||
{
|
||||
return NotFound(new ProblemResponse("Not implemented")); //TODO
|
||||
}
|
||||
}
|
95
API/Controllers/LibraryConnectorController.cs
Normal file
95
API/Controllers/LibraryConnectorController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using API.Schema;
|
||||
using API.Schema.LibraryConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class LibraryConnectorController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all configured Library-Connectors
|
||||
/// </summary>
|
||||
/// <returns>Array of configured Library-Connectors</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<LibraryConnector[]>(Status200OK)]
|
||||
public IActionResult GetAllConnectors()
|
||||
{
|
||||
LibraryConnector[] connectors = context.LibraryConnectors.ToArray();
|
||||
return Ok(connectors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Library-Connector with requested ID
|
||||
/// </summary>
|
||||
/// <param name="id">Library-Connector-ID</param>
|
||||
/// <returns>Library-Connector</returns>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType<LibraryConnector>(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetConnector(string id)
|
||||
{
|
||||
LibraryConnector? ret = context.LibraryConnectors.Find(id);
|
||||
return (ret is not null) switch
|
||||
{
|
||||
true => Ok(ret),
|
||||
false => NotFound()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Library-Connector
|
||||
/// </summary>
|
||||
/// <param name="libraryConnector">Library-Connector</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult CreateConnector([FromBody]LibraryConnector libraryConnector)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.LibraryConnectors.Add(libraryConnector);
|
||||
context.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the Library-Connector with the requested ID
|
||||
/// </summary>
|
||||
/// <param name="id">Library-Connector-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult DeleteConnector(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
LibraryConnector? ret = context.LibraryConnectors.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
context.Remove(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
234
API/Controllers/MangaController.cs
Normal file
234
API/Controllers/MangaController.cs
Normal file
@ -0,0 +1,234 @@
|
||||
using API.Schema;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class MangaController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all cached Manga with IDs
|
||||
/// </summary>
|
||||
/// <param name="ids">Array of Manga-IDs</param>
|
||||
/// <returns>Array of Manga</returns>
|
||||
[HttpPost("WithIDs")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||
public IActionResult GetManga([FromBody]string[] ids)
|
||||
{
|
||||
Manga[] ret = context.Manga.Where(m => ids.Contains(m.MangaId)).ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Manga with ID
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>Manga</returns>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType<Manga>(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetManga(string id)
|
||||
{
|
||||
Manga? ret = context.Manga.Find(id);
|
||||
return (ret is not null) switch
|
||||
{
|
||||
true => Ok(ret),
|
||||
false => NotFound()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Manga with ID
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult DeleteManga(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Manga? ret = context.Manga.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
context.Remove(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new Manga
|
||||
/// </summary>
|
||||
/// <param name="manga">Manga</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult CreateManga([FromBody] Manga manga)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Manga.Add(manga);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Manga MetaData
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <param name="manga">New Manga-Info</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult UpdateMangaMetadata(string id, [FromBody]Manga manga)
|
||||
{
|
||||
try
|
||||
{
|
||||
Manga? ret = context.Manga.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
ret.UpdateWithInfo(manga);
|
||||
context.Update(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns URL of Cover of Manga
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>URL of Cover</returns>
|
||||
[HttpGet("{id}/Cover")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetCover(string id)
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Chapters of Manga
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>Array of Chapters</returns>
|
||||
[HttpGet("{id}/Chapters")]
|
||||
[ProducesResponseType<Chapter[]>(Status200OK)]
|
||||
[ProducesResponseType<string>(Status404NotFound)]
|
||||
public IActionResult GetChapters(string id)
|
||||
{
|
||||
Manga? m = context.Manga.Find(id);
|
||||
if (m is null)
|
||||
return NotFound("Manga could not be found");
|
||||
Chapter[] ret = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds/Creates new Chapter for Manga
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <param name="chapters">Array of Chapters</param>
|
||||
/// <remarks>Manga-ID and all Chapters have to be the same</remarks>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPut("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType<string>(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult CreateChapters(string id, [FromBody]Chapter[] chapters)
|
||||
{
|
||||
try
|
||||
{
|
||||
Manga? ret = context.Manga.Find(id);
|
||||
if(ret is null)
|
||||
return NotFound("Manga could not be found");
|
||||
if(chapters.All(c => c.ParentMangaId == ret.MangaId))
|
||||
return BadRequest("Chapters belong to different Manga.");
|
||||
|
||||
context.Chapters.AddRange(chapters);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the latest Chapter of requested Manga
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>Latest Chapter</returns>
|
||||
[HttpGet("{id}/Chapter/Latest")]
|
||||
[ProducesResponseType<Chapter>(Status200OK)]
|
||||
[ProducesResponseType<string>(Status404NotFound)]
|
||||
public IActionResult GetLatestChapter(string id)
|
||||
{
|
||||
Manga? m = context.Manga.Find(id);
|
||||
if (m is null)
|
||||
return NotFound("Manga could not be found");
|
||||
Chapter? c = context.Chapters.Find(m.LatestChapterAvailableId);
|
||||
if (c is null)
|
||||
return NotFound("Chapter could not be found");
|
||||
return Ok(c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure the cut-off for Manga
|
||||
/// </summary>
|
||||
/// <remarks>This is important for the DownloadNewChapters-Job</remarks>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("{id}/IgnoreChaptersBefore")]
|
||||
[ProducesResponseType<float>(Status200OK)]
|
||||
public IActionResult IgnoreChaptersBefore(string id)
|
||||
{
|
||||
Manga? m = context.Manga.Find(id);
|
||||
if (m is null)
|
||||
return NotFound("Manga could not be found");
|
||||
return Ok(m.IgnoreChapterBefore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move the Directory the .cbz-files are located in
|
||||
/// </summary>
|
||||
/// <param name="id">Manga-ID</param>
|
||||
/// <param name="folder">New Directory-Path</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPost("{id}/MoveFolder")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult MoveFolder(string id, [FromBody]string folder)
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
}
|
95
API/Controllers/NotificationConnectorController.cs
Normal file
95
API/Controllers/NotificationConnectorController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using API.Schema;
|
||||
using API.Schema.NotificationConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class NotificationConnectorController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all configured Notification-Connectors
|
||||
/// </summary>
|
||||
/// <returns>Array of configured Notification-Connectors</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<NotificationConnector[]>(Status200OK)]
|
||||
public IActionResult GetAllConnectors()
|
||||
{
|
||||
NotificationConnector[] ret = context.NotificationConnectors.ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Notification-Connector with requested ID
|
||||
/// </summary>
|
||||
/// <param name="id">Notification-Connector-ID</param>
|
||||
/// <returns>Notification-Connector</returns>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType<NotificationConnector>(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetConnector(string id)
|
||||
{
|
||||
NotificationConnector? ret = context.NotificationConnectors.Find(id);
|
||||
return (ret is not null) switch
|
||||
{
|
||||
true => Ok(ret),
|
||||
false => NotFound()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Notification-Connector
|
||||
/// </summary>
|
||||
/// <param name="notificationConnector">Notification-Connector</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPut]
|
||||
[ProducesResponseType<NotificationConnector[]>(Status200OK)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult CreateConnector([FromBody]NotificationConnector notificationConnector)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.NotificationConnectors.Add(notificationConnector);
|
||||
context.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the Notification-Connector with the requested ID
|
||||
/// </summary>
|
||||
/// <param name="id">Notification-Connector-ID</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult DeleteConnector(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
NotificationConnector? ret = context.NotificationConnectors.Find(id);
|
||||
switch (ret is not null)
|
||||
{
|
||||
case true:
|
||||
context.Remove(ret);
|
||||
context.SaveChanges();
|
||||
return Ok();
|
||||
case false: return NotFound();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
161
API/Controllers/SettingsController.cs
Normal file
161
API/Controllers/SettingsController.cs
Normal file
@ -0,0 +1,161 @@
|
||||
using API.Schema;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class SettingsController(PgsqlContext context) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all Settings
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetSettings()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current UserAgent used by Tranga
|
||||
/// </summary>
|
||||
/// <returns>UserAgent as string</returns>
|
||||
[HttpGet("UserAgent")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetUserAgent()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a new UserAgent
|
||||
/// </summary>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("UserAgent")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult SetUserAgent()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the UserAgent to default
|
||||
/// </summary>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("UserAgent")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult ResetUserAgent()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Request-Limits
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("RequestLimits")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetRequestLimits()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all Request-Limits to new values
|
||||
/// </summary>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("RequestLimits")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult SetRequestLimits()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset all Request-Limits
|
||||
/// </summary>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpDelete("RequestLimits")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult ResetRequestLimits()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Level of Image-Compression for Images
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ImageCompression")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetImageCompression()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the Image-Compression-Level for Images
|
||||
/// </summary>
|
||||
/// <param name="percentage">100 to disable, 0-99 for JPEG compression-Level</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("ImageCompression")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult SetImageCompression(int percentage)
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get state of Black/White-Image setting
|
||||
/// </summary>
|
||||
/// <returns>True if enabled</returns>
|
||||
[HttpGet("BWImages")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetBwImagesToggle()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable/Disable conversion of Images to Black and White
|
||||
/// </summary>
|
||||
/// <param name="enabled">true to enable</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("BWImages")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult SetBwImagesToggle(bool enabled)
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get state of April Fools Mode
|
||||
/// </summary>
|
||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||
/// <returns>True if enabled</returns>
|
||||
[HttpGet("AprilFoolsMode")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult GetAprilFoolsMode()
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable/Disable April Fools Mode
|
||||
/// </summary>
|
||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||
/// <param name="enabled">true to enable</param>
|
||||
/// <returns>Nothing</returns>
|
||||
[HttpPatch("AprilFoolsMode")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||
public IActionResult SetAprilFoolsMode(bool enabled)
|
||||
{
|
||||
return StatusCode(500, "Not implemented"); //TODO
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user