Skip to content

Commit

Permalink
Develop (#69)
Browse files Browse the repository at this point in the history
* Remove extension manifest from upload result (#68)
  • Loading branch information
manuelmayer-dev authored Oct 6, 2023
1 parent d66ab94 commit db5b32b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using ExtensionStoreAPI.Core.DataTypes.MacroDeck;

namespace ExtensionStoreAPI.Core.DataTypes.Response;

public class ExtensionFileUploadResult
{
public ExtensionManifest? ExtensionManifest { get; set; }
public string? Readme { get; set; }
public string? Description { get; set; }
public string? PackageFileName { get; set; }
public string? IconFileName { get; set; }
public string? FileHash { get; set; }
public string? LicenseName { get; set; }
public string? LicenseUrl { get; set; }
public string Name { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public string Repository { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string PackageFileName { get; set; } = string.Empty;
public string IconFileName { get; set; } = string.Empty;
public string FileHash { get; set; } = string.Empty;
public string LicenseName { get; set; } = string.Empty;
public string LicenseUrl { get; set; } = string.Empty;
public bool Success { get; set; }
public bool NewPlugin { get; set; }
public string? CurrentVersion { get; set; }
public string? NewVersion { get; set; }
public string CurrentVersion { get; set; } = string.Empty;
public string NewVersion { get; set; } = string.Empty;
public int MinApiVersion { get; set; }
}
28 changes: 22 additions & 6 deletions src/ExtensionStoreAPI.Core/Managers/ExtensionFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,33 @@ public async Task<ExtensionFileUploadResult> CreateFileAsync(Stream packageStrea

var result = new ExtensionFileUploadResult
{
Name = extensionManifest.Name!,
Author = extensionManifest.Author!,
Repository = extensionManifest.Repository!,
MinApiVersion = extensionManifest.TargetPluginApiVersion!.Value,
Success = true,
NewPlugin = !extensionExists,
ExtensionManifest = extensionManifest,
PackageFileName = packageFileName,
IconFileName = iconFileName,
FileHash = fileHash,
LicenseName = license.Name,
LicenseUrl = license.Url,
Readme = readme,
Description = description,
NewVersion = extensionManifest.Version,
CurrentVersion = currentFile?.Version
NewVersion = extensionManifest.Version!,
CurrentVersion = currentFile?.Version ?? string.Empty
};

var extensionFileEntity = _mapper.Map<ExtensionFileEntity>(result);
var extensionFileEntity = new ExtensionFileEntity
{
Version = extensionManifest.Version!,
MinApiVersion = extensionManifest.TargetPluginApiVersion!.Value,
PackageFileName = packageFileName,
IconFileName = iconFileName,
FileHash = fileHash,
LicenseName = license.Name,
LicenseUrl = license.Url,
Readme = readme
};

try
{
Expand Down Expand Up @@ -220,7 +232,11 @@ private static async Task<ExtensionManifest> GetExtensionManifest(string path)
}

if (string.IsNullOrWhiteSpace(extensionManifest.PackageId)
|| string.IsNullOrWhiteSpace(extensionManifest.Version))
|| string.IsNullOrWhiteSpace(extensionManifest.Version)
|| string.IsNullOrWhiteSpace(extensionManifest.Author)
|| string.IsNullOrWhiteSpace(extensionManifest.Name)
|| string.IsNullOrWhiteSpace(extensionManifest.Repository)
|| !extensionManifest.TargetPluginApiVersion.HasValue)
{
throw new ErrorCodeException(ErrorCodes.ExtensionManifestInvalid);
}
Expand Down
11 changes: 0 additions & 11 deletions src/ExtensionStoreAPI/AutoMapper/ExtensionFileProfile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AutoMapper;
using ExtensionStoreAPI.Core.DataAccess.Entities;
using ExtensionStoreAPI.Core.DataTypes.ExtensionStore;
using ExtensionStoreAPI.Core.DataTypes.Response;
using JetBrains.Annotations;

namespace ExtensionStoreAPI.AutoMapper;
Expand All @@ -14,15 +13,5 @@ public ExtensionFileProfile()
CreateMap<ExtensionFileEntity, ExtensionFile>()
.ForMember(dest => dest.UploadDateTime, opt => opt.MapFrom(x => x.CreatedTimestamp))
.ReverseMap();

CreateMap<ExtensionFileUploadResult, ExtensionFile>()
.ForMember(dest => dest.Version, opt => opt.MapFrom(x => x.ExtensionManifest!.Version))
.ForMember(dest => dest.MinApiVersion, opt => opt.MapFrom(x => x.ExtensionManifest!.TargetPluginApiVersion))
.ForMember(dest => dest.FileHash, opt => opt.MapFrom(x => x.FileHash));

CreateMap<ExtensionFileUploadResult, ExtensionFileEntity>()
.ForMember(dest => dest.Version, opt => opt.MapFrom(x => x.ExtensionManifest!.Version))
.ForMember(dest => dest.MinApiVersion, opt => opt.MapFrom(x => x.ExtensionManifest!.TargetPluginApiVersion))
.ForMember(dest => dest.FileHash, opt => opt.MapFrom(x => x.FileHash));
}
}

0 comments on commit db5b32b

Please sign in to comment.