🐛 Trying to fix Pass service issues
This commit is contained in:
@@ -170,12 +170,12 @@ public class BroadcastEventHandler(
|
||||
|
||||
await nats.PublishAsync(
|
||||
AccountStatusUpdatedEvent.Type,
|
||||
GrpcTypeHelper.ConvertObjectToByteString(new AccountStatusUpdatedEvent
|
||||
ByteString.CopyFromUtf8(JsonSerializer.Serialize(new AccountStatusUpdatedEvent
|
||||
{
|
||||
AccountId = evt.AccountId,
|
||||
Status = status,
|
||||
UpdatedAt = SystemClock.Instance.GetCurrentInstant()
|
||||
}).ToByteArray()
|
||||
}, GrpcTypeHelper.SerializerOptionsWithIgnore)).ToByteArray()
|
||||
);
|
||||
|
||||
logger.LogInformation("Broadcasted status update for user {AccountId}", evt.AccountId);
|
||||
@@ -209,12 +209,12 @@ public class BroadcastEventHandler(
|
||||
|
||||
await nats.PublishAsync(
|
||||
AccountStatusUpdatedEvent.Type,
|
||||
GrpcTypeHelper.ConvertObjectToByteString(new AccountStatusUpdatedEvent
|
||||
ByteString.CopyFromUtf8(JsonSerializer.Serialize(new AccountStatusUpdatedEvent
|
||||
{
|
||||
AccountId = evt.AccountId,
|
||||
Status = status,
|
||||
UpdatedAt = SystemClock.Instance.GetCurrentInstant()
|
||||
}).ToByteArray()
|
||||
}, GrpcTypeHelper.SerializerOptionsWithIgnore)).ToByteArray()
|
||||
);
|
||||
|
||||
logger.LogInformation("Broadcasted status update for user {AccountId}", evt.AccountId);
|
||||
|
||||
@@ -211,6 +211,7 @@ public class CacheServiceRedis : ICacheService
|
||||
},
|
||||
ReferenceHandler = ReferenceHandler.Preserve,
|
||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||
Converters = { new ByteStringConverter() }
|
||||
};
|
||||
_jsonOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
_jsonOptions.PropertyNameCaseInsensitive = true;
|
||||
|
||||
50
DysonNetwork.Shared/Data/ByteStringConverter.cs
Normal file
50
DysonNetwork.Shared/Data/ByteStringConverter.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace DysonNetwork.Shared.Data;
|
||||
|
||||
public class ByteStringConverter : JsonConverter<ByteString>
|
||||
{
|
||||
public override ByteString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
{
|
||||
return ByteString.Empty;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
return ByteString.FromBase64(reader.GetString());
|
||||
}
|
||||
|
||||
//This is a temporary workaround to fix the issue that the old data in the cache is not in base64 format.
|
||||
if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
var value = string.Empty;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
return ByteString.CopyFromUtf8(value);
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.PropertyName && reader.GetString() == "$values")
|
||||
{
|
||||
if (reader.Read() && reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
value = reader.GetString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonException("Expected a string or an object with a '$values' property.");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, ByteString value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToBase64());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user