Skip to content

Commit

Permalink
Only failover to Steam Store if the Premium API is down
Browse files Browse the repository at this point in the history
  • Loading branch information
mvegter committed Jul 18, 2021
1 parent 0984d53 commit ab1cce8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
27 changes: 4 additions & 23 deletions src/Depressurizer.Core/Helpers/DepressurizerPremium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,12 @@ class DepressurizerPremiumResponse
public int hltbMain { get; set; }
}

#region Properties

private static Logger Logger => Logger.Instance;

#endregion

public static AppType load(DatabaseEntry entry, string steamWebApi, string languageCode)
public static void load(DatabaseEntry entry, string steamWebApi, string languageCode)
{
string url = string.Format("{0}/{1}?key={2}&language={3}", Settings.Instance.PremiumServer, entry.AppId, steamWebApi, languageCode);

try
{
return load(entry, new Uri(url));
}
catch (Exception e)
{
Logger.Error("Could not load Premium API ({0}) due to: {1}", url, e.ToString());
}

return AppType.Unknown;
load(entry, new Uri(string.Format("{0}/{1}?key={2}&language={3}", Settings.Instance.PremiumServer, entry.AppId, steamWebApi, languageCode)));
}

public static AppType load(DatabaseEntry entry, Uri uri)
public static void load(DatabaseEntry entry, Uri uri)
{
HttpClient client = new HttpClient();
using (Stream s = client.GetStreamAsync(uri).Result)
Expand All @@ -70,7 +53,7 @@ public static AppType load(DatabaseEntry entry, Uri uri)
DepressurizerPremiumResponse response = new JsonSerializer().Deserialize<DepressurizerPremiumResponse>(reader);
if (!Enum.TryParse(response.appType, true, out AppType type) || type == AppType.Unknown)
{
return AppType.Unknown;
return;
}

entry.Name = response.name;
Expand Down Expand Up @@ -137,8 +120,6 @@ public static AppType load(DatabaseEntry entry, Uri uri)

entry.LastStoreScrape = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}

return entry.AppType;
}
}
}
18 changes: 11 additions & 7 deletions src/Depressurizer.Core/Models/DatabaseEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,21 @@ public void ScrapeStore(string steamWebApi, StoreLanguage storeLanguage)
/// </param>
public void ScrapeStore(string steamWebApi, string languageCode)
{
AppType result = AppType.Unknown;
if (!string.IsNullOrWhiteSpace(Settings.Instance.PremiumServer))
{
result = DepressurizerPremium.load(this, steamWebApi, languageCode);
try
{
DepressurizerPremium.load(this, steamWebApi, languageCode);
return;
}
catch (Exception e)
{
Logger.Error("Could not load Premium API ({0}) due to: {1}. Failing over to Steam Store", AppId, e);
}
}

if (result == AppType.Unknown)
{
result = ScrapeStoreHelper(languageCode);
SetTypeFromStoreScrape(result);
}
AppType result = ScrapeStoreHelper(languageCode);
SetTypeFromStoreScrape(result);
}

#endregion
Expand Down

0 comments on commit ab1cce8

Please sign in to comment.