diff --git a/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductsController.cs b/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductsController.cs index 51469d5e6..cf32b58a4 100644 --- a/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductsController.cs +++ b/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductsController.cs @@ -1,4 +1,4 @@ - using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -12,6 +12,7 @@ using OptimaJet.DWKit.StarterApplication.Models; using OptimaJet.DWKit.StarterApplication.Services; using OptimaJet.DWKit.StarterApplication.Utility; +using Serilog; namespace OptimaJet.DWKit.StarterApplication.Controllers { @@ -124,12 +125,15 @@ class ManifestResponse [HttpGet("{package}/published")] public async Task GetPublishedAppDetails(string package) { + Log.Information($"GetPublishedAppDetails: {package}"); + // Get the play-listing/manifest.json artifact var manifestArtifact = await ProductService.GetPublishedAppDetails(package); if (manifestArtifact == null) { return NotFound(); } + Log.Information($"GetPublishedAppDetails: Manifest={manifestArtifact.Url}"); // Get the size of the apk var apkArtifact = await ProductService.GetPublishedFile(manifestArtifact.ProductId, "apk"); @@ -138,26 +142,45 @@ public async Task GetPublishedAppDetails(string package) return NotFound(); } var updatedApkArtifact = WebRequestWrapper.GetFileInfo(apkArtifact); + Log.Information($"GetPublishedAppDetails: APK Size={updatedApkArtifact.FileSize}"); // Get the contents of the manifest.json var manifestJson = await WebClient.DownloadStringTaskAsync(manifestArtifact.Url); + Log.Information($"GetPublishedAppDetails: Manifest=\n{manifestJson}"); var manifest = JsonConvert.DeserializeObject(manifestJson); - var url = manifest.url; + Log.Information("GetPublishedAppDetails: Manifest Parsed=\n{@Manifest}", manifest); + + // The bucket in the URL stored in the manifest can change over time. The URL from + // the database query is updated when buckets change. Update the hostname stored + // in the manifest file based on the hostname from the artifact query. + var manifestUri = new Uri(manifestArtifact.Url); + var baseUri = new Uri(manifest.url); + var url = new UriBuilder(baseUri) + { + Host = manifestUri.Host + }.Uri.ToString(); + Log.Information($"GetPublishedAppDetails: url={url}"); var titles = new Dictionary(manifest.languages.Count); var descriptions = new Dictionary(manifest.languages.Count); foreach(string language in manifest.languages) { + Log.Information($"GetPublishedAppDetails: Language={language}"); var title = ""; var titleSearch = $"{language}/title.txt"; + Log.Information($"GetPublishedAppDetails: Language={language}, titleSearch={titleSearch}"); var titlePath = manifest.files.Where(s => s.Contains(titleSearch)).FirstOrDefault(); + Log.Information($"GetPublishedAppDetails: Language={language}, titlePath={titlePath}"); + if (!string.IsNullOrEmpty(titlePath)) { title = await WebClient.DownloadStringTaskAsync(url + titlePath); } + Log.Information($"GetPublishedAppDetails: Language={language}, Title={title}"); 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); } + Log.Information("GetPublishedAppDetails: Language=" + language + ", Description=" + description); descriptions.Add(language, description); }