Stop data sync after account authorization revoke

This commit is contained in:
2026-09-22 13:02:55 +08:00
parent 51c9524437
commit e8a8b2f926
6 changed files with 159 additions and 12 deletions
+21 -3
View File
@@ -190,24 +190,42 @@ public sealed class RemoteControlClient : IDisposable
cancellationToken, RemoteDataProtocol.MaxBatchBytes).ConfigureAwait(false);
}
public Task<IReadOnlyList<RemoteSyncBatch>> FlushDataBatchesAsync(
RemoteDataBatchQueue queue,
ReportingConfig reportingConfig,
CancellationToken cancellationToken = default) =>
FlushDataBatchesAsync(queue, reportingConfig, new HashSet<string>(StringComparer.Ordinal), cancellationToken);
public async Task<IReadOnlyList<RemoteSyncBatch>> FlushDataBatchesAsync(
RemoteDataBatchQueue queue,
ReportingConfig reportingConfig,
ISet<string> blockedAccountIds,
CancellationToken cancellationToken = default)
{
EnsureAuthenticated();
var confirmed = new List<RemoteSyncBatch>();
foreach (var batch in queue.Pending())
{
if (blockedAccountIds.Contains(batch.AccountId))
continue;
var filtered = RemoteDataBatchAuthorization.Filter(reportingConfig, batch, out _);
if (filtered is null)
{
queue.Drop(batch.BatchId);
continue;
}
var acknowledgement = await SubmitDataBatchAsync(reportingConfig, filtered, cancellationToken).ConfigureAwait(false);
if (acknowledgement.Accepted && queue.MarkConfirmed(acknowledgement))
confirmed.Add(filtered);
try
{
var acknowledgement = await SubmitDataBatchAsync(reportingConfig, filtered, cancellationToken).ConfigureAwait(false);
if (acknowledgement.Accepted && queue.MarkConfirmed(acknowledgement))
confirmed.Add(filtered);
}
catch (RemoteClientException exception) when (exception.StatusCode == 403 && exception.Code == "AccountNotAuthorized")
{
// Authorization revocation is terminal for locally buffered content: do not retain or retry it.
queue.DropAllForAccount(batch.AccountId);
blockedAccountIds.Add(batch.AccountId);
}
}
return confirmed;
}