Got index server list working
This commit is contained in:
parent
36d99b1e35
commit
271cf1f407
19 changed files with 445 additions and 67 deletions
51
backend/src/Services/ClientService.cs
Normal file
51
backend/src/Services/ClientService.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using JellyGlass.Exceptions;
|
||||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public class ClientService : IClientService
|
||||
{
|
||||
private IServerRepository _repository;
|
||||
private static JellyfinApiClient[] _clients = [];
|
||||
private ILogger<ClientService> _logger;
|
||||
|
||||
public ClientService(IServerRepository repository, ILogger<ClientService> logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<JellyfinApiClient[]> GetJellyfinClients()
|
||||
{
|
||||
if (!_clients.Any())
|
||||
{
|
||||
await LoadClients();
|
||||
}
|
||||
|
||||
return _clients;
|
||||
}
|
||||
|
||||
private async Task LoadClients()
|
||||
{
|
||||
var servers = await _repository.GetServers();
|
||||
var clients = new List<JellyfinApiClient>();
|
||||
|
||||
foreach (var server in servers)
|
||||
{
|
||||
var client = new JellyfinApiClient(server.Url, server.Username, server.Password);
|
||||
|
||||
try
|
||||
{
|
||||
await client.Authenticate();
|
||||
}
|
||||
catch (JellyfinApiClientException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
clients.Add(client);
|
||||
}
|
||||
|
||||
_clients = clients.ToArray();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue