fix: authorize verified offline data sync
Build web service image / build (push) Successful in 1m6s

This commit is contained in:
2026-09-30 13:30:48 +08:00
parent edba7d0d38
commit e8abb15f68
12 changed files with 218 additions and 22 deletions
@@ -29,5 +29,15 @@ public static class AccountBindingMatcher
: new AccountMatch(null, nicknameMatches.Length == 0 ? "none" : "nickname", false);
}
public static bool IsUniquelyMatchedToAccount(
string expectedAccountId,
UiAccountIdentity boundIdentity,
IReadOnlyList<DatabaseAccountIdentity> databaseAccounts)
{
if (string.IsNullOrWhiteSpace(expectedAccountId)) return false;
var match = Match(boundIdentity, databaseAccounts);
return match.IsMatched && string.Equals(match.AccountId, expectedAccountId, StringComparison.OrdinalIgnoreCase);
}
private static string? Normalize(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();
}
@@ -17,6 +17,29 @@ public sealed class RemoteAccountContext
get { lock (_gate) return _snapshot; }
}
public static string? SelectActiveAccountId(
bool uiSessionAvailable,
string? preferredAccountId,
IReadOnlyCollection<RemoteAccountIdentity> identities,
IReadOnlyCollection<string> liveBoundAccountIds)
{
ArgumentNullException.ThrowIfNull(identities);
ArgumentNullException.ThrowIfNull(liveBoundAccountIds);
if (!uiSessionAvailable) return null;
var liveBoundIds = liveBoundAccountIds.ToHashSet(StringComparer.OrdinalIgnoreCase);
var eligible = identities
.Where(identity => identity.Verified && liveBoundIds.Contains(identity.AccountId))
.ToArray();
if (!string.IsNullOrWhiteSpace(preferredAccountId))
{
var preferred = eligible.FirstOrDefault(identity =>
string.Equals(identity.AccountId, preferredAccountId, StringComparison.OrdinalIgnoreCase));
if (preferred is not null) return preferred.AccountId;
}
return eligible.Length == 1 ? eligible[0].AccountId : null;
}
public RemoteAccountContextSnapshot SwitchTo(
string accountId,
IReadOnlyCollection<RemoteAccountIdentity> identities,