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>
|
||||
</Space>
|
||||
|
||||
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="AddArchive" />
|
||||
<ArchiveUploader @ref="Uploader" GameId="GameId" RedistributableId="RedistributableId" OnArchiveUploaded="LoadData" />
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid GameId { 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;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
|
@ -70,9 +69,6 @@
|
|||
Archives = await ArchiveService.Get(a => a.GameId == GameId).ToListAsync();
|
||||
else if (RedistributableId != Guid.Empty)
|
||||
Archives = await ArchiveService.Get(a => a.RedistributableId == RedistributableId).ToListAsync();
|
||||
|
||||
if (ArchivesChanged.HasDelegate)
|
||||
await ArchivesChanged.InvokeAsync(Archives);
|
||||
}
|
||||
|
||||
private async Task Download(Archive archive)
|
||||
|
@ -84,27 +80,7 @@
|
|||
|
||||
private async Task UploadArchive()
|
||||
{
|
||||
if (GameId != Guid.Empty)
|
||||
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));
|
||||
await Uploader.Open();
|
||||
}
|
||||
|
||||
private async Task Delete(Archive archive)
|
||||
|
@ -113,6 +89,8 @@
|
|||
{
|
||||
await ArchiveService.Delete(archive);
|
||||
|
||||
await LoadData();
|
||||
|
||||
await MessageService.Success("Archive deleted!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
@using System.Diagnostics;
|
||||
@using Hangfire;
|
||||
@using LANCommander.Jobs.Background;
|
||||
@using Microsoft.EntityFrameworkCore;
|
||||
@inject HttpClient HttpClient
|
||||
@inject NavigationManager Navigator
|
||||
@inject ArchiveService ArchiveService
|
||||
|
@ -62,7 +63,9 @@
|
|||
</Modal>
|
||||
|
||||
@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;
|
||||
|
||||
|
@ -113,9 +116,21 @@
|
|||
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;
|
||||
|
||||
|
@ -128,8 +143,8 @@
|
|||
{
|
||||
if (FileInput != null)
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(archive.ObjectKey) && archive.ObjectKey != Guid.Empty.ToString())
|
||||
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", archive.ObjectKey.ToString());
|
||||
if (!String.IsNullOrWhiteSpace(Archive.ObjectKey) && Archive.ObjectKey != Guid.Empty.ToString())
|
||||
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", Archive.ObjectKey.ToString());
|
||||
else
|
||||
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", "");
|
||||
|
||||
|
@ -163,12 +178,32 @@
|
|||
Archive.ObjectKey = objectKey.ToString();
|
||||
Archive.CompressedSize = File.Size;
|
||||
|
||||
if (Archive.Id != Guid.Empty)
|
||||
Archive = await ArchiveService.Update(Archive);
|
||||
else
|
||||
Archive = await ArchiveService.Add(Archive);
|
||||
|
||||
Visible = false;
|
||||
|
||||
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)
|
||||
await OnArchiveUploaded.InvokeAsync(Archive);
|
||||
await OnArchiveUploaded.InvokeAsync(Archive.Id);
|
||||
|
||||
await MessageService.Success("Archive uploaded!");
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@
|
|||
</div>
|
||||
|
||||
<div data-panel="Archives">
|
||||
<ArchiveEditor @bind-Archives="Game.Archives" GameId="Game.Id" />
|
||||
<ArchiveEditor GameId="Game.Id" />
|
||||
</div>
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
|
||||
<div data-panel="Archives">
|
||||
<ArchiveEditor @bind-Archives="Redistributable.Archives" RedistributableId="Redistributable.Id" />
|
||||
<ArchiveEditor RedistributableId="Redistributable.Id" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</ActionColumn>
|
||||
</Table>
|
||||
|
||||
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="OnArchiveUploaded" />
|
||||
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="LoadData" />
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -78,21 +78,7 @@
|
|||
|
||||
System.IO.File.Create(archiveFilePath).Close();
|
||||
|
||||
await Uploader.Open(archive);
|
||||
}
|
||||
|
||||
async Task OnArchiveUploaded(Archive archive)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ArchiveService.Update(archive);
|
||||
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await MessageService.Error("Archive could not be updated.");
|
||||
}
|
||||
await Uploader.Open(archive.Id);
|
||||
}
|
||||
|
||||
async Task Delete(Archive archive)
|
||||
|
|
Loading…
Reference in New Issue