diff --git a/back/src/Kyoo.Abstractions/Controllers/IScanner.cs b/back/src/Kyoo.Abstractions/Controllers/IScanner.cs index 62f14f9f..776131b5 100644 --- a/back/src/Kyoo.Abstractions/Controllers/IScanner.cs +++ b/back/src/Kyoo.Abstractions/Controllers/IScanner.cs @@ -23,5 +23,6 @@ namespace Kyoo.Abstractions.Controllers; public interface IScanner { + Task SendRescanRequest(); Task SendRefreshRequest(string kind, Guid id); } diff --git a/back/src/Kyoo.Core/Views/Admin/Misc.cs b/back/src/Kyoo.Core/Views/Admin/Misc.cs index 3f0f9c96..edd53514 100644 --- a/back/src/Kyoo.Core/Views/Admin/Misc.cs +++ b/back/src/Kyoo.Core/Views/Admin/Misc.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Permissions; using Kyoo.Core.Controllers; using Microsoft.AspNetCore.Http; @@ -65,6 +66,22 @@ public class Misc(MiscRepository repo) : BaseApi return NoContent(); } + /// + /// Rescan library + /// + /// + /// Trigger a complete library rescan + /// + /// Nothing + [HttpPost("/rescan")] + [PartialPermission(Kind.Write)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public async Task RescanLibrary([FromServices] IScanner scanner) + { + await scanner.SendRescanRequest(); + return NoContent(); + } + /// /// List items to refresh. /// diff --git a/back/src/Kyoo.Core/Views/Resources/ShowApi.cs b/back/src/Kyoo.Core/Views/Resources/ShowApi.cs index fb23e4f3..0517095a 100644 --- a/back/src/Kyoo.Core/Views/Resources/ShowApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/ShowApi.cs @@ -50,7 +50,7 @@ public class ShowApi(ILibraryManager libraryManager) : CrudThumbsApi(libra /// /// The ID or slug of the . /// Nothing - /// No episode with the given ID or slug could be found. + /// No show with the given ID or slug could be found. [HttpPost("{identifier:id}/refresh")] [PartialPermission(Kind.Write)] [ProducesResponseType(StatusCodes.Status204NoContent)] diff --git a/back/src/Kyoo.RabbitMq/ScannerProducer.cs b/back/src/Kyoo.RabbitMq/ScannerProducer.cs index bc9db49d..75c575a0 100644 --- a/back/src/Kyoo.RabbitMq/ScannerProducer.cs +++ b/back/src/Kyoo.RabbitMq/ScannerProducer.cs @@ -19,7 +19,6 @@ using System.Text; using System.Text.Json; using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models; using Kyoo.Utils; using RabbitMQ.Client; @@ -35,29 +34,17 @@ public class ScannerProducer : IScanner _channel.QueueDeclare("scanner", exclusive: false, autoDelete: false); } - private IRepository.ResourceEventHandler _Publish( - string exchange, - string type, - string action - ) - where T : IResource, IQuery + private Task _Publish(T message) { - return (T resource) => - { - Message message = - new() - { - Action = action, - Type = type, - Value = resource, - }; - _channel.BasicPublish( - exchange, - routingKey: message.AsRoutingKey(), - body: message.AsBytes() - ); - return Task.CompletedTask; - }; + var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(message, Utility.JsonOptions)); + _channel.BasicPublish("", routingKey: "scanner", body: body); + return Task.CompletedTask; + } + + public Task SendRescanRequest() + { + var message = new { Action = "rescan", }; + return _Publish(message); } public Task SendRefreshRequest(string kind, Guid id) @@ -68,8 +55,6 @@ public class ScannerProducer : IScanner Kind = kind.ToLowerInvariant(), Id = id }; - var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(message, Utility.JsonOptions)); - _channel.BasicPublish("", routingKey: "scanner", body: body); - return Task.CompletedTask; + return _Publish(message); } }