Refactored archive editor to not bind archives and handle service calls through uploader.
Fixes #40net8.0
parent
3dbee36886
commit
ce402cf5c1
|
@ -46,15 +46,14 @@
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="AddArchive" />
|
<ArchiveUploader @ref="Uploader" GameId="GameId" RedistributableId="RedistributableId" OnArchiveUploaded="LoadData" />
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public Guid GameId { get; set; }
|
[Parameter] public Guid GameId { get; set; }
|
||||||
[Parameter] public Guid RedistributableId { get; set; }
|
[Parameter] public Guid RedistributableId { get; set; }
|
||||||
[Parameter] public ICollection<Archive> Archives { get; set; }
|
|
||||||
[Parameter] public EventCallback<ICollection<Archive>> ArchivesChanged { get; set; }
|
|
||||||
|
|
||||||
Archive Archive;
|
ICollection<Archive> Archives { get; set; }
|
||||||
|
|
||||||
ArchiveUploader Uploader;
|
ArchiveUploader Uploader;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
|
@ -70,9 +69,6 @@
|
||||||
Archives = await ArchiveService.Get(a => a.GameId == GameId).ToListAsync();
|
Archives = await ArchiveService.Get(a => a.GameId == GameId).ToListAsync();
|
||||||
else if (RedistributableId != Guid.Empty)
|
else if (RedistributableId != Guid.Empty)
|
||||||
Archives = await ArchiveService.Get(a => a.RedistributableId == RedistributableId).ToListAsync();
|
Archives = await ArchiveService.Get(a => a.RedistributableId == RedistributableId).ToListAsync();
|
||||||
|
|
||||||
if (ArchivesChanged.HasDelegate)
|
|
||||||
await ArchivesChanged.InvokeAsync(Archives);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Download(Archive archive)
|
private async Task Download(Archive archive)
|
||||||
|
@ -84,27 +80,7 @@
|
||||||
|
|
||||||
private async Task UploadArchive()
|
private async Task UploadArchive()
|
||||||
{
|
{
|
||||||
if (GameId != Guid.Empty)
|
await Uploader.Open();
|
||||||
Archive = new Archive() { GameId = GameId, Id = Guid.NewGuid() };
|
|
||||||
|
|
||||||
if (RedistributableId != Guid.Empty)
|
|
||||||
Archive = new Archive() { RedistributableId = RedistributableId, Id = Guid.NewGuid() };
|
|
||||||
|
|
||||||
await Uploader.Open(Archive);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task AddArchive(Archive archive)
|
|
||||||
{
|
|
||||||
var lastArchive = Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault();
|
|
||||||
|
|
||||||
Archive = await ArchiveService.Add(archive);
|
|
||||||
|
|
||||||
await LoadData();
|
|
||||||
|
|
||||||
var settings = SettingService.GetSettings();
|
|
||||||
|
|
||||||
if (lastArchive != null && settings.Archives.EnablePatching)
|
|
||||||
BackgroundJob.Enqueue<PatchArchiveBackgroundJob>(x => x.Execute(lastArchive.Id, Archive.Id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete(Archive archive)
|
private async Task Delete(Archive archive)
|
||||||
|
@ -113,6 +89,8 @@
|
||||||
{
|
{
|
||||||
await ArchiveService.Delete(archive);
|
await ArchiveService.Delete(archive);
|
||||||
|
|
||||||
|
await LoadData();
|
||||||
|
|
||||||
await MessageService.Success("Archive deleted!");
|
await MessageService.Success("Archive deleted!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
@using System.Diagnostics;
|
@using System.Diagnostics;
|
||||||
@using Hangfire;
|
@using Hangfire;
|
||||||
@using LANCommander.Jobs.Background;
|
@using LANCommander.Jobs.Background;
|
||||||
|
@using Microsoft.EntityFrameworkCore;
|
||||||
@inject HttpClient HttpClient
|
@inject HttpClient HttpClient
|
||||||
@inject NavigationManager Navigator
|
@inject NavigationManager Navigator
|
||||||
@inject ArchiveService ArchiveService
|
@inject ArchiveService ArchiveService
|
||||||
|
@ -62,7 +63,9 @@
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public EventCallback<Archive> OnArchiveUploaded { get; set; }
|
[Parameter] public Guid GameId { get; set; }
|
||||||
|
[Parameter] public Guid RedistributableId { get; set; }
|
||||||
|
[Parameter] public EventCallback<Guid> OnArchiveUploaded { get; set; }
|
||||||
|
|
||||||
Archive Archive;
|
Archive Archive;
|
||||||
|
|
||||||
|
@ -113,9 +116,21 @@
|
||||||
File = args.File;
|
File = args.File;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Open(Archive archive)
|
public async Task Open(Guid? archiveId = null)
|
||||||
{
|
{
|
||||||
Archive = archive;
|
if (archiveId.HasValue && archiveId != Guid.Empty)
|
||||||
|
{
|
||||||
|
Archive = await ArchiveService.Get(archiveId.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Archive = new Archive();
|
||||||
|
|
||||||
|
if (GameId != Guid.Empty)
|
||||||
|
Archive.GameId = GameId;
|
||||||
|
else if (RedistributableId != Guid.Empty)
|
||||||
|
Archive.RedistributableId = RedistributableId;
|
||||||
|
}
|
||||||
|
|
||||||
Visible = true;
|
Visible = true;
|
||||||
|
|
||||||
|
@ -128,8 +143,8 @@
|
||||||
{
|
{
|
||||||
if (FileInput != null)
|
if (FileInput != null)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrWhiteSpace(archive.ObjectKey) && archive.ObjectKey != Guid.Empty.ToString())
|
if (!String.IsNullOrWhiteSpace(Archive.ObjectKey) && Archive.ObjectKey != Guid.Empty.ToString())
|
||||||
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", archive.ObjectKey.ToString());
|
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", Archive.ObjectKey.ToString());
|
||||||
else
|
else
|
||||||
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", "");
|
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", "");
|
||||||
|
|
||||||
|
@ -163,12 +178,32 @@
|
||||||
Archive.ObjectKey = objectKey.ToString();
|
Archive.ObjectKey = objectKey.ToString();
|
||||||
Archive.CompressedSize = File.Size;
|
Archive.CompressedSize = File.Size;
|
||||||
|
|
||||||
|
if (Archive.Id != Guid.Empty)
|
||||||
|
Archive = await ArchiveService.Update(Archive);
|
||||||
|
else
|
||||||
|
Archive = await ArchiveService.Add(Archive);
|
||||||
|
|
||||||
Visible = false;
|
Visible = false;
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
Archive? lastArchive = null;
|
||||||
|
|
||||||
|
var settings = SettingService.GetSettings();
|
||||||
|
|
||||||
|
if (settings.Archives.EnablePatching)
|
||||||
|
{
|
||||||
|
if (Archive.GameId != Guid.Empty)
|
||||||
|
lastArchive = await ArchiveService.Get(a => a.Id != Archive.Id && a.GameId == Archive.GameId).OrderByDescending(a => a.CreatedOn).FirstOrDefaultAsync();
|
||||||
|
else if (Archive.RedistributableId != Guid.Empty)
|
||||||
|
lastArchive = await ArchiveService.Get(a => a.Id != Archive.Id && a.RedistributableId == Archive.RedistributableId).OrderByDescending(a => a.CreatedOn).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (lastArchive != null && settings.Archives.EnablePatching)
|
||||||
|
BackgroundJob.Enqueue<PatchArchiveBackgroundJob>(x => x.Execute(lastArchive.Id, Archive.Id));
|
||||||
|
}
|
||||||
|
|
||||||
if (OnArchiveUploaded.HasDelegate)
|
if (OnArchiveUploaded.HasDelegate)
|
||||||
await OnArchiveUploaded.InvokeAsync(Archive);
|
await OnArchiveUploaded.InvokeAsync(Archive.Id);
|
||||||
|
|
||||||
await MessageService.Success("Archive uploaded!");
|
await MessageService.Success("Archive uploaded!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-panel="Archives">
|
<div data-panel="Archives">
|
||||||
<ArchiveEditor @bind-Archives="Game.Archives" GameId="Game.Id" />
|
<ArchiveEditor GameId="Game.Id" />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-panel="Archives">
|
<div data-panel="Archives">
|
||||||
<ArchiveEditor @bind-Archives="Redistributable.Archives" RedistributableId="Redistributable.Id" />
|
<ArchiveEditor RedistributableId="Redistributable.Id" />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
</ActionColumn>
|
</ActionColumn>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="OnArchiveUploaded" />
|
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="LoadData" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,21 +78,7 @@
|
||||||
|
|
||||||
System.IO.File.Create(archiveFilePath).Close();
|
System.IO.File.Create(archiveFilePath).Close();
|
||||||
|
|
||||||
await Uploader.Open(archive);
|
await Uploader.Open(archive.Id);
|
||||||
}
|
|
||||||
|
|
||||||
async Task OnArchiveUploaded(Archive archive)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await ArchiveService.Update(archive);
|
|
||||||
|
|
||||||
await LoadData();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
await MessageService.Error("Archive could not be updated.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task Delete(Archive archive)
|
async Task Delete(Archive archive)
|
||||||
|
|
Loading…
Reference in New Issue