mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 11:58:19 +02:00
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using API.MangaConnectors;
|
|
using API.Schema.MangaContext;
|
|
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
|
|
|
namespace API.Controllers;
|
|
|
|
[ApiVersion(2)]
|
|
[ApiController]
|
|
[Route("v{v:apiVersion}/[controller]")]
|
|
public class MaintenanceController(MangaContext mangaContext) : Controller
|
|
{
|
|
|
|
/// <summary>
|
|
/// Removes all <see cref="Manga"/> not marked for Download on any <see cref="MangaConnector"/>
|
|
/// </summary>
|
|
/// <response code="200"></response>
|
|
/// <response code="500">Error during Database Operation</response>
|
|
[HttpPost("CleanupNoDownloadManga")]
|
|
[ProducesResponseType(Status200OK)]
|
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
public async Task<Results<Ok, InternalServerError<string>>> CleanupNoDownloadManga()
|
|
{
|
|
if (await mangaContext.Mangas
|
|
.Include(m => m.MangaConnectorIds)
|
|
.Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload))
|
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } noDownloads)
|
|
return TypedResults.InternalServerError("Could not fetch Manga");
|
|
|
|
mangaContext.Mangas.RemoveRange(noDownloads);
|
|
|
|
if(await mangaContext.Sync(HttpContext.RequestAborted) is { success: false } result)
|
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
|
return TypedResults.Ok();
|
|
}
|
|
} |