diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index 4ab6424e4..3975713f2 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -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); diff --git a/src/Artemis.WebClient.Workshop/DownloadHandlers/Implementations/ProfileEntryDownloadHandler.cs b/src/Artemis.WebClient.Workshop/DownloadHandlers/Implementations/ProfileEntryDownloadHandler.cs index 496072c9c..cb7e6e7a6 100644 --- a/src/Artemis.WebClient.Workshop/DownloadHandlers/Implementations/ProfileEntryDownloadHandler.cs +++ b/src/Artemis.WebClient.Workshop/DownloadHandlers/Implementations/ProfileEntryDownloadHandler.cs @@ -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 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.FromSuccess(profileConfiguration); } catch (Exception e) @@ -40,12 +33,4 @@ public class ProfileEntryDownloadHandler : IEntryDownloadHandler return EntryInstallResult.FromFailure(e.Message); } } - - private async Task GetProfile(ZipArchiveEntry userProfileEntry) - { - await using Stream stream = userProfileEntry.Open(); - using StreamReader reader = new(stream); - - return JsonConvert.DeserializeObject(await reader.ReadToEndAsync(), IProfileService.ExportSettings)!; - } } \ No newline at end of file diff --git a/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWebClientException.cs b/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWebClientException.cs index 1bd2af386..a5400594c 100644 --- a/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWebClientException.cs +++ b/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWebClientException.cs @@ -1,6 +1,4 @@ -using System; - -namespace Artemis.Core; +namespace Artemis.WebClient.Workshop.Exceptions; /// /// An exception thrown when a web client related error occurs diff --git a/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWorkshopException.cs b/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWorkshopException.cs new file mode 100644 index 000000000..968526086 --- /dev/null +++ b/src/Artemis.WebClient.Workshop/Exceptions/ArtemisWorkshopException.cs @@ -0,0 +1,22 @@ +namespace Artemis.WebClient.Workshop.Exceptions; + +/// +/// An exception thrown when a workshop related error occurs +/// +public class ArtemisWorkshopException : Exception +{ + /// + public ArtemisWorkshopException() + { + } + + /// + public ArtemisWorkshopException(string? message) : base(message) + { + } + + /// + public ArtemisWorkshopException(string? message, Exception? innerException) : base(message, innerException) + { + } +} \ No newline at end of file diff --git a/src/Artemis.WebClient.Workshop/Services/AccessToken.cs b/src/Artemis.WebClient.Workshop/Services/AccessToken.cs index f67dd9395..7f4f7ba04 100644 --- a/src/Artemis.WebClient.Workshop/Services/AccessToken.cs +++ b/src/Artemis.WebClient.Workshop/Services/AccessToken.cs @@ -1,4 +1,5 @@ using Artemis.Core; +using Artemis.WebClient.Workshop.Exceptions; using IdentityModel.Client; namespace Artemis.WebClient.Workshop.Services; diff --git a/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs b/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs index 5a75e499c..5f47d2567 100644 --- a/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs +++ b/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs @@ -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; diff --git a/src/Artemis.WebClient.Workshop/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs b/src/Artemis.WebClient.Workshop/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs index 7f09ce387..9b4287625 100644 --- a/src/Artemis.WebClient.Workshop/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs +++ b/src/Artemis.WebClient.Workshop/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs @@ -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");