mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 01:44:17 +02:00
292 lines
9.1 KiB
C#
292 lines
9.1 KiB
C#
using API.MangaDownloadClients;
|
|
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
namespace API.Controllers;
|
|
|
|
[ApiVersion(2)]
|
|
[ApiController]
|
|
[Route("v{v:apiVersion}/[controller]")]
|
|
public class SettingsController() : Controller
|
|
{
|
|
/// <summary>
|
|
/// Get all <see cref="Tranga.Settings"/>
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpGet]
|
|
[ProducesResponseType<TrangaSettings>(Status200OK, "application/json")]
|
|
public IActionResult GetSettings()
|
|
{
|
|
return Ok(Tranga.Settings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the current UserAgent used by Tranga
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpGet("UserAgent")]
|
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
|
public IActionResult GetUserAgent()
|
|
{
|
|
return Ok(Tranga.Settings.UserAgent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set a new UserAgent
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpPatch("UserAgent")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult SetUserAgent([FromBody]string userAgent)
|
|
{
|
|
//TODO Validate
|
|
Tranga.Settings.SetUserAgent(userAgent);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset the UserAgent to default
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpDelete("UserAgent")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult ResetUserAgent()
|
|
{
|
|
Tranga.Settings.SetUserAgent(TrangaSettings.DefaultUserAgent);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all Request-Limits
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpGet("RequestLimits")]
|
|
[ProducesResponseType<Dictionary<RequestType,int>>(Status200OK, "application/json")]
|
|
public IActionResult GetRequestLimits()
|
|
{
|
|
return Ok(Tranga.Settings.RequestLimits);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update all Request-Limits to new values
|
|
/// </summary>
|
|
/// <remarks><h1>NOT IMPLEMENTED</h1></remarks>
|
|
[HttpPatch("RequestLimits")]
|
|
[ProducesResponseType(Status501NotImplemented)]
|
|
public IActionResult SetRequestLimits()
|
|
{
|
|
return StatusCode(501);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates a Request-Limit value
|
|
/// </summary>
|
|
/// <param name="RequestType">Type of Request</param>
|
|
/// <param name="requestLimit">New limit in Requests/Minute</param>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">Limit needs to be greater than 0</response>
|
|
[HttpPatch("RequestLimits/{RequestType}")]
|
|
[ProducesResponseType(Status200OK)]
|
|
[ProducesResponseType(Status400BadRequest)]
|
|
public IActionResult SetRequestLimit(RequestType RequestType, [FromBody]int requestLimit)
|
|
{
|
|
if (requestLimit <= 0)
|
|
return BadRequest();
|
|
Tranga.Settings.SetRequestLimit(RequestType, requestLimit);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset Request-Limit
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpDelete("RequestLimits/{RequestType}")]
|
|
[ProducesResponseType<string>(Status200OK)]
|
|
public IActionResult ResetRequestLimits(RequestType RequestType)
|
|
{
|
|
Tranga.Settings.SetRequestLimit(RequestType, TrangaSettings.DefaultRequestLimits[RequestType]);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset Request-Limit
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpDelete("RequestLimits")]
|
|
[ProducesResponseType<string>(Status200OK)]
|
|
public IActionResult ResetRequestLimits()
|
|
{
|
|
Tranga.Settings.ResetRequestLimits();
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns Level of Image-Compression for Images
|
|
/// </summary>
|
|
/// <response code="200">JPEG ImageCompression-level as Integer</response>
|
|
[HttpGet("ImageCompressionLevel")]
|
|
[ProducesResponseType<int>(Status200OK, "text/plain")]
|
|
public IActionResult GetImageCompression()
|
|
{
|
|
return Ok(Tranga.Settings.ImageCompression);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the Image-Compression-Level for Images
|
|
/// </summary>
|
|
/// <param name="level">100 to disable, 0-99 for JPEG ImageCompression-Level</param>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">Level outside permitted range</response>
|
|
[HttpPatch("ImageCompressionLevel/{level}")]
|
|
[ProducesResponseType(Status200OK)]
|
|
[ProducesResponseType(Status400BadRequest)]
|
|
public IActionResult SetImageCompression(int level)
|
|
{
|
|
if (level < 1 || level > 100)
|
|
return BadRequest();
|
|
Tranga.Settings.UpdateImageCompression(level);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get state of Black/White-Image setting
|
|
/// </summary>
|
|
/// <response code="200">True if enabled</response>
|
|
[HttpGet("BWImages")]
|
|
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
|
public IActionResult GetBwImagesToggle()
|
|
{
|
|
return Ok(Tranga.Settings.BlackWhiteImages);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enable/Disable conversion of Images to Black and White
|
|
/// </summary>
|
|
/// <param name="enabled">true to enable</param>
|
|
/// <response code="200"></response>
|
|
[HttpPatch("BWImages/{enabled}")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult SetBwImagesToggle(bool enabled)
|
|
{
|
|
Tranga.Settings.SetBlackWhiteImageEnabled(enabled);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Chapter Naming Scheme
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Placeholders:
|
|
/// %M Obj Name
|
|
/// %V Volume
|
|
/// %C Chapter
|
|
/// %T Title
|
|
/// %A Author (first in list)
|
|
/// %I Chapter Internal ID
|
|
/// %i Obj Internal ID
|
|
/// %Y Year (Obj)
|
|
///
|
|
/// ?_(...) replace _ with a value from above:
|
|
/// Everything inside the braces will only be added if the value of %_ is not null
|
|
/// </remarks>
|
|
/// <response code="200"></response>
|
|
[HttpGet("ChapterNamingScheme")]
|
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
|
public IActionResult GetCustomNamingScheme()
|
|
{
|
|
return Ok(Tranga.Settings.ChapterNamingScheme);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the Chapter Naming Scheme
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Placeholders:
|
|
/// %M Obj Name
|
|
/// %V Volume
|
|
/// %C Chapter
|
|
/// %T Title
|
|
/// %A Author (first in list)
|
|
/// %Y Year (Obj)
|
|
///
|
|
/// ?_(...) replace _ with a value from above:
|
|
/// Everything inside the braces will only be added if the value of %_ is not null
|
|
/// </remarks>
|
|
/// <response code="200"></response>
|
|
[HttpPatch("ChapterNamingScheme")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult SetCustomNamingScheme([FromBody]string namingScheme)
|
|
{
|
|
//TODO Move old Chapters
|
|
Tranga.Settings.SetChapterNamingScheme(namingScheme);
|
|
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the FlareSolverr-URL
|
|
/// </summary>
|
|
/// <param name="flareSolverrUrl">URL of FlareSolverr-Instance</param>
|
|
/// <response code="200"></response>
|
|
[HttpPost("FlareSolverr/Url")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult SetFlareSolverrUrl([FromBody]string flareSolverrUrl)
|
|
{
|
|
Tranga.Settings.SetFlareSolverrUrl(flareSolverrUrl);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the FlareSolverr-URL (HttpClient does not use FlareSolverr anymore)
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpDelete("FlareSolverr/Url")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult ClearFlareSolverrUrl()
|
|
{
|
|
Tranga.Settings.SetFlareSolverrUrl(string.Empty);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test FlareSolverr
|
|
/// </summary>
|
|
/// <response code="200">FlareSolverr is working!</response>
|
|
/// <response code="500">FlareSolverr is not working</response>
|
|
[HttpPost("FlareSolverr/Test")]
|
|
[ProducesResponseType(Status200OK)]
|
|
[ProducesResponseType(Status500InternalServerError)]
|
|
public IActionResult TestFlareSolverrReachable()
|
|
{
|
|
const string knownProtectedUrl = "https://prowlarr.servarr.com/v1/ping";
|
|
FlareSolverrDownloadClient client = new();
|
|
RequestResult result = client.MakeRequestInternal(knownProtectedUrl);
|
|
return (int)result.statusCode >= 200 && (int)result.statusCode < 300 ? Ok() : StatusCode(500, result.statusCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the language in which Manga are downloaded
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpGet("DownloadLanguage")]
|
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
|
public IActionResult GetDownloadLanguage()
|
|
{
|
|
return Ok(Tranga.Settings.DownloadLanguage);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the language in which Manga are downloaded
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
[HttpPatch("DownloadLanguage/{Language}")]
|
|
[ProducesResponseType(Status200OK)]
|
|
public IActionResult SetDownloadLanguage(string Language)
|
|
{
|
|
//TODO Validation
|
|
Tranga.Settings.SetDownloadLanguage(Language);
|
|
return Ok();
|
|
}
|
|
} |