don't look at me
This commit is contained in:
parent
e9f444e5b4
commit
cedbad8fba
56 changed files with 1111 additions and 294 deletions
14
backend/src/Services/ILibraryService.cs
Normal file
14
backend/src/Services/ILibraryService.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using JellyGlass.Models;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface ILibraryService
|
||||
{
|
||||
public Task<Library[]> GetLibraries();
|
||||
public Task<ItemDTO[]> GetItemsFromLibrary(string libraryName);
|
||||
|
||||
|
||||
// public Task<ItemDTO[]> GetChildrenFromItems(ItemDTO[] items);
|
||||
// public Task<ItemDTO[]> GetItemsByName(string name, string itemType);
|
||||
// public Task<ItemDTO[]> GetItemsByType(string itemType);
|
||||
}
|
||||
10
backend/src/Services/IServerService.cs
Normal file
10
backend/src/Services/IServerService.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface IServerService
|
||||
{
|
||||
public Task<JellyfinApiClient[]> GetJellyfinClients();
|
||||
// public JellyfinApiClient GetClientForServer(string url);
|
||||
// public JellyfinApiClient GetClientForServerId(string serverId);
|
||||
}
|
||||
74
backend/src/Services/LibraryService.cs
Normal file
74
backend/src/Services/LibraryService.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using JellyGlass.Models;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public class LibraryService : ILibraryService
|
||||
{
|
||||
private IServerService _serverService;
|
||||
|
||||
public LibraryService(IServerService serverService)
|
||||
{
|
||||
_serverService = serverService;
|
||||
}
|
||||
|
||||
public async Task<Library[]> GetLibraries()
|
||||
{
|
||||
var clients = await _serverService.GetJellyfinClients();
|
||||
|
||||
var libraries = new Dictionary<string, Library>();
|
||||
|
||||
foreach (var client in clients)
|
||||
{
|
||||
var clientLibraries = await client.GetInstanceLibraries();
|
||||
|
||||
foreach (var library in clientLibraries.Items)
|
||||
{
|
||||
if (!libraries.ContainsKey(library.Name))
|
||||
{
|
||||
|
||||
libraries.Add(library.Name, new Library()
|
||||
{
|
||||
Name = library.Name,
|
||||
ThumbnailUrl = $"{client.InstanceUrl}/Items/{library.Id}/Primary"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return libraries.Values.ToArray();
|
||||
}
|
||||
|
||||
public async Task<ItemDTO[]> GetItemsFromLibrary(string libraryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// public async Task<ItemDTO[]> GetChildrenFromItems(ItemDTO[] items)
|
||||
// {
|
||||
// var children = new List<ItemDTO>();
|
||||
|
||||
// foreach (var item in items)
|
||||
// {
|
||||
// var client = _serverService.GetClientForServerId(item.ServerID);
|
||||
|
||||
// var itemChildren = await client.GetItemChildren(item.ID);
|
||||
|
||||
// foreach (var child in itemChildren.Items)
|
||||
// {
|
||||
// children.Add(new ItemDTO(child, client.InstanceUrl));
|
||||
// }
|
||||
// }
|
||||
|
||||
// return children.ToArray();
|
||||
// }
|
||||
|
||||
// public async Task<ItemDTO> GetItemsByName(string name, string itemType)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// public async Task<ItemDTO> GetItemsByType(string itemType)
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
52
backend/src/Services/ServerService.cs
Normal file
52
backend/src/Services/ServerService.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using JellyGlass.Exceptions;
|
||||
using JellyGlass.Models;
|
||||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public class ServerService : IServerService
|
||||
{
|
||||
private IServerRepository _repository;
|
||||
private static JellyfinApiClient[] _clients = [];
|
||||
private ILogger<ServerService> _logger;
|
||||
|
||||
public ServerService(IServerRepository repository, ILogger<ServerService> 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