Skip to content

Commit

Permalink
Add Logging to debug issue with /products/package/published endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvire committed Feb 29, 2024
1 parent 7ba297c commit b3d0511
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
 using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand All @@ -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
{
Expand Down Expand Up @@ -124,12 +125,15 @@ class ManifestResponse
[HttpGet("{package}/published")]
public async Task<IActionResult> 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");
Expand All @@ -138,26 +142,45 @@ public async Task<IActionResult> 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<ManifestResponse>(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<string,string>(manifest.languages.Count);
var descriptions = new Dictionary<string,string>(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);
}

Expand Down

0 comments on commit b3d0511

Please sign in to comment.