api to use hardcoded jsonpath for now. Libation is fully functional again

This commit is contained in:
Robert McRackan 2020-08-20 14:47:26 -04:00
parent 57302e1b5c
commit 57ee150d3c
4 changed files with 29 additions and 16 deletions

View File

@ -17,7 +17,7 @@ namespace InternalUtilities
{ {
Localization.SetLocale(Configuration.Instance.LocaleCountryCode); Localization.SetLocale(Configuration.Instance.LocaleCountryCode);
return await EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.GetIdentityTokensJsonPath(), loginCallback); return await EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.TEST_GetFirstIdentityTokensJsonPath(), loginCallback);
} }
private static AsyncRetryPolicy policy { get; } private static AsyncRetryPolicy policy { get; }

View File

@ -19,25 +19,33 @@ namespace InternalUtilities
_ = new AccountsPersister(new Accounts(), AccountsSettingsFile); _ = new AccountsPersister(new Accounts(), AccountsSettingsFile);
} }
// convenience for for tests and demos. don't use in production Libation
public static Account TEST_GetFirstAccount()
=> new AccountsPersister(AccountsSettingsFile).Accounts.GetAll().FirstOrDefault();
// convenience for for tests and demos. don't use in production Libation // convenience for for tests and demos. don't use in production Libation
public static string TEST_GetFirstIdentityTokensJsonPath() public static string TEST_GetFirstIdentityTokensJsonPath()
=> TEST_GetFirstAccount().GetIdentityTokensJsonPath(); => TEST_GetFirstAccount().GetIdentityTokensJsonPath();
// convenience for for tests and demos. don't use in production Libation
// TEMP public static Account TEST_GetFirstAccount()
public static string GetIdentityTokensJsonPath() => null; => new AccountsPersister(AccountsSettingsFile).Accounts.GetAll().FirstOrDefault();
public static string GetIdentityTokensJsonPath(this Account account) public static string GetIdentityTokensJsonPath(this Account account)
=> GetIdentityTokensJsonPath(account.AccountId, account?.IdentityTokens?.Locale.Name); => GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name);
public static string GetIdentityTokensJsonPath(string username, string locale) public static string GetIdentityTokensJsonPath(string username, string locale)
{ {
var usernameSanitized = JsonConvert.ToString(username); var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username));
var localeSanitized = JsonConvert.ToString(locale); var localeSanitized = trimSurroundingQuotes(JsonConvert.ToString(locale));
return $"$.AccountsSettings[?(@.Username == '{usernameSanitized}' && @.IdentityTokens.Locale == '{localeSanitized}')].IdentityTokens"; return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeSanitized}')].IdentityTokens";
} }
// SubString algo is better than .Trim("\"")
// orig string "
// json string "\""
// Eg:
// => str.Trim("\"")
// output \
// vs
// => str.Substring(1, str.Length - 2)
// output \"
// also works with surrounding single quotes
private static string trimSurroundingQuotes(string str)
=> str.Substring(1, str.Length - 2);
} }
} }

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.127</Version> <Version>3.1.12.136</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -86,6 +86,13 @@ namespace LibationLauncher
static string AccountsSettingsFileLegacy30 => Path.Combine(Configuration.Instance.LibationFiles, "IdentityTokens.json"); static string AccountsSettingsFileLegacy30 => Path.Combine(Configuration.Instance.LibationFiles, "IdentityTokens.json");
private static void migrate_v3_to_v4() private static void migrate_v3_to_v4()
{
migrateLegacyIdentityFile();
updateSettingsFile();
}
private static void migrateLegacyIdentityFile()
{ {
if (File.Exists(AccountsSettingsFileLegacy30)) if (File.Exists(AccountsSettingsFileLegacy30))
{ {
@ -104,8 +111,6 @@ namespace LibationLauncher
// delete legacy token file // delete legacy token file
File.Delete(AccountsSettingsFileLegacy30); File.Delete(AccountsSettingsFileLegacy30);
} }
updateSettingsFile();
} }
private static void updateLegacyFileWithLocale() private static void updateLegacyFileWithLocale()
@ -178,7 +183,7 @@ namespace LibationLauncher
// don't delete old settings until new values are used // don't delete old settings until new values are used
// remember to remove these from Configuration.cs // remember to remove these from Configuration.cs
throw new NotImplementedException(); return;
// use JObject to remove decrypt key and locale from Settings.json // use JObject to remove decrypt key and locale from Settings.json
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);