Make scanner use new /paths route

This commit is contained in:
Zoe Roux 2024-04-21 19:42:48 +02:00
parent c4b42c9961
commit 1e73998aa9
No known key found for this signature in database
5 changed files with 51 additions and 29 deletions

View File

@ -94,7 +94,7 @@ public class PermissionAttribute : Attribute, IFilterFactory
/// <summary> /// <summary>
/// The group of this permission. /// The group of this permission.
/// </summary> /// </summary>
public Group Group { get; } public Group Group { get; set; }
/// <summary> /// <summary>
/// Ask a permission to run an action. /// Ask a permission to run an action.

View File

@ -56,4 +56,5 @@ public static class Constants
/// A group name for <see cref="ApiDefinitionAttribute"/>. It should be used for endpoints used by admins. /// A group name for <see cref="ApiDefinitionAttribute"/>. It should be used for endpoints used by admins.
/// </summary> /// </summary>
public const string AdminGroup = "4:Admin"; public const string AdminGroup = "4:Admin";
public const string OtherGroup = "5:Other";
} }

View File

@ -30,19 +30,8 @@ namespace Kyoo.Core.Api;
[Route("health")] [Route("health")]
[ApiController] [ApiController]
[ApiDefinition("Health")] [ApiDefinition("Health")]
public class Health : BaseApi public class Health(HealthCheckService healthCheckService) : BaseApi
{ {
private readonly HealthCheckService _healthCheckService;
/// <summary>
/// Create a new <see cref="Health"/>.
/// </summary>
/// <param name="healthCheckService">The service to check health.</param>
public Health(HealthCheckService healthCheckService)
{
_healthCheckService = healthCheckService;
}
/// <summary> /// <summary>
/// Check if the api is ready to accept requests. /// Check if the api is ready to accept requests.
/// </summary> /// </summary>
@ -57,7 +46,7 @@ public class Health : BaseApi
headers.Pragma = "no-cache"; headers.Pragma = "no-cache";
headers.Expires = "Thu, 01 Jan 1970 00:00:00 GMT"; headers.Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
HealthReport result = await _healthCheckService.CheckHealthAsync(); HealthReport result = await healthCheckService.CheckHealthAsync();
return result.Status switch return result.Status switch
{ {
HealthStatus.Healthy => Ok(new HealthResult("Healthy")), HealthStatus.Healthy => Ok(new HealthResult("Healthy")),

View File

@ -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 <https://www.gnu.org/licenses/>.
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;
/// <summary>
/// Private APIs only used for other services. Can change at any time without notice.
/// </summary>
[ApiController]
[Permission(nameof(Misc), Kind.Read, Group = Group.Admin)]
public class Misc(MiscRepository repo) : BaseApi
{
/// <summary>
/// List all registered paths.
/// </summary>
/// <returns>The list of paths known to Kyoo.</returns>
[HttpGet("/paths")]
[ProducesResponseType(StatusCodes.Status200OK)]
public Task<ICollection<string>> GetAllPaths()
{
return repo.GetRegisteredPaths();
}
}

View File

@ -36,25 +36,12 @@ class KyooClient:
await self.client.close() await self.client.close()
async def get_registered_paths(self) -> List[str]: async def get_registered_paths(self) -> List[str]:
paths = None
async with self.client.get( async with self.client.get(
f"{self._url}/episodes", f"{self._url}/paths",
params={"limit": 0},
headers={"X-API-Key": self._api_key}, headers={"X-API-Key": self._api_key},
) as r: ) as r:
r.raise_for_status() r.raise_for_status()
ret = await r.json() return 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
async def create_issue(self, path: str, issue: str, extra: dict | None = None): async def create_issue(self, path: str, issue: str, extra: dict | None = None):
async with self.client.post( async with self.client.post(