mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Shared UI - Added HttpClientUtilities offering progressable stream content
Submission wizard - Added upload progress Submission wizard - Close on finish
This commit is contained in:
1 parent
ad4da3032d
commit
a1fd8d5099
10 files changed
+249
-16
No files matched your search
@@ -25,6 +25,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Artemis.Core\Artemis.Core.csproj" />
|
||||
<ProjectReference Include="..\Artemis.UI.Shared\Artemis.UI.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers;
|
||||
|
||||
public interface IEntryUploadHandler
|
||||
{
|
||||
Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, CancellationToken cancellationToken);
|
||||
Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken);
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
using RGB.NET.Layout;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers.Implementations;
|
||||
|
||||
public class LayoutEntryUploadHandler : IEntryUploadHandler
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, CancellationToken cancellationToken)
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
+6
-5
@@ -3,6 +3,7 @@ using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.Web.Workshop.Entities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, CancellationToken cancellationToken)
|
||||
public async Task<EntryUploadResult> CreateReleaseAsync(Guid entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
if (file is not ProfileConfiguration profileConfiguration)
|
||||
throw new InvalidOperationException("Can only create releases for profile configurations");
|
||||
@@ -42,19 +43,19 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
|
||||
// Submit the archive
|
||||
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);
|
||||
|
||||
|
||||
// Construct the request
|
||||
archiveStream.Seek(0, SeekOrigin.Begin);
|
||||
MultipartFormDataContent content = new();
|
||||
StreamContent streamContent = new(archiveStream);
|
||||
ProgressableStreamContent streamContent = new(archiveStream, progress);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
content.Add(streamContent, "file", "file.zip");
|
||||
|
||||
|
||||
// Submit
|
||||
HttpResponseMessage response = await client.PostAsync("releases/upload/" + entryId, content, cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
||||
|
||||
|
||||
Release? release = JsonConvert.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
||||
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user