Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.1.0 #9

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AeFinder.Cli.Core/Options/CommonOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace AeFinder.Cli.Options;

public class CommonOptions
{
[Option(longName: "appid", Required = true, HelpText = "The appid of the AeFinder App.")]
[Option(longName: "appid", Required = true, HelpText = "The appid of the AeIndexer.")]
public string AppId { get; set; }

[Option(longName: "key", Required = true, HelpText = "The deploy key of the AeFinder App.")]
[Option(longName: "key", Required = true, HelpText = "The deploy key of the AeIndexer.")]
public string Key { get; set; }

[Option(longName: "network", Required = false, Default = AeFinderNetwork.MainNet, HelpText = "The AeFinder network (MainNet or TestNet).")]
Expand Down
9 changes: 6 additions & 3 deletions src/AeFinder.Cli.Core/Options/DeployAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace AeFinder.Cli.Options;

[Verb("deploy", HelpText = "Deploy AeFinder App.")]
[Verb("deploy", HelpText = "Deploy AeIndexer.")]
public class DeployAppOptions : CommonOptions
{
[Option(longName: "code", Required = true, HelpText = "The code file path of your AeFinder App.")]
[Option(longName: "code", Required = true, HelpText = "The code file path of your AeIndexer.")]
public string Code { get; set; }

[Option(longName: "manifest", Required = true, HelpText = "The manifest file path of your AeFinder App.")]
[Option(longName: "manifest", Required = true, HelpText = "The manifest file path of your AeIndexer.")]
public string Manifest { get; set; }

[Option(longName: "attachments", Required = false, HelpText = "The Attachment list path of your AeIndexer.")]
public IEnumerable<string> Attachments { get; set; }
}
2 changes: 1 addition & 1 deletion src/AeFinder.Cli.Core/Options/InitAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AeFinder.Cli.Options;

[Verb("init", HelpText = "Init AeFinder App development project.")]
[Verb("init", HelpText = "Init AeIndexer development project.")]
public class InitAppOptions : CommonOptions
{
[Option(longName: "name", Required = true, HelpText = "The project name.")]
Expand Down
12 changes: 9 additions & 3 deletions src/AeFinder.Cli.Core/Options/UpdateAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace AeFinder.Cli.Options;

[Verb("update", HelpText = "Update AeFinder App.")]
[Verb("update", HelpText = "Update AeIndexer.")]
public class UpdateAppOptions : CommonOptions
{
[Option(longName: "code", Required = false, HelpText = "The code file path of your AeFinder App.")]
[Option(longName: "code", Required = false, HelpText = "The code file path of your AeIndexer.")]
public string Code { get; set; }

[Option(longName: "manifest", Required = false, HelpText = "The manifest file path of your AeFinder App.")]
[Option(longName: "manifest", Required = false, HelpText = "The manifest file path of your AeIndexer.")]
public string Manifest { get; set; }

[Option(longName: "version", Required = true, HelpText = "The version to update.")]
public string Version { get; set; }

[Option(longName: "delete-attachments", Required = false, HelpText = "The attachment keys to delete.")]
public IEnumerable<string> DeleteAttachmentKeys { get; set; }

[Option(longName: "attachments", Required = false, HelpText = "The attachment path list.")]
public IEnumerable<string> Attachments { get; set; }
}
38 changes: 31 additions & 7 deletions src/AeFinder.Cli.Core/Services/AppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AppService(IAuthService authService,

public async Task DeployAsync(DeployAppOptions options)
{
_logger.LogInformation("Deploying app...");
_logger.LogInformation("Deploying AeIndexer...");

var token = await _authService.GetAccessTokenAsync(options.Network, options.AppId, options.Key);
var url = $"{CliConsts.AeFinderEndpoints[options.Network].ApiEndpoint}api/apps/subscriptions";
Expand All @@ -39,6 +39,10 @@ public async Task DeployAsync(DeployAppOptions options)
var formDataContent = new MultipartFormDataContent();
formDataContent.Add(new StringContent(await File.ReadAllTextAsync(options.Manifest)), "Manifest");
formDataContent.Add(new StreamContent(new MemoryStream(await File.ReadAllBytesAsync(options.Code))), "Code", "code.dll");
foreach (var path in options.Attachments)
{
formDataContent.Add(new StreamContent(new MemoryStream(await File.ReadAllBytesAsync(path))), "AttachmentList", Path.GetFileName(path));
}

using var response = await client.PostAsync(
url,
Expand All @@ -49,14 +53,16 @@ public async Task DeployAsync(DeployAppOptions options)
await _remoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);

var responseContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Deploy app successfully. Version: {Version}", responseContent);
_logger.LogInformation("Deploy AeIndexer successfully. Version: {Version}", responseContent);
}

public async Task UpdateAsync(UpdateAppOptions options)
{
var token = await _authService.GetAccessTokenAsync(options.Network, options.AppId, options.Key);

if (!options.Code.IsNullOrWhiteSpace())
if (!options.Code.IsNullOrWhiteSpace() ||
(options.DeleteAttachmentKeys != null && options.DeleteAttachmentKeys.Any()) ||
(options.Attachments != null && options.Attachments.Any()))
{
await UpdateCodeAsync(options, token);
}
Expand All @@ -69,15 +75,33 @@ public async Task UpdateAsync(UpdateAppOptions options)

private async Task UpdateCodeAsync(UpdateAppOptions options, string token)
{
_logger.LogInformation("Updating app code...");
_logger.LogInformation("Updating AeIndexer code...");

var url =
$"{CliConsts.AeFinderEndpoints[options.Network].ApiEndpoint}api/apps/subscriptions/code/{options.Version}";

var client = _cliHttpClientFactory.CreateClient(token);

var formDataContent = new MultipartFormDataContent();
formDataContent.Add(new StreamContent(new MemoryStream(await File.ReadAllBytesAsync(options.Code))), "Code", "code.dll");
if (!options.Code.IsNullOrWhiteSpace())
{
formDataContent.Add(new StreamContent(new MemoryStream(await File.ReadAllBytesAsync(options.Code))), "Code",
"code.dll");
}

if (options.DeleteAttachmentKeys != null && options.DeleteAttachmentKeys.Any())
{
formDataContent.Add(new StringContent(options.DeleteAttachmentKeys.JoinAsString(",")), "AttachmentDeleteFileKeyList");
}

if (options.Attachments != null)
{
foreach (var path in options.Attachments)
{
formDataContent.Add(new StreamContent(new MemoryStream(await File.ReadAllBytesAsync(path))),
"AttachmentList", Path.GetFileName(path));
}
}

using var response = await client.PutAsync(
url,
Expand All @@ -87,12 +111,12 @@ private async Task UpdateCodeAsync(UpdateAppOptions options, string token)

await _remoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);

_logger.LogInformation("Update code successfully.");
_logger.LogInformation("Update AeIndexer successfully.");
}

private async Task UpdateManifestAsync(UpdateAppOptions options, string token)
{
_logger.LogInformation("Updating app manifest...");
_logger.LogInformation("Updating AeIndexer manifest...");

var url =
$"{CliConsts.AeFinderEndpoints[options.Network].ApiEndpoint}api/apps/subscriptions/manifest/{options.Version}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DevelopmentTemplateAppService(IAuthService authService, IJsonSerializer j

public async Task CreateProjectAsync(InitAppOptions options)
{
_logger.LogInformation("Initialize app...");
_logger.LogInformation("Initialize AeIndexer...");

CheckOptions(options);

Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task CreateProjectAsync(InitAppOptions options)
var result = await response.Content.ReadAsStreamAsync();
ZipHelper.UnZip(result, options.Directory);

_logger.LogInformation("The AeFinder App: {App} is initialized successfully. Directory: {Directory}", options.Name, options.Directory);
_logger.LogInformation("The AeIndexer: {App} is initialized successfully. Directory: {Directory}", options.Name, options.Directory);
}

private static void CheckOptions(InitAppOptions options)
Expand Down
Loading