mirror of
https://github.com/snltty/linker.git
synced 2025-10-05 09:06:54 +08:00
185
This commit is contained in:
31
src/linker.libs/json/KeyValuePairJsonConverter.cs
Normal file
31
src/linker.libs/json/KeyValuePairJsonConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace linker.libs.json
|
||||
{
|
||||
public class KeyValuePairJsonConverter<TKey, TValue> : JsonConverter<KeyValuePair<TKey, TValue>>
|
||||
{
|
||||
public override KeyValuePair<TKey, TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
using (JsonDocument doc = JsonDocument.ParseValue(ref reader))
|
||||
{
|
||||
var root = doc.RootElement;
|
||||
TKey key = JsonSerializer.Deserialize<TKey>(root.GetProperty("Key").GetRawText());
|
||||
TValue value = JsonSerializer.Deserialize<TValue>(root.GetProperty("Value").GetRawText());
|
||||
return new KeyValuePair<TKey, TValue>(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, KeyValuePair<TKey, TValue> value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Key");
|
||||
JsonSerializer.Serialize(writer, value.Key, options);
|
||||
writer.WritePropertyName("Value");
|
||||
JsonSerializer.Serialize(writer, value.Value, options);
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
@@ -178,6 +178,8 @@ namespace linker.libs.web
|
||||
}.ToJson().ToBytes(), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
|
||||
while (websocket.State == WebSocketState.Open)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = await websocket.ReceiveAsync(buffer, CancellationToken.None);
|
||||
switch (result.MessageType)
|
||||
@@ -199,6 +201,11 @@ namespace linker.libs.web
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.Instance.Error($"{req.Path}->{ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -53,9 +53,9 @@ namespace linker.messenger.relay
|
||||
return relayTestTransfer.Nodes;
|
||||
}
|
||||
|
||||
public KeyValuePair<string, TunnelProtocolType> GetDefault(ApiControllerParamsInfo param)
|
||||
public KeyValuePairInfo GetDefault(ApiControllerParamsInfo param)
|
||||
{
|
||||
return new KeyValuePair<string, TunnelProtocolType>(relayClientStore.DefaultNodeId, relayClientStore.DefaultProtocol);
|
||||
return new KeyValuePairInfo { Key = relayClientStore.DefaultNodeId, Value = relayClientStore.DefaultProtocol };
|
||||
}
|
||||
public async Task SyncDefault(ApiControllerParamsInfo param)
|
||||
{
|
||||
@@ -126,9 +126,14 @@ namespace linker.messenger.relay
|
||||
public sealed class SyncInfo
|
||||
{
|
||||
public string[] Ids { get; set; } = [];
|
||||
public KeyValuePair<string, TunnelProtocolType> Data { get; set; } = new KeyValuePair<string, TunnelProtocolType>();
|
||||
public KeyValuePairInfo Data { get; set; } = new KeyValuePairInfo();
|
||||
}
|
||||
|
||||
public sealed class KeyValuePairInfo
|
||||
{
|
||||
public string Key { get; set; } = string.Empty;
|
||||
public TunnelProtocolType Value { get; set; } = TunnelProtocolType.Tcp;
|
||||
}
|
||||
|
||||
public sealed class RelayConnectInfo
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
v1.8.5
|
||||
2025-06-23 10:05:27
|
||||
2025-06-23 11:57:38
|
||||
1. 一些累计更新
|
||||
2. 备用信标服务器
|
||||
3. 设置默认中继节点
|
||||
|
Reference in New Issue
Block a user