diff --git a/back/src/Kyoo.Core/Controllers/MiscRepository.cs b/back/src/Kyoo.Core/Controllers/MiscRepository.cs index f3013a5e..06afb8ad 100644 --- a/back/src/Kyoo.Core/Controllers/MiscRepository.cs +++ b/back/src/Kyoo.Core/Controllers/MiscRepository.cs @@ -28,6 +28,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Postgresql; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using static System.Text.Json.JsonNamingPolicy; namespace Kyoo.Core.Controllers; @@ -82,4 +83,38 @@ public class MiscRepository( .Concat(context.Movies.Select(x => x.Path)) .ToListAsync(); } + + public async Task> GetRefreshableItems(DateTime end) + { + IQueryable GetItems() + where T : class, IResource, IRefreshable + { + return context + .Set() + .Select(x => new RefreshableItem + { + Kind = CamelCase.ConvertName(typeof(T).Name), + Id = x.Id, + RefreshDate = x.NextMetadataRefresh!.Value + }); + } + + return await GetItems() + .Concat(GetItems()) + .Concat(GetItems()) + .Concat(GetItems()) + .Concat(GetItems()) + .Where(x => x.RefreshDate <= end) + .OrderBy(x => x.RefreshDate) + .ToListAsync(); + } +} + +public class RefreshableItem +{ + public string Kind { get; set; } + + public Guid Id { get; set; } + + public DateTime RefreshDate { get; set; } } diff --git a/back/src/Kyoo.Core/Views/Admin/Misc.cs b/back/src/Kyoo.Core/Views/Admin/Misc.cs index dd54fea7..b2a35991 100644 --- a/back/src/Kyoo.Core/Views/Admin/Misc.cs +++ b/back/src/Kyoo.Core/Views/Admin/Misc.cs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . +using System; using System.Collections.Generic; using System.Threading.Tasks; using Kyoo.Abstractions.Models.Permissions; @@ -42,4 +43,16 @@ public class Misc(MiscRepository repo) : BaseApi { return repo.GetRegisteredPaths(); } + + /// + /// List items to refresh. + /// + /// The upper limit for the refresh date. + /// The items that should be refreshed before the given date + [HttpGet("/refreshables")] + [ProducesResponseType(StatusCodes.Status200OK)] + public Task> GetAllPaths([FromQuery] DateTime? date) + { + return repo.GetRefreshableItems(date ?? DateTime.UtcNow); + } }