mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-07 15:42:10 +02:00
Compare commits
4 Commits
cef3b24efd
...
9521f66bac
Author | SHA1 | Date | |
---|---|---|---|
9521f66bac | |||
3981a41303 | |||
f2961711cf | |||
93ad691971 |
@ -1,3 +1,13 @@
|
|||||||
namespace API.APIEndpointRecords;
|
namespace API.APIEndpointRecords;
|
||||||
|
|
||||||
public record NewLibraryRecord(string path, string name);
|
public record NewLibraryRecord(string path, string name)
|
||||||
|
{
|
||||||
|
public bool Validate()
|
||||||
|
{
|
||||||
|
if (path.Length < 1) //TODO Better Path validation
|
||||||
|
return false;
|
||||||
|
if (name.Length < 1)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,33 @@ public class LocalLibrariesController(PgsqlContext context) : Controller
|
|||||||
return Ok(library);
|
return Ok(library);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{LibraryId}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public IActionResult UpdateLocalLibrary(string LibraryId, [FromBody]NewLibraryRecord record)
|
||||||
|
{
|
||||||
|
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
||||||
|
if (library is null)
|
||||||
|
return NotFound();
|
||||||
|
if (record.Validate() == false)
|
||||||
|
return BadRequest();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
library.LibraryName = record.name;
|
||||||
|
library.BasePath = record.path;
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPatch("{LibraryId}/ChangeBasePath")]
|
[HttpPatch("{LibraryId}/ChangeBasePath")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
@ -85,9 +112,12 @@ public class LocalLibrariesController(PgsqlContext context) : Controller
|
|||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
|
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreateNewLibrary([FromBody] NewLibraryRecord library)
|
public IActionResult CreateNewLibrary([FromBody]NewLibraryRecord library)
|
||||||
{
|
{
|
||||||
|
if (library.Validate() == false)
|
||||||
|
return BadRequest();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LocalLibrary newLibrary = new (library.path, library.name);
|
LocalLibrary newLibrary = new (library.path, library.name);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Text.Json.Nodes;
|
using API.MangaDownloadClients;
|
||||||
using API.MangaDownloadClients;
|
|
||||||
using API.Schema;
|
using API.Schema;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@ -17,10 +17,10 @@ public class SettingsController(PgsqlContext context) : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<string>(StatusCodes.Status200OK, "application/json")]
|
[ProducesResponseType<JObject>(Status200OK, "application/json")]
|
||||||
public IActionResult GetSettings()
|
public IActionResult GetSettings()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.Serialize());
|
return Ok(JObject.Parse(TrangaSettings.Serialize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -142,9 +142,9 @@ public class SettingsController(PgsqlContext context) : Controller
|
|||||||
[HttpPatch("ImageCompression")]
|
[HttpPatch("ImageCompression")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
public IActionResult SetImageCompression(int level)
|
public IActionResult SetImageCompression([FromBody]int level)
|
||||||
{
|
{
|
||||||
if (level < 0 || level > 100)
|
if (level < 1 || level > 100)
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
TrangaSettings.UpdateCompressImages(level);
|
TrangaSettings.UpdateCompressImages(level);
|
||||||
return Ok();
|
return Ok();
|
||||||
@ -168,7 +168,7 @@ public class SettingsController(PgsqlContext context) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpPatch("BWImages")]
|
[HttpPatch("BWImages")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
public IActionResult SetBwImagesToggle(bool enabled)
|
public IActionResult SetBwImagesToggle([FromBody]bool enabled)
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateBwImages(enabled);
|
TrangaSettings.UpdateBwImages(enabled);
|
||||||
return Ok();
|
return Ok();
|
||||||
@ -194,7 +194,7 @@ public class SettingsController(PgsqlContext context) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpPatch("AprilFoolsMode")]
|
[HttpPatch("AprilFoolsMode")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
public IActionResult SetAprilFoolsMode(bool enabled)
|
public IActionResult SetAprilFoolsMode([FromBody]bool enabled)
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateAprilFoolsMode(enabled);
|
TrangaSettings.UpdateAprilFoolsMode(enabled);
|
||||||
return Ok();
|
return Ok();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user