[CHANGES]
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
<ForcedLoadingOverlay Visible="_isLoading"/>
|
||||
|
||||
@{
|
||||
var client = PreparingClient?.YouTubeClient;
|
||||
var client = ClientChannel?.YouTubeClient;
|
||||
var clientState = client?.State;
|
||||
var channel = PreparingClient?.Channel;
|
||||
var channel = ClientChannel?.Channel;
|
||||
var avatar = channel?.AvatarImages.FirstOrDefault();
|
||||
var banner = channel?.BannerImages.FirstOrDefault();
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace Manager.App.Components.Dialogs
|
||||
{
|
||||
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
|
||||
[Parameter] public string DefaultUserAgent { get; set; } = "";
|
||||
private ClientPrep? PreparingClient { get; set; }
|
||||
private ClientChannel? ClientChannel { get; set; }
|
||||
private CookieCollection ImportCookies { get; set; } = [];
|
||||
private bool _isLoading;
|
||||
private AccountImportSteps _steps = AccountImportSteps.Authenticate;
|
||||
@@ -21,7 +21,7 @@ namespace Manager.App.Components.Dialogs
|
||||
|
||||
private bool CanSave()
|
||||
{
|
||||
return PreparingClient?.YouTubeClient?.State?.LoggedIn == true;
|
||||
return ClientChannel?.YouTubeClient?.State?.LoggedIn == true;
|
||||
}
|
||||
|
||||
private bool CanContinue()
|
||||
@@ -35,7 +35,7 @@ namespace Manager.App.Components.Dialogs
|
||||
}
|
||||
break;
|
||||
case AccountImportSteps.Validate:
|
||||
if (PreparingClient?.YouTubeClient?.State?.LoggedIn == true)
|
||||
if (ClientChannel?.YouTubeClient?.State?.LoggedIn == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace Manager.App.Components.Dialogs
|
||||
case AccountImportSteps.Validate:
|
||||
if (CanSave())
|
||||
{
|
||||
MudDialog?.Close(DialogResult.Ok(PreparingClient));
|
||||
MudDialog?.Close(DialogResult.Ok(ClientChannel));
|
||||
await InvokeAsync(StateHasChanged);
|
||||
return;
|
||||
}
|
||||
@@ -88,8 +88,8 @@ namespace Manager.App.Components.Dialogs
|
||||
|
||||
private void ClearPreparedClient()
|
||||
{
|
||||
PreparingClient?.YouTubeClient?.Dispose();
|
||||
PreparingClient = null;
|
||||
ClientChannel?.YouTubeClient?.Dispose();
|
||||
ClientChannel = null;
|
||||
ImportCookies.Clear();
|
||||
_steps = AccountImportSteps.Authenticate;
|
||||
StateHasChanged();
|
||||
@@ -142,24 +142,24 @@ namespace Manager.App.Components.Dialogs
|
||||
private async Task BuildClient()
|
||||
{
|
||||
_isLoading = true;
|
||||
PreparingClient = new ClientPrep();
|
||||
ClientChannel = new ClientChannel();
|
||||
var clientResult = await YouTubeClient.CreateAsync(ImportCookies, DefaultUserAgent);
|
||||
if (clientResult.IsSuccess)
|
||||
{
|
||||
PreparingClient.YouTubeClient = clientResult.Value;
|
||||
ClientChannel.YouTubeClient = clientResult.Value;
|
||||
}
|
||||
|
||||
if (PreparingClient.YouTubeClient == null)
|
||||
if (ClientChannel.YouTubeClient == null)
|
||||
{
|
||||
SnackbarService.Add("Failed to get client!", Severity.Error);
|
||||
_isLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var accountResult = await PreparingClient.YouTubeClient.GetChannelByIdAsync(PreparingClient.YouTubeClient.Id);
|
||||
var accountResult = await ClientChannel.YouTubeClient.GetChannelByIdAsync(ClientChannel.YouTubeClient.Id);
|
||||
if (accountResult.IsSuccess)
|
||||
{
|
||||
PreparingClient.Channel = accountResult.Value;
|
||||
ClientChannel.Channel = accountResult.Value;
|
||||
}
|
||||
_isLoading = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
@@ -29,7 +29,7 @@ public partial class Channels : ComponentBase
|
||||
return;
|
||||
}
|
||||
|
||||
var clientPrep = (ClientPrep)result.Data;
|
||||
var clientPrep = (ClientChannel)result.Data;
|
||||
if (clientPrep?.YouTubeClient == null)
|
||||
{
|
||||
return;
|
||||
|
@@ -8,14 +8,14 @@ namespace Manager.App.Controllers;
|
||||
public class CacheController(ILogger<CacheController> logger, CacheService cacheService) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Cache([FromQuery(Name = "url")] string url)
|
||||
public async Task<IActionResult> Cache([FromQuery(Name = "url")] string url, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return BadRequest("No url given.");
|
||||
}
|
||||
|
||||
var cacheResult = await cacheService.CacheFromUrl(url);
|
||||
var cacheResult = await cacheService.CacheFromUrl(url, cancellationToken);
|
||||
if (!cacheResult.IsSuccess)
|
||||
{
|
||||
logger.LogError("Cache request failed. {ErrorMessage}", cacheResult.Error?.Description);
|
||||
|
@@ -1,10 +0,0 @@
|
||||
using Manager.YouTube;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
|
||||
namespace Manager.App.Models.Library;
|
||||
|
||||
public class ClientPrep
|
||||
{
|
||||
public YouTubeClient? YouTubeClient { get; set; }
|
||||
public Channel? Channel { get; set; }
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using DotBased.Logging;
|
||||
using DotBased.Monads;
|
||||
using Manager.App.Models.Library;
|
||||
using Manager.Data.Entities.LibraryContext;
|
||||
using Manager.YouTube;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
@@ -10,7 +11,7 @@ namespace Manager.App.Services.System;
|
||||
public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientService> logger)
|
||||
: ExtendedBackgroundService(nameof(ClientService), "Managing YouTube clients", logger, TimeSpan.FromMinutes(10))
|
||||
{
|
||||
private readonly List<YouTubeClient> _loadedClients = [];
|
||||
private readonly List<ClientChannel> _loadedClients = [];
|
||||
private CancellationToken _cancellationToken;
|
||||
private ILibraryService? _libraryService;
|
||||
|
||||
|
Reference in New Issue
Block a user