From 1e73998aa99e8093130c4ed92c9b3b1402603545 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 21 Apr 2024 19:42:48 +0200 Subject: [PATCH] Make scanner use new /paths route --- .../Permission/PermissionAttribute.cs | 2 +- .../Models/Utils/Constants.cs | 1 + .../src/Kyoo.Core/Views/{ => Admin}/Health.cs | 15 +------ back/src/Kyoo.Core/Views/Admin/Misc.cs | 45 +++++++++++++++++++ scanner/providers/kyoo_client.py | 17 +------ 5 files changed, 51 insertions(+), 29 deletions(-) rename back/src/Kyoo.Core/Views/{ => Admin}/Health.cs (83%) create mode 100644 back/src/Kyoo.Core/Views/Admin/Misc.cs diff --git a/back/src/Kyoo.Abstractions/Models/Attributes/Permission/PermissionAttribute.cs b/back/src/Kyoo.Abstractions/Models/Attributes/Permission/PermissionAttribute.cs index 29aad1e4..ba1ff743 100644 --- a/back/src/Kyoo.Abstractions/Models/Attributes/Permission/PermissionAttribute.cs +++ b/back/src/Kyoo.Abstractions/Models/Attributes/Permission/PermissionAttribute.cs @@ -94,7 +94,7 @@ public class PermissionAttribute : Attribute, IFilterFactory /// /// The group of this permission. /// - public Group Group { get; } + public Group Group { get; set; } /// /// Ask a permission to run an action. diff --git a/back/src/Kyoo.Abstractions/Models/Utils/Constants.cs b/back/src/Kyoo.Abstractions/Models/Utils/Constants.cs index 6db78c51..f12c44d5 100644 --- a/back/src/Kyoo.Abstractions/Models/Utils/Constants.cs +++ b/back/src/Kyoo.Abstractions/Models/Utils/Constants.cs @@ -56,4 +56,5 @@ public static class Constants /// A group name for . It should be used for endpoints used by admins. /// public const string AdminGroup = "4:Admin"; + public const string OtherGroup = "5:Other"; } diff --git a/back/src/Kyoo.Core/Views/Health.cs b/back/src/Kyoo.Core/Views/Admin/Health.cs similarity index 83% rename from back/src/Kyoo.Core/Views/Health.cs rename to back/src/Kyoo.Core/Views/Admin/Health.cs index 7680b3b4..3fa1d7aa 100644 --- a/back/src/Kyoo.Core/Views/Health.cs +++ b/back/src/Kyoo.Core/Views/Admin/Health.cs @@ -30,19 +30,8 @@ namespace Kyoo.Core.Api; [Route("health")] [ApiController] [ApiDefinition("Health")] -public class Health : BaseApi +public class Health(HealthCheckService healthCheckService) : BaseApi { - private readonly HealthCheckService _healthCheckService; - - /// - /// Create a new . - /// - /// The service to check health. - public Health(HealthCheckService healthCheckService) - { - _healthCheckService = healthCheckService; - } - /// /// Check if the api is ready to accept requests. /// @@ -57,7 +46,7 @@ public class Health : BaseApi headers.Pragma = "no-cache"; headers.Expires = "Thu, 01 Jan 1970 00:00:00 GMT"; - HealthReport result = await _healthCheckService.CheckHealthAsync(); + HealthReport result = await healthCheckService.CheckHealthAsync(); return result.Status switch { HealthStatus.Healthy => Ok(new HealthResult("Healthy")), diff --git a/back/src/Kyoo.Core/Views/Admin/Misc.cs b/back/src/Kyoo.Core/Views/Admin/Misc.cs new file mode 100644 index 00000000..dd54fea7 --- /dev/null +++ b/back/src/Kyoo.Core/Views/Admin/Misc.cs @@ -0,0 +1,45 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + +using System.Collections.Generic; +using System.Threading.Tasks; +using Kyoo.Abstractions.Models.Permissions; +using Kyoo.Core.Controllers; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Kyoo.Core.Api; + +/// +/// Private APIs only used for other services. Can change at any time without notice. +/// +[ApiController] +[Permission(nameof(Misc), Kind.Read, Group = Group.Admin)] +public class Misc(MiscRepository repo) : BaseApi +{ + /// + /// List all registered paths. + /// + /// The list of paths known to Kyoo. + [HttpGet("/paths")] + [ProducesResponseType(StatusCodes.Status200OK)] + public Task> GetAllPaths() + { + return repo.GetRegisteredPaths(); + } +} diff --git a/scanner/providers/kyoo_client.py b/scanner/providers/kyoo_client.py index 47a16c93..5c305ad6 100644 --- a/scanner/providers/kyoo_client.py +++ b/scanner/providers/kyoo_client.py @@ -36,25 +36,12 @@ class KyooClient: await self.client.close() async def get_registered_paths(self) -> List[str]: - paths = None async with self.client.get( - f"{self._url}/episodes", - params={"limit": 0}, + f"{self._url}/paths", headers={"X-API-Key": self._api_key}, ) as r: r.raise_for_status() - ret = await r.json() - paths = list(x["path"] for x in ret["items"]) - - async with self.client.get( - f"{self._url}/movies", - params={"limit": 0}, - headers={"X-API-Key": self._api_key}, - ) as r: - r.raise_for_status() - ret = await r.json() - paths += list(x["path"] for x in ret["items"]) - return paths + return await r.json() async def create_issue(self, path: str, issue: str, extra: dict | None = None): async with self.client.post(