diff --git a/SimpleVoiceroid2Proxy/Server/Controller.cs b/SimpleVoiceroid2Proxy/Server/Controller.cs index e71268e..93d4fe0 100644 --- a/SimpleVoiceroid2Proxy/Server/Controller.cs +++ b/SimpleVoiceroid2Proxy/Server/Controller.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; +using System.Linq; using System.Text.Json; using System.Threading.Tasks; +using System.Web; namespace SimpleVoiceroid2Proxy.Server; @@ -47,13 +50,26 @@ public async Task HandleAsync(HttpContext context) private async Task HandleGetTalkAsync(HttpContext context) { - await HandleTalkAsync(context, context.Query["text"]); + await HandleTalkAsync(context, context.Query.GetValues("text")?.FirstOrDefault()); } private async Task HandlePostTalkAsync(HttpContext context) { - var payload = await JsonSerializer.DeserializeAsync>(context.Request.InputStream); - await HandleTalkAsync(context, (string?)payload!["text"]); + string? text = null; + if (context.RequestMediaType == "application/x-www-form-urlencoded") + { + using var reader = new StreamReader(context.Request.InputStream); + var body = reader.ReadToEnd(); + var form = HttpUtility.ParseQueryString(body); + text = form.GetValues("text")?.FirstOrDefault(); + } + else + { + var payload = await JsonSerializer.DeserializeAsync>(context.Request.InputStream); + text = payload!["text"].GetString(); + } + + await HandleTalkAsync(context, text); } private async Task HandleTalkAsync(HttpContext context, string? text) diff --git a/SimpleVoiceroid2Proxy/Server/HttpContext.cs b/SimpleVoiceroid2Proxy/Server/HttpContext.cs index 8f3b4ef..26ba0ca 100644 --- a/SimpleVoiceroid2Proxy/Server/HttpContext.cs +++ b/SimpleVoiceroid2Proxy/Server/HttpContext.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Net; +using System.Net.Http.Headers; using System.Text; using System.Text.Json; using System.Threading.Tasks; @@ -14,6 +15,14 @@ public sealed class HttpContext(HttpListenerContext Context) : IDisposable public HttpListenerRequest Request => Context.Request; public HttpListenerResponse Response => Context.Response; public NameValueCollection Query => HttpUtility.ParseQueryString(Request.Url.Query, Encoding.UTF8); + public string? RequestMediaType + { + get + { + MediaTypeHeaderValue.TryParse(Request.ContentType, out var value); + return value.MediaType; + } + } public async Task RespondJson(HttpStatusCode code, Dictionary payload) { diff --git a/SimpleVoiceroid2Proxy/SimpleVoiceroid2Proxy.csproj b/SimpleVoiceroid2Proxy/SimpleVoiceroid2Proxy.csproj index ee9e3e7..2382913 100644 --- a/SimpleVoiceroid2Proxy/SimpleVoiceroid2Proxy.csproj +++ b/SimpleVoiceroid2Proxy/SimpleVoiceroid2Proxy.csproj @@ -10,6 +10,7 @@ true + diff --git a/SimpleVoiceroid2Proxy/packages.lock.json b/SimpleVoiceroid2Proxy/packages.lock.json index 8027fb7..d535302 100644 --- a/SimpleVoiceroid2Proxy/packages.lock.json +++ b/SimpleVoiceroid2Proxy/packages.lock.json @@ -11,15 +11,6 @@ "Codeer.Friendly.Windows": "2.17.0" } }, - "Microsoft.NETFramework.ReferenceAssemblies": { - "type": "Direct", - "requested": "[1.0.3, )", - "resolved": "1.0.3", - "contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==", - "dependencies": { - "Microsoft.NETFramework.ReferenceAssemblies.net481": "1.0.3" - } - }, "RM.Friendly.WPFStandardControls": { "type": "Direct", "requested": "[1.59.1, )", @@ -80,11 +71,6 @@ "System.Threading.Tasks.Extensions": "4.5.4" } }, - "Microsoft.NETFramework.ReferenceAssemblies.net481": { - "type": "Transitive", - "resolved": "1.0.3", - "contentHash": "Vv/20vgHS7VglVOVh8J3Iz/MA+VYKVRp9f7r2qiKBMuzviTOmocG70yq0Q8T5OTmCONkEAIJwETD1zhEfLkAXQ==" - }, "System.Buffers": { "type": "Transitive", "resolved": "4.5.1", @@ -133,6 +119,7 @@ "resolved": "4.5.0", "contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ==" } - } + }, + ".NETFramework,Version=v4.8.1/win7-x86": {} } } \ No newline at end of file