mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
chore(bot): revert temp fix (407e0ce) + update watson
This commit is contained in:
parent
aa103f85e7
commit
3c4644f3cc
4 changed files with 21 additions and 57 deletions
|
|
@ -1,4 +1,3 @@
|
|||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using Serilog;
|
||||
|
|
@ -58,7 +57,7 @@ public class HttpListenerService
|
|||
private async Task RuntimeConfigSet(HttpContextBase ctx)
|
||||
{
|
||||
var key = ctx.Request.Url.Parameters["key"];
|
||||
var value = ReadStream(ctx.Request.Data, ctx.Request.ContentLength);
|
||||
var value = ctx.Request.DataAsString;
|
||||
await _runtimeConfig.Set(key, value);
|
||||
await RuntimeConfigGet(ctx);
|
||||
}
|
||||
|
|
@ -77,7 +76,7 @@ public class HttpListenerService
|
|||
var shardIdString = ctx.Request.Url.Parameters["shard_id"];
|
||||
if (!int.TryParse(shardIdString, out var shardId)) return;
|
||||
|
||||
var packet = JsonSerializer.Deserialize<GatewayPacket>(ReadStream(ctx.Request.Data, ctx.Request.ContentLength), _jsonSerializerOptions);
|
||||
var packet = JsonSerializer.Deserialize<GatewayPacket>(ctx.Request.DataAsString, _jsonSerializerOptions);
|
||||
var evt = DeserializeEvent(shardId, packet.EventType!, (JsonElement)packet.Payload!);
|
||||
if (evt != null)
|
||||
{
|
||||
|
|
@ -108,39 +107,4 @@ public class HttpListenerService
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//temporary re-implementation of the ReadStream function found in WatsonWebserver.Lite, but with handling for closed connections
|
||||
//https://github.com/dotnet/WatsonWebserver/issues/171
|
||||
private static string ReadStream(Stream input, long contentLength)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||
if (!input.CanRead) throw new InvalidOperationException("Input stream is not readable");
|
||||
if (contentLength < 1) return "";
|
||||
|
||||
byte[] buffer = new byte[65536];
|
||||
long bytesRemaining = contentLength;
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
int read;
|
||||
|
||||
while (bytesRemaining > 0)
|
||||
{
|
||||
read = input.Read(buffer, 0, buffer.Length);
|
||||
if (read > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
bytesRemaining -= read;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Connection closed before reading end of stream.");
|
||||
}
|
||||
}
|
||||
|
||||
if (ms.Length < 1) return null;
|
||||
var str = Encoding.Default.GetString(ms.ToArray());
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue