-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1477 from qdraw/feature/202403_in_app_update_mess…
…age_by_version add fallback for github && tests
- Loading branch information
Showing
25 changed files
with
9,502 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
starsky/starsky.feature.health/UpdateCheck/Interfaces/ICheckForUpdates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using starsky.feature.health.UpdateCheck.Models; | ||
|
||
namespace starsky.feature.health.UpdateCheck.Interfaces | ||
{ | ||
public interface ICheckForUpdates | ||
{ | ||
Task<KeyValuePair<UpdateStatus, string>> IsUpdateNeeded(string currentVersion = ""); | ||
Task<(UpdateStatus, string?)> IsUpdateNeeded(string currentVersion = ""); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
starsky/starsky.feature.health/UpdateCheck/Interfaces/ISpecificVersionReleaseInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace starsky.feature.health.UpdateCheck.Interfaces; | ||
|
||
public interface ISpecificVersionReleaseInfo | ||
{ | ||
Task<string> SpecificVersionMessage(string? versionToCheckFor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
starsky/starsky.feature.health/UpdateCheck/Services/SpecificVersionReleaseInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using starsky.feature.health.UpdateCheck.Interfaces; | ||
using starsky.foundation.http.Interfaces; | ||
using starsky.foundation.injection; | ||
using starsky.foundation.platform.Interfaces; | ||
using starsky.foundation.platform.Models; | ||
|
||
namespace starsky.feature.health.UpdateCheck.Services; | ||
|
||
[Service(typeof(ISpecificVersionReleaseInfo), InjectionLifetime = InjectionLifetime.Singleton)] | ||
public class SpecificVersionReleaseInfo : ISpecificVersionReleaseInfo | ||
{ | ||
internal const string GetSpecificVersionReleaseInfoCacheName = "GetSpecificVersionReleaseInfo"; | ||
|
||
internal const string SpecificVersionReleaseInfoUrl = "qdraw.nl/special/starsky/releaseinfo"; | ||
|
||
private readonly IHttpClientHelper _httpClientHelper; | ||
private readonly IMemoryCache? _cache; | ||
private readonly IWebLogger _webLogger; | ||
private readonly AppSettings? _appSettings; | ||
|
||
public SpecificVersionReleaseInfo(IHttpClientHelper httpClientHelper, AppSettings? appSettings, | ||
IMemoryCache? cache, IWebLogger webLogger) | ||
{ | ||
_appSettings = appSettings; | ||
_httpClientHelper = httpClientHelper; | ||
_cache = cache; | ||
_webLogger = webLogger; | ||
} | ||
|
||
public async Task<string> SpecificVersionMessage(string? versionToCheckFor) | ||
{ | ||
if ( string.IsNullOrWhiteSpace(versionToCheckFor) ) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
if ( _cache == null || _appSettings?.AddMemoryCache != true ) | ||
{ | ||
var specificVersionReleaseInfoContent = | ||
await QuerySpecificVersionInfo(); | ||
return Parse(specificVersionReleaseInfoContent, versionToCheckFor); | ||
} | ||
|
||
if ( _cache.TryGetValue(GetSpecificVersionReleaseInfoCacheName, | ||
out var cacheResult) && cacheResult != null ) | ||
{ | ||
return Parse(( string )cacheResult, versionToCheckFor); | ||
} | ||
|
||
cacheResult = await QuerySpecificVersionInfo(); | ||
_cache.Set(GetSpecificVersionReleaseInfoCacheName, cacheResult, | ||
new TimeSpan(48, 0, 0)); | ||
|
||
return Parse(( string )cacheResult, versionToCheckFor); | ||
} | ||
|
||
internal string Parse(string json, string? versionToCheckFor) | ||
{ | ||
if ( string.IsNullOrWhiteSpace(json) ) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
versionToCheckFor ??= string.Empty; | ||
Dictionary<string, Dictionary<string, string>>? dict = null; | ||
|
||
try | ||
{ | ||
dict = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(json); | ||
} | ||
catch ( JsonException e ) | ||
{ | ||
_webLogger.LogError("[SpecificVersionReleaseInfo] Json parse error: " + e.Message); | ||
} | ||
|
||
if ( dict?.TryGetValue(versionToCheckFor, out var valueDict) is not true ) | ||
return string.Empty; | ||
|
||
var outputValue = valueDict.TryGetValue("en", out var languageValue) | ||
? ConvertMarkdownLinkToHtml(languageValue) | ||
: string.Empty; | ||
|
||
return outputValue; | ||
} | ||
|
||
internal static string ConvertMarkdownLinkToHtml(string markdown) | ||
{ | ||
// Regular expression to match Markdown links | ||
// [Link text Here](https://link-url-here.org) | ||
const string pattern = @"\[(.*?)\]\((.*?)\)"; | ||
|
||
// Replace Markdown links with HTML anchor tags | ||
return Regex.Replace(markdown, pattern, | ||
"<a target=\"_blank\" ref=\"nofollow\" href=\"$2\">$1</a>", RegexOptions.None, | ||
TimeSpan.FromMilliseconds(100)); | ||
} | ||
|
||
internal async Task<string> QuerySpecificVersionInfo() | ||
{ | ||
// argument check is done in QueryIsUpdateNeeded | ||
var (key, value) = await _httpClientHelper.ReadString( | ||
"https://" + SpecificVersionReleaseInfoUrl); | ||
|
||
if ( key ) return value; | ||
_webLogger.LogInformation($"[SpecificVersionReleaseInfo] {value} [end]"); | ||
return string.Empty; | ||
} | ||
} |
Oops, something went wrong.
b99c333
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://starskyapp.netlify.app as production
🚀 Deployed on https://65f3663e056959327bc9a30e--starskyapp.netlify.app