mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Profile upload - Use new format
This commit is contained in:
parent
23f80895b6
commit
c75e839756
@ -499,12 +499,6 @@ internal class ProfileService : IProfileService
|
||||
SaveProfileConfigurationIcon(profileConfiguration);
|
||||
}
|
||||
|
||||
if (exportModel.ProfileImage != null)
|
||||
{
|
||||
profileConfiguration.Icon.SetIconByStream(exportModel.ProfileImage);
|
||||
SaveProfileConfigurationIcon(profileConfiguration);
|
||||
}
|
||||
|
||||
profileConfiguration.Entity.ProfileId = profileEntity.Id;
|
||||
category.AddProfileConfiguration(profileConfiguration, 0);
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Extensions;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.DownloadHandlers.Implementations;
|
||||
|
||||
@ -26,13 +24,8 @@ public class ProfileEntryDownloadHandler : IEntryDownloadHandler
|
||||
using MemoryStream stream = new();
|
||||
await client.DownloadDataAsync($"releases/download/{releaseId}", stream, progress, cancellationToken);
|
||||
|
||||
using ZipArchive zipArchive = new(stream, ZipArchiveMode.Read);
|
||||
List<ZipArchiveEntry> profiles = zipArchive.Entries.Where(e => e.Name.EndsWith("json", StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||
ZipArchiveEntry userProfileEntry = profiles.First();
|
||||
ProfileConfigurationExportModel profile = await GetProfile(userProfileEntry);
|
||||
|
||||
ProfileCategory category = _profileService.ProfileCategories.FirstOrDefault(c => c.Name == "Workshop") ?? _profileService.CreateProfileCategory("Workshop", true);
|
||||
ProfileConfiguration profileConfiguration = _profileService.ImportProfile(category, profile, true, true, null);
|
||||
ProfileConfiguration profileConfiguration = await _profileService.ImportProfile(stream, category, true, true, null);
|
||||
return EntryInstallResult<ProfileConfiguration>.FromSuccess(profileConfiguration);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -40,12 +33,4 @@ public class ProfileEntryDownloadHandler : IEntryDownloadHandler
|
||||
return EntryInstallResult<ProfileConfiguration>.FromFailure(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ProfileConfigurationExportModel> GetProfile(ZipArchiveEntry userProfileEntry)
|
||||
{
|
||||
await using Stream stream = userProfileEntry.Open();
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
return JsonConvert.DeserializeObject<ProfileConfigurationExportModel>(await reader.ReadToEndAsync(), IProfileService.ExportSettings)!;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core;
|
||||
namespace Artemis.WebClient.Workshop.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// An exception thrown when a web client related error occurs
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
namespace Artemis.WebClient.Workshop.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// An exception thrown when a workshop related error occurs
|
||||
/// </summary>
|
||||
public class ArtemisWorkshopException : Exception
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ArtemisWorkshopException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisWorkshopException(string? message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisWorkshopException(string? message, Exception? innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.WebClient.Workshop.Exceptions;
|
||||
using IdentityModel.Client;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
@ -7,6 +7,7 @@ using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Artemis.Core;
|
||||
using Artemis.WebClient.Workshop.Exceptions;
|
||||
using Artemis.WebClient.Workshop.Repositories;
|
||||
using DynamicData;
|
||||
using IdentityModel;
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Net.Http.Headers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.Web.Workshop.Entities;
|
||||
using Newtonsoft.Json;
|
||||
@ -26,26 +25,12 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
if (file is not ProfileConfiguration profileConfiguration)
|
||||
throw new InvalidOperationException("Can only create releases for profile configurations");
|
||||
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(profileConfiguration);
|
||||
string json = JsonConvert.SerializeObject(export, IProfileService.ExportSettings);
|
||||
|
||||
using MemoryStream archiveStream = new();
|
||||
|
||||
// Create a ZIP archive with a single entry on the archive stream
|
||||
using (ZipArchive archive = new(archiveStream, ZipArchiveMode.Create, true))
|
||||
{
|
||||
ZipArchiveEntry entry = archive.CreateEntry("profile.json");
|
||||
await using (Stream entryStream = entry.Open())
|
||||
{
|
||||
await entryStream.WriteAsync(Encoding.Default.GetBytes(json), cancellationToken);
|
||||
}
|
||||
}
|
||||
await using Stream archiveStream = await _profileService.ExportProfile(profileConfiguration);
|
||||
|
||||
// Submit the archive
|
||||
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);
|
||||
|
||||
// Construct the request
|
||||
archiveStream.Seek(0, SeekOrigin.Begin);
|
||||
MultipartFormDataContent content = new();
|
||||
ProgressableStreamContent streamContent = new(archiveStream, progress);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user