find working plex connection on startup (#438)
This commit is contained in:
@@ -6,6 +6,12 @@ namespace ErsatzTV.Infrastructure.Plex
|
||||
{
|
||||
public interface IPlexServerApi
|
||||
{
|
||||
[Get("/")]
|
||||
[Headers("Accept: application/json")]
|
||||
public Task Ping(
|
||||
[Query] [AliasAs("X-Plex-Token")]
|
||||
string token);
|
||||
|
||||
[Get("/library/sections")]
|
||||
[Headers("Accept: application/json")]
|
||||
public Task<PlexMediaContainerResponse<PlexMediaContainerDirectoryContent<PlexLibraryResponse>>> GetLibraries(
|
||||
|
||||
@@ -30,6 +30,28 @@ namespace ErsatzTV.Infrastructure.Plex
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<bool> Ping(
|
||||
PlexConnection connection,
|
||||
PlexServerAuthToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
IPlexServerApi service = RestService.For<IPlexServerApi>(
|
||||
new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(connection.Uri),
|
||||
Timeout = TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
await service.Ping(token.AuthToken);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Either<BaseError, List<PlexLibrary>>> GetLibraries(
|
||||
PlexConnection connection,
|
||||
PlexServerAuthToken token)
|
||||
|
||||
Reference in New Issue
Block a user