Merge branch 'develop' of https://github.com/ombi-app/Ombi into develop

pull/4252/head
tidusjar 3 years ago
commit 5080a1e9d0

@ -23,7 +23,7 @@ namespace Ombi.Api.Plex
Task<PlexFriends> GetUsers(string authToken);
Task<PlexAccount> GetAccount(string authToken);
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
Task<OAuthPin> GetPin(int pinId);
Task<OAuthContainer> GetPin(int pinId);
Task<Uri> GetOAuthUrl(string code, string applicationUrl);
Task<PlexAddWrapper> AddUser(string emailAddress, string serverId, string authToken, int[] libs);
}

@ -1,7 +1,14 @@
using System;
using System.Collections.Generic;
namespace Ombi.Api.Plex.Models.OAuth
{
public class OAuthContainer
{
public OAuthPin Result { get; set; }
public OAuthErrorsContainer Errors { get; set; }
}
public class OAuthPin
{
public int id { get; set; }
@ -24,4 +31,15 @@ namespace Ombi.Api.Plex.Models.OAuth
public string coordinates { get; set; }
}
public class OAuthErrorsContainer
{
public List<OAuthErrors> errors { get; set; }
}
public class OAuthErrors
{
public int code { get; set; }
public string message { get; set; }
}
}

@ -1,7 +1,7 @@
using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Ombi.Api.Plex.Models;
using Ombi.Api.Plex.Models.Friends;
using Ombi.Api.Plex.Models.OAuth;
@ -208,12 +208,28 @@ namespace Ombi.Api.Plex
return await Api.Request<PlexMetadata>(request);
}
public async Task<OAuthPin> GetPin(int pinId)
public async Task<OAuthContainer> GetPin(int pinId)
{
var request = new Request($"api/v2/pins/{pinId}", "https://plex.tv/", HttpMethod.Get);
await AddHeaders(request);
return await Api.Request<OAuthPin>(request);
var response = await Api.RequestContent(request);
if (response.Contains("errors"))
{
var errors = JsonConvert.DeserializeObject<OAuthErrorsContainer>(response, Ombi.Api.Api.Settings);
return new OAuthContainer
{
Errors = errors
};
}
var pinResult = JsonConvert.DeserializeObject<OAuthPin>(response, Ombi.Api.Api.Settings);
return new OAuthContainer
{
Result = pinResult
};
}
public async Task<Uri> GetOAuthUrl(string code, string applicationUrl)

@ -73,7 +73,7 @@ namespace Ombi.Api
}
// do something with the response
var receivedString = await httpResponseMessage.Content.ReadAsStringAsync();
var receivedString = await httpResponseMessage.Content.ReadAsStringAsync(cancellationToken);
LogDebugContent(receivedString);
if (request.ContentType == ContentType.Json)
{

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Ombi.Api.Plex;
using Ombi.Api.Plex.Models;
using Ombi.Api.Plex.Models.OAuth;
@ -11,24 +13,37 @@ namespace Ombi.Core.Authentication
{
public class PlexOAuthManager : IPlexOAuthManager
{
public PlexOAuthManager(IPlexApi api, ISettingsService<CustomizationSettings> settings)
public PlexOAuthManager(IPlexApi api, ISettingsService<CustomizationSettings> settings, ILogger<PlexOAuthManager> logger)
{
_api = api;
_customizationSettingsService = settings;
_logger = logger;
}
private readonly IPlexApi _api;
private readonly ISettingsService<CustomizationSettings> _customizationSettingsService;
private readonly ILogger _logger;
public async Task<string> GetAccessTokenFromPin(int pinId)
{
var pin = await _api.GetPin(pinId);
if (pin.expiresAt < DateTime.UtcNow)
if (pin.Errors != null)
{
foreach (var err in pin.Errors?.errors ?? new List<OAuthErrors>())
{
_logger.LogError($"Code: '{err.code}' : '{err.message}'");
}
return string.Empty;
}
if (pin.Result.expiresIn <= 0)
{
_logger.LogError("Pin has expired");
return string.Empty;
}
return pin.authToken;
return pin.Result.authToken;
}
public async Task<PlexAccount> GetAccount(string accessToken)

@ -82,6 +82,11 @@
<i class="fas fa-plus"></i> {{ 'Requests.MarkAvailable' | translate }}
</button>
<button id="markUnavailableBtn" *ngIf="movie.available" (click)="markUnavailable()" mat-raised-button class="btn-spacing"
color="accent">
<i class="fas fa-minus"></i> {{ 'Requests.MarkUnavailable' | translate }}
</button>
<button id="denyBtn" *ngIf="movieRequest && !movieRequest.denied" mat-raised-button class="btn-spacing" color="warn" (click)="deny()">
<i class="fas fa-times"></i> {{'Requests.Deny' | translate }}
</button>

@ -168,6 +168,17 @@ export class MovieDetailsComponent {
}
}
public async markUnavailable() {
const result = await this.requestService.markMovieUnavailable({ id: this.movieRequest.id }).toPromise();
if (result.result) {
this.movie.available = false;
this.messageService.send(result.message, "Ok");
} else {
this.messageService.send(result.errorMessage, "Ok");
}
}
public setAdvancedOptions(data: IAdvancedData) {
this.advancedOptions = data;
if (data.rootFolderId) {

@ -9,7 +9,8 @@
<div class="row">
<div
class="mobile-top-text">
<h1 id="mediaTitle" class="large-text">{{title}} <span *ngIf="releaseDate" class="grey-text">
<h1 id="mediaTitle" class="large-text">{{title}}
<span *ngIf="releaseDateFormat" class="grey-text">
({{releaseDate | amLocal | amDateFormat: 'YYYY'}})</span>
</h1>

@ -13,6 +13,12 @@ export class TopBannerComponent {
@Input() available: boolean;
@Input() background: any;
get releaseDateFormat(): Date|null {
if (this.releaseDate && this.releaseDate instanceof Date && this.releaseDate.getFullYear() !== 1) {
return this.releaseDate;
}
return null;
}
constructor(private sanitizer:DomSanitizer){ }

@ -20,6 +20,7 @@ export class PlexTvService {
"X-Plex-Device": "Ombi (Web)",
"X-Plex-Platform": "Web",
"Accept": "application/json",
'X-Plex-Model': 'Plex OAuth',
});
return this.http.post<IPlexPin>("https://plex.tv/api/v2/pins?strong=true", null, {headers});
}

@ -1,4 +1,4 @@
<settings-menu>
<settings-menu>
</settings-menu>
<div class="small-middle-container">
<div *ngIf="form">
@ -55,7 +55,7 @@
<mat-form-field appearance="outline">
<mat-label>Quality Profiles</mat-label>
<mat-select formControlName="defaultProfileId">
<mat-option *ngFor="let profile of profiles" value="{{profile._id}}">{{profile.label}}</mat-option>
<mat-option *ngFor="let profile of profiles?.list" value="{{profile._id}}">{{profile.label}}</mat-option>
</mat-select>
<mat-error>A Default Quality Profile is required</mat-error>
</mat-form-field>

Loading…
Cancel
Save