mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Add a private route to get items to auto refresh
This commit is contained in:
parent
58f0f3d74b
commit
9ee35534bd
@ -28,6 +28,7 @@ using Kyoo.Abstractions.Models;
|
|||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using static System.Text.Json.JsonNamingPolicy;
|
||||||
|
|
||||||
namespace Kyoo.Core.Controllers;
|
namespace Kyoo.Core.Controllers;
|
||||||
|
|
||||||
@ -82,4 +83,38 @@ public class MiscRepository(
|
|||||||
.Concat(context.Movies.Select(x => x.Path))
|
.Concat(context.Movies.Select(x => x.Path))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<RefreshableItem>> GetRefreshableItems(DateTime end)
|
||||||
|
{
|
||||||
|
IQueryable<RefreshableItem> GetItems<T>()
|
||||||
|
where T : class, IResource, IRefreshable
|
||||||
|
{
|
||||||
|
return context
|
||||||
|
.Set<T>()
|
||||||
|
.Select(x => new RefreshableItem
|
||||||
|
{
|
||||||
|
Kind = CamelCase.ConvertName(typeof(T).Name),
|
||||||
|
Id = x.Id,
|
||||||
|
RefreshDate = x.NextMetadataRefresh!.Value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return await GetItems<Show>()
|
||||||
|
.Concat(GetItems<Movie>())
|
||||||
|
.Concat(GetItems<Season>())
|
||||||
|
.Concat(GetItems<Episode>())
|
||||||
|
.Concat(GetItems<Collection>())
|
||||||
|
.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; }
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Models.Permissions;
|
using Kyoo.Abstractions.Models.Permissions;
|
||||||
@ -42,4 +43,16 @@ public class Misc(MiscRepository repo) : BaseApi
|
|||||||
{
|
{
|
||||||
return repo.GetRegisteredPaths();
|
return repo.GetRegisteredPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List items to refresh.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="date">The upper limit for the refresh date.</param>
|
||||||
|
/// <returns>The items that should be refreshed before the given date</returns>
|
||||||
|
[HttpGet("/refreshables")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public Task<ICollection<RefreshableItem>> GetAllPaths([FromQuery] DateTime? date)
|
||||||
|
{
|
||||||
|
return repo.GetRefreshableItems(date ?? DateTime.UtcNow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user