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

Bump url-parse from 1.4.7 to 1.5.3 in /source/SIL.AppBuilder.Portal.Frontend #942

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
{
builder.AddResource<ProductActions,Guid>("product-actions");
builder.AddResource<ProjectToken>("project-tokens");
builder.AddResource<AppDetails,Guid>("app-details");
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
 using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using JsonApiDotNetCore.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OptimaJet.DWKit.StarterApplication.Models;
using OptimaJet.DWKit.StarterApplication.Services;
using OptimaJet.DWKit.StarterApplication.Utility;
Expand All @@ -18,16 +22,19 @@ public ProductsController(
IJsonApiContext jsonApiContext,
ICurrentUserContext currentUserContext,
WebRequestWrapper webRequestWrapper,
IWebClient webClient,
OrganizationService organizationService,
ProductService productService,
UserService userService)
: base(jsonApiContext, productService, currentUserContext, organizationService, userService)
{
WebRequestWrapper = webRequestWrapper;
WebClient = webClient;
ProductService = productService;
}

public WebRequestWrapper WebRequestWrapper { get; }
public IWebClient WebClient { get; }
public ProductService ProductService { get; }

[HttpGet("{id}/actions")]
Expand Down Expand Up @@ -100,6 +107,74 @@ public async Task<IActionResult> CheckPublishedFile(Guid id, String type)
return Ok();
}

class ManifestResponse
{
public string url;
public string icon;
public string color;
[JsonProperty("default-language")]
public string defaultLanguage;
public List<string> languages;
public List<string> files;
}

[AllowAnonymous]
[HttpGet("{package}/published")]
public async Task<IActionResult> GetPublishedAppDetails(string package)
{
// Get the play-listing/manifest.json artifact
var manifestArtifact = await ProductService.GetPublishedAppDetails(package);
if (manifestArtifact == null)
{
return NotFound();
}

// Get the size of the apk
var apkArtifact = await ProductService.GetPublishedFile(manifestArtifact.ProductId, "apk");
if (apkArtifact == null)
{
return NotFound();
}
var updatedApkArtifact = WebRequestWrapper.GetFileInfo(apkArtifact);

// Get the contents of the manifest.json
var manifestJson = await WebClient.DownloadStringTaskAsync(manifestArtifact.Url);

var manifest = JsonConvert.DeserializeObject<ManifestResponse>(manifestJson);
var url = manifest.url;
var titles = new Dictionary<string,string>(manifest.languages.Count);
var descriptions = new Dictionary<string,string>(manifest.languages.Count);
foreach(string language in manifest.languages)
{
var title = "";
var titleSearch = $"{language}/title.txt";
var titlePath = manifest.files.Where(s => s.Contains(titleSearch)).FirstOrDefault();
if (!string.IsNullOrEmpty(titlePath)) { title = await WebClient.DownloadStringTaskAsync(url + titlePath); }
titles.Add(language, title.Trim());

var description = "";
var descriptionSearch = $"{language}/short_description.txt";
var descriptionPath = manifest.files.Where(s => s.Contains(descriptionSearch)).FirstOrDefault();
if (!string.IsNullOrEmpty(descriptionPath)) { description = await WebClient.DownloadStringTaskAsync(url + descriptionPath); }
descriptions.Add(language, description);
}

var details = new AppDetails
{
Id = manifestArtifact.ProductId,
Link = $"/api/products/{manifestArtifact.ProductId}/files/published/apk",
Size = updatedApkArtifact.FileSize.Value,
DefaultLanguage = manifest.defaultLanguage,
Color = manifest.color,
Icon = url + manifest.icon,
Languages = manifest.languages,
Titles = titles,
Descriptions = descriptions
};

return Ok(details);
}

[HttpGet("{id}/transitions")]
public async Task<IActionResult> GetProductTransitions(Guid id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
var productTransitionEntity = modelBuilder.Entity<ProductTransition>();
var workflowSchemeEntity = modelBuilder.Entity<WorkflowScheme>();
var projectImportEntity = modelBuilder.Entity<ProjectImport>();
var productPublicationEntity = modelBuilder.Entity<ProductPublication>();

userEntity
.HasMany(u => u.OrganizationMemberships)
Expand Down Expand Up @@ -239,6 +240,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.Property(t => t.TransitionType)
.HasDefaultValue(ProductTransitionType.Activity);

productPublicationEntity
.HasIndex(p => p.Package);


productWorkflowSchemeEntity.ToTable("WorkflowProcessScheme");

Expand Down
Loading