-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from pticostaricags/development
Adding localization to UpdateVideoPlan. Converting to code-behind
- Loading branch information
Showing
4 changed files
with
147 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
...airPlayCombinedSln/FairPlayCombined.Models/FairPlayTube/VideoPlan/UpdateVideoPlanModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
using FairPlayCombined.Common.GeneratorsAttributes; | ||
using FairPlayCombined.Common.CustomAttributes; | ||
using FairPlayCombined.Common.GeneratorsAttributes; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace FairPlayCombined.Models.FairPlayTube.VideoPlan | ||
{ | ||
public class UpdateVideoPlanModel : IUpdateModel | ||
{ | ||
[Key] | ||
public long VideoPlanId { get; set; } | ||
|
||
[Required] | ||
[CustomRequired] | ||
public string? ApplicationUserId { get; set; } | ||
|
||
[Required] | ||
[StringLength(50)] | ||
[CustomRequired] | ||
[CustomStringLength(50)] | ||
public string? VideoName { get; set; } | ||
|
||
[Required] | ||
[StringLength(500)] | ||
[CustomRequired] | ||
[CustomStringLength(500)] | ||
public string? VideoDescription { get; set; } | ||
|
||
[Required] | ||
[StringLength(1000)] | ||
[CustomRequired] | ||
[CustomStringLength(1000)] | ||
public string? VideoScript { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...irPlayCombinedSln/FairPlayTube.SharedUI/Components/Pages/Creator/UpdateVideoPlan.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using FairPlayCombined.Interfaces.Common; | ||
using FairPlayCombined.Interfaces.FairPlayTube; | ||
using FairPlayCombined.Interfaces; | ||
using FairPlayCombined.Models.AzureVideoIndexer; | ||
using FairPlayCombined.Models.FairPlayTube.VideoPlan; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.FluentUI.AspNetCore.Components; | ||
using FairPlayCombined.Common.CustomAttributes; | ||
using Microsoft.Extensions.Localization; | ||
|
||
namespace FairPlayTube.SharedUI.Components.Pages.Creator | ||
{ | ||
public partial class UpdateVideoPlan | ||
{ | ||
[Parameter] | ||
public long? VideoPlanId { get; set; } | ||
[SupplyParameterFromForm] | ||
private UpdateVideoPlanModel updateVideoPlanModel { get; set; } = new(); | ||
[Inject] IPromptGeneratorService? PromptGeneratorService { get; set; } | ||
[Inject] IOpenAIService? OpenAIService { get; set; } | ||
[Inject] IAzureVideoIndexerService? AzureVideoIndexerService { get; set; } | ||
[Inject] IVideoPlanService? VideoPlanService { get; set; } | ||
[Inject] IToastService? ToastService { get; set; } | ||
[Inject] IUserProviderService? UserProviderService { get; set; } | ||
[Inject] IYouTubeClientService? YouTubeClientService { get; set; } | ||
[Inject] ILogger<CreateVideoPlan>? Logger { get; set; } | ||
[Inject] NavigationManager? NavigationManager { get; set; } | ||
[Inject] AzureVideoIndexerServiceConfiguration? AzureVideoIndexerServiceConfiguration { get; set; } | ||
[Inject] IStringLocalizer<UpdateVideoPlan>? Localizer { get; set; } | ||
private readonly CancellationTokenSource cancellationTokenSource = new(); | ||
private bool IsBusy { get; set; } | ||
private string? GeneratedYouTubeThumbnailUri { get; set; } | ||
private string? RevisedPrompt { get; set; } | ||
private VideoPlanModel? originalVideoPlan { get; set; } | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
this.updateVideoPlanModel.ApplicationUserId = this.UserProviderService!.GetCurrentUserId(); | ||
if (this.originalVideoPlan is null) | ||
{ | ||
this.originalVideoPlan = await this.VideoPlanService!.GetVideoPlanByIdAsync(this.VideoPlanId!.Value, this.cancellationTokenSource.Token); | ||
this.updateVideoPlanModel.VideoPlanId = this.VideoPlanId.Value; | ||
this.updateVideoPlanModel.VideoName = this.originalVideoPlan.VideoName; | ||
this.updateVideoPlanModel.VideoDescription = this.originalVideoPlan.VideoDescription; | ||
this.updateVideoPlanModel.VideoScript = this.originalVideoPlan.VideoScript; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.ToastService!.ShowError(ex.Message); | ||
} | ||
finally | ||
{ | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
private async Task OnValidSubmitAsync() | ||
{ | ||
try | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
await this.VideoPlanService!.UpdateVideoPlanAsync( | ||
this.updateVideoPlanModel, this.cancellationTokenSource.Token); | ||
this.ToastService!.ShowSuccess(Localizer![PlanUpdatedTextKey]); | ||
StateHasChanged(); | ||
var promptInfo = await this.PromptGeneratorService!.GetPromptCompleteInfoAsync(promptName: | ||
"YouTubeThumbnail", cancellationToken: this.cancellationTokenSource.Token); | ||
string prompt = $"{promptInfo!.BaseText}. Video Title: {this.updateVideoPlanModel.VideoName}. Video Description: {this.updateVideoPlanModel.VideoDescription}. Video Script: {this.updateVideoPlanModel.VideoScript}"; | ||
if (prompt.Length > 4000) | ||
prompt = prompt.Substring(0, 4000); | ||
var result = await this.OpenAIService!.GenerateDallE3ImageAsync(prompt, this.cancellationTokenSource.Token); | ||
if (result != null) | ||
{ | ||
this.GeneratedYouTubeThumbnailUri = result!.data![0]!.url!; | ||
this.RevisedPrompt = result!.data[0]!.revised_prompt; | ||
this.ToastService!.ShowSuccess(Localizer![ThumbnailCreatedTextKey]); | ||
} | ||
else | ||
{ | ||
this.ToastService!.ShowError(Localizer![ThumbnailWasNotCreatedTextKey]); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.ToastService!.ShowError(ex.Message); | ||
} | ||
finally | ||
{ | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
await this.cancellationTokenSource.CancelAsync(); | ||
this.cancellationTokenSource.Dispose(); | ||
} | ||
|
||
#region Resource Keys | ||
[ResourceKey(defaultValue: "Update Video Plan")] | ||
public const string UpdateVideoPlanTextKey = "UpdateVideoPlanText"; | ||
[ResourceKey(defaultValue: "Name")] | ||
public const string NameTextKey = "NameText"; | ||
[ResourceKey(defaultValue: "Description")] | ||
public const string DescriptionTextKey = "DescriptionText"; | ||
[ResourceKey(defaultValue: "Video Script")] | ||
public const string VideoScriptTextKey = "VideoScriptText"; | ||
[ResourceKey(defaultValue: "Save")] | ||
public const string SaveTextKey = "SaveText"; | ||
[ResourceKey(defaultValue: "Your Plan has been updated")] | ||
public const string PlanUpdatedTextKey = "PlanUpdatedText"; | ||
[ResourceKey(defaultValue: "Your thumbnail has been created")] | ||
public const string ThumbnailCreatedTextKey = "ThumbnailCreatedTextKey"; | ||
[ResourceKey(defaultValue: "Your thumbnail could not be created")] | ||
public const string ThumbnailWasNotCreatedTextKey = "ThumbnailWasNotCreatedText"; | ||
#endregion Resource Keys | ||
} | ||
} |