[CHANGES]

This commit is contained in:
max
2025-09-18 00:42:17 +02:00
parent ab532ac6dc
commit 9e173258ed
6 changed files with 18 additions and 27 deletions

View File

@@ -5,9 +5,9 @@
<ForcedLoadingOverlay Visible="_isLoading"/> <ForcedLoadingOverlay Visible="_isLoading"/>
@{ @{
var client = PreparingClient?.YouTubeClient; var client = ClientChannel?.YouTubeClient;
var clientState = client?.State; var clientState = client?.State;
var channel = PreparingClient?.Channel; var channel = ClientChannel?.Channel;
var avatar = channel?.AvatarImages.FirstOrDefault(); var avatar = channel?.AvatarImages.FirstOrDefault();
var banner = channel?.BannerImages.FirstOrDefault(); var banner = channel?.BannerImages.FirstOrDefault();
} }

View File

@@ -10,7 +10,7 @@ namespace Manager.App.Components.Dialogs
{ {
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; } [CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
[Parameter] public string DefaultUserAgent { get; set; } = ""; [Parameter] public string DefaultUserAgent { get; set; } = "";
private ClientPrep? PreparingClient { get; set; } private ClientChannel? ClientChannel { get; set; }
private CookieCollection ImportCookies { get; set; } = []; private CookieCollection ImportCookies { get; set; } = [];
private bool _isLoading; private bool _isLoading;
private AccountImportSteps _steps = AccountImportSteps.Authenticate; private AccountImportSteps _steps = AccountImportSteps.Authenticate;
@@ -21,7 +21,7 @@ namespace Manager.App.Components.Dialogs
private bool CanSave() private bool CanSave()
{ {
return PreparingClient?.YouTubeClient?.State?.LoggedIn == true; return ClientChannel?.YouTubeClient?.State?.LoggedIn == true;
} }
private bool CanContinue() private bool CanContinue()
@@ -35,7 +35,7 @@ namespace Manager.App.Components.Dialogs
} }
break; break;
case AccountImportSteps.Validate: case AccountImportSteps.Validate:
if (PreparingClient?.YouTubeClient?.State?.LoggedIn == true) if (ClientChannel?.YouTubeClient?.State?.LoggedIn == true)
{ {
return true; return true;
} }
@@ -61,7 +61,7 @@ namespace Manager.App.Components.Dialogs
case AccountImportSteps.Validate: case AccountImportSteps.Validate:
if (CanSave()) if (CanSave())
{ {
MudDialog?.Close(DialogResult.Ok(PreparingClient)); MudDialog?.Close(DialogResult.Ok(ClientChannel));
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
return; return;
} }
@@ -88,8 +88,8 @@ namespace Manager.App.Components.Dialogs
private void ClearPreparedClient() private void ClearPreparedClient()
{ {
PreparingClient?.YouTubeClient?.Dispose(); ClientChannel?.YouTubeClient?.Dispose();
PreparingClient = null; ClientChannel = null;
ImportCookies.Clear(); ImportCookies.Clear();
_steps = AccountImportSteps.Authenticate; _steps = AccountImportSteps.Authenticate;
StateHasChanged(); StateHasChanged();
@@ -142,24 +142,24 @@ namespace Manager.App.Components.Dialogs
private async Task BuildClient() private async Task BuildClient()
{ {
_isLoading = true; _isLoading = true;
PreparingClient = new ClientPrep(); ClientChannel = new ClientChannel();
var clientResult = await YouTubeClient.CreateAsync(ImportCookies, DefaultUserAgent); var clientResult = await YouTubeClient.CreateAsync(ImportCookies, DefaultUserAgent);
if (clientResult.IsSuccess) 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); SnackbarService.Add("Failed to get client!", Severity.Error);
_isLoading = false; _isLoading = false;
return; return;
} }
var accountResult = await PreparingClient.YouTubeClient.GetChannelByIdAsync(PreparingClient.YouTubeClient.Id); var accountResult = await ClientChannel.YouTubeClient.GetChannelByIdAsync(ClientChannel.YouTubeClient.Id);
if (accountResult.IsSuccess) if (accountResult.IsSuccess)
{ {
PreparingClient.Channel = accountResult.Value; ClientChannel.Channel = accountResult.Value;
} }
_isLoading = false; _isLoading = false;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);

View File

@@ -29,7 +29,7 @@ public partial class Channels : ComponentBase
return; return;
} }
var clientPrep = (ClientPrep)result.Data; var clientPrep = (ClientChannel)result.Data;
if (clientPrep?.YouTubeClient == null) if (clientPrep?.YouTubeClient == null)
{ {
return; return;

View File

@@ -8,14 +8,14 @@ namespace Manager.App.Controllers;
public class CacheController(ILogger<CacheController> logger, CacheService cacheService) : ControllerBase public class CacheController(ILogger<CacheController> logger, CacheService cacheService) : ControllerBase
{ {
[HttpGet] [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)) if (string.IsNullOrWhiteSpace(url))
{ {
return BadRequest("No url given."); return BadRequest("No url given.");
} }
var cacheResult = await cacheService.CacheFromUrl(url); var cacheResult = await cacheService.CacheFromUrl(url, cancellationToken);
if (!cacheResult.IsSuccess) if (!cacheResult.IsSuccess)
{ {
logger.LogError("Cache request failed. {ErrorMessage}", cacheResult.Error?.Description); logger.LogError("Cache request failed. {ErrorMessage}", cacheResult.Error?.Description);

View File

@@ -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; }
}

View File

@@ -1,6 +1,7 @@
using System.Net; using System.Net;
using DotBased.Logging; using DotBased.Logging;
using DotBased.Monads; using DotBased.Monads;
using Manager.App.Models.Library;
using Manager.Data.Entities.LibraryContext; using Manager.Data.Entities.LibraryContext;
using Manager.YouTube; using Manager.YouTube;
using Manager.YouTube.Models.Innertube; using Manager.YouTube.Models.Innertube;
@@ -10,7 +11,7 @@ namespace Manager.App.Services.System;
public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientService> logger) public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientService> logger)
: ExtendedBackgroundService(nameof(ClientService), "Managing YouTube clients", logger, TimeSpan.FromMinutes(10)) : ExtendedBackgroundService(nameof(ClientService), "Managing YouTube clients", logger, TimeSpan.FromMinutes(10))
{ {
private readonly List<YouTubeClient> _loadedClients = []; private readonly List<ClientChannel> _loadedClients = [];
private CancellationToken _cancellationToken; private CancellationToken _cancellationToken;
private ILibraryService? _libraryService; private ILibraryService? _libraryService;