#1506 #865 Fixed an issue with the test buttons not working correctly

pull/1515/head
tidusjar 7 years ago
parent 573c0b5f33
commit dd610fd5fb

@ -14,6 +14,12 @@ export interface IPlexLibraries {
mediaContainer: IMediaContainer; mediaContainer: IMediaContainer;
} }
export interface IPlexLibResponse {
successful: boolean;
message: string;
data:IPlexLibraries;
}
export interface IMediaContainer { export interface IMediaContainer {
directory: IDirectory[]; directory: IDirectory[];
} }

@ -6,7 +6,7 @@ import { Observable } from "rxjs/Rx";
import { ServiceAuthHelpers } from "../service.helpers"; import { ServiceAuthHelpers } from "../service.helpers";
import { IPlexAuthentication, IPlexLibraries, IPlexServerViewModel } from "../../interfaces"; import { IPlexAuthentication, IPlexLibResponse, IPlexServerViewModel } from "../../interfaces";
import { IPlexServer } from "../../interfaces"; import { IPlexServer } from "../../interfaces";
@Injectable() @Injectable()
@ -23,7 +23,7 @@ export class PlexService extends ServiceAuthHelpers {
return this.http.post(`${this.url}servers`, JSON.stringify({ login, password }), { headers: this.headers }).map(this.extractData); return this.http.post(`${this.url}servers`, JSON.stringify({ login, password }), { headers: this.headers }).map(this.extractData);
} }
public getLibraries(plexSettings: IPlexServer): Observable<IPlexLibraries> { public getLibraries(plexSettings: IPlexServer): Observable<IPlexLibResponse> {
return this.http.post(`${this.url}Libraries`, JSON.stringify(plexSettings), { headers: this.headers }).map(this.extractData).catch(this.handleError); return this.http.post(`${this.url}Libraries`, JSON.stringify(plexSettings), { headers: this.headers }).map(this.extractData).catch(this.handleError);
} }

@ -1,4 +1,5 @@
import { Headers, Http, Response } from "@angular/http"; import { Headers, Http, Response } from "@angular/http";
import "rxjs/add/observable/throw";
import { Observable } from "rxjs/Observable"; import { Observable } from "rxjs/Observable";
import { AuthHttp } from "angular2-jwt"; import { AuthHttp } from "angular2-jwt";

@ -39,7 +39,7 @@ export class EmbyComponent implements OnInit {
public test(server: IEmbyServer) { public test(server: IEmbyServer) {
this.testerService.embyTest(server).subscribe(x => { this.testerService.embyTest(server).subscribe(x => {
if (x) { if (x === true) {
this.notificationService.success("Connected", `Successfully connected to the Emby server ${server.name}!`); this.notificationService.success("Connected", `Successfully connected to the Emby server ${server.name}!`);
} else { } else {
this.notificationService.error("Connected", `We could not connect to the Emby server ${server.name}!`); this.notificationService.error("Connected", `We could not connect to the Emby server ${server.name}!`);

@ -60,7 +60,7 @@ export class PlexComponent implements OnInit, OnDestroy {
public testPlex(server: IPlexServer) { public testPlex(server: IPlexServer) {
this.testerService.plexTest(server).subscribe(x => { this.testerService.plexTest(server).subscribe(x => {
if (x) { if (x === true) {
this.notificationService.success("Connected", `Successfully connected to the Plex server ${server.name}!`); this.notificationService.success("Connected", `Successfully connected to the Plex server ${server.name}!`);
} else { } else {
this.notificationService.error("Connected", `We could not connect to the Plex server ${server.name}!`); this.notificationService.error("Connected", `We could not connect to the Plex server ${server.name}!`);
@ -90,15 +90,19 @@ export class PlexComponent implements OnInit, OnDestroy {
} }
this.plexService.getLibraries(server).subscribe(x => { this.plexService.getLibraries(server).subscribe(x => {
server.plexSelectedLibraries = []; server.plexSelectedLibraries = [];
x.mediaContainer.directory.forEach((item, index) => { if (x.successful) {
const lib: IPlexLibrariesSettings = { x.data.mediaContainer.directory.forEach((item) => {
key: item.key, const lib: IPlexLibrariesSettings = {
title: item.title, key: item.key,
enabled: false, title: item.title,
}; enabled: false,
server.plexSelectedLibraries.push(lib); };
}); server.plexSelectedLibraries.push(lib);
}, });
} else {
this.notificationService.error("Error", x.message);
}
},
err => { this.notificationService.error("Error", err); }); err => { this.notificationService.error("Error", err); });
} }

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Ombi.Api.Plex; using Ombi.Api.Plex;
using Ombi.Api.Plex.Models; using Ombi.Api.Plex.Models;
using Ombi.Attributes; using Ombi.Attributes;
@ -18,14 +19,17 @@ namespace Ombi.Controllers.External
[Produces("application/json")] [Produces("application/json")]
public class PlexController : Controller public class PlexController : Controller
{ {
public PlexController(IPlexApi plexApi, ISettingsService<PlexSettings> plexSettings) public PlexController(IPlexApi plexApi, ISettingsService<PlexSettings> plexSettings,
ILogger<PlexController> logger)
{ {
PlexApi = plexApi; PlexApi = plexApi;
PlexSettings = plexSettings; PlexSettings = plexSettings;
_log = logger;
} }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISettingsService<PlexSettings> PlexSettings { get; } private ISettingsService<PlexSettings> PlexSettings { get; }
private readonly ILogger<PlexController> _log;
/// <summary> /// <summary>
/// Signs into the Plex API. /// Signs into the Plex API.
@ -88,11 +92,29 @@ namespace Ombi.Controllers.External
/// <param name="settings">The settings.</param> /// <param name="settings">The settings.</param>
/// <returns></returns> /// <returns></returns>
[HttpPost("Libraries")] [HttpPost("Libraries")]
public async Task<PlexContainer> GetPlexLibraries([FromBody] PlexServers settings) public async Task<PlexLibrariesResponse> GetPlexLibraries([FromBody] PlexServers settings)
{ {
var libs = await PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri); try
{
var libs = await PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri);
return new PlexLibrariesResponse
{
Successful = true,
Data = libs
};
}
catch (Exception e)
{
_log.LogWarning(e,"Error thrown when attempting to obtain the plex libs");
return libs; var message = e.InnerException != null ? $"{e.Message} - {e.InnerException.Message}" : e.Message;
return new PlexLibrariesResponse
{
Successful = false,
Message = message
};
}
} }
/// <summary> /// <summary>

@ -0,0 +1,38 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: PlexLibrariesResponse.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using Ombi.Api.Plex.Models;
namespace Ombi.Models.External
{
public class PlexLibrariesResponse
{
public PlexContainer Data { get; set; }
public bool Successful { get; set; }
public string Message { get; set; }
}
}
Loading…
Cancel
Save