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();
|
||||
}
|
||||
}
|
||||
10
backend/src/Services/IClientService.cs
Normal file
10
backend/src/Services/IClientService.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface IClientService
|
||||
{
|
||||
public Task<JellyfinApiClient[]> GetJellyfinClients();
|
||||
// public JellyfinApiClient GetClientForServer(string url);
|
||||
// public JellyfinApiClient GetClientForServerId(string serverId);
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
using JellyGlass.Repositories;
|
||||
|
||||
|
||||
using JellyGlass.Models;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface IServerService
|
||||
{
|
||||
public Task<JellyfinApiClient[]> GetJellyfinClients();
|
||||
// public JellyfinApiClient GetClientForServer(string url);
|
||||
// public JellyfinApiClient GetClientForServerId(string serverId);
|
||||
public Task<ServerDTO[]> GetServers();
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ namespace JellyGlass.Services;
|
|||
|
||||
public class LibraryService : ILibraryService
|
||||
{
|
||||
private IServerService _serverService;
|
||||
private IClientService _serverService;
|
||||
|
||||
public LibraryService(IServerService serverService)
|
||||
public LibraryService(IClientService serverService)
|
||||
{
|
||||
_serverService = serverService;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using JellyGlass.Exceptions;
|
||||
|
||||
|
||||
using JellyGlass.Models;
|
||||
using JellyGlass.Repositories;
|
||||
|
||||
|
|
@ -6,47 +7,24 @@ namespace JellyGlass.Services;
|
|||
|
||||
public class ServerService : IServerService
|
||||
{
|
||||
private IServerRepository _repository;
|
||||
private static JellyfinApiClient[] _clients = [];
|
||||
private ILogger<ServerService> _logger;
|
||||
private readonly IServerRepository _repository;
|
||||
|
||||
public ServerService(IServerRepository repository, ILogger<ServerService> logger)
|
||||
public ServerService(IServerRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<JellyfinApiClient[]> GetJellyfinClients()
|
||||
{
|
||||
if (!_clients.Any())
|
||||
{
|
||||
await LoadClients();
|
||||
}
|
||||
|
||||
return _clients;
|
||||
}
|
||||
|
||||
private async Task LoadClients()
|
||||
public async Task<ServerDTO[]> GetServers()
|
||||
{
|
||||
var servers = await _repository.GetServers();
|
||||
var clients = new List<JellyfinApiClient>();
|
||||
|
||||
foreach (var server in servers)
|
||||
var dtos = new List<ServerDTO>();
|
||||
|
||||
foreach (var s in servers)
|
||||
{
|
||||
var client = new JellyfinApiClient(server.Url, server.Username, server.Password);
|
||||
|
||||
try
|
||||
{
|
||||
await client.Authenticate();
|
||||
}
|
||||
catch (JellyfinApiClientException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
clients.Add(client);
|
||||
dtos.Add(new ServerDTO(s));
|
||||
}
|
||||
|
||||
_clients = clients.ToArray();
|
||||
return dtos.ToArray();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue