From 18cd620db8446604e2090f858bd2ef1f79fba925 Mon Sep 17 00:00:00 2001 From: Abrynos <6608231+Abrynos@users.noreply.github.com> Date: Thu, 20 Sep 2018 22:20:52 +0200 Subject: [PATCH] Add Utilities.MarkdownToText() (#903) * Add Utilities.MarkdownToText() * Add GET /Api/WWW/MarkdownToText?text={text} and sort usings alphabetically * Revert sorting usings * Sort functions * Remove Log if the user is at fault * Rename variable and adjust if for errors --- ArchiSteamFarm/ArchiSteamFarm.csproj | 1 + .../IPC/Controllers/Api/WWWController.cs | 9 +++++++++ ArchiSteamFarm/Utilities.cs | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 58f5a2200..4285b78fb 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -40,6 +40,7 @@ + diff --git a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs index b89b0278e..dd392ece9 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs @@ -57,6 +57,15 @@ namespace ArchiSteamFarm.IPC.Controllers.Api { return Ok(new GenericResponse>(result)); } + [HttpGet("MarkdownToText")] + public ActionResult> MarkdownToTextGet([FromQuery] string text) { + if (string.IsNullOrEmpty(text)) { + return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(text)))); + } + + return Ok(new GenericResponse(ArchiSteamFarm.Utilities.MarkdownToText(text))); + } + [HttpPost("Send")] public async Task>> SendPost([FromBody] WWWSendRequest request) { if (request == null) { diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index d4e172241..8b81081d7 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -177,6 +177,21 @@ namespace ArchiSteamFarm { return true; } + internal static string MarkdownToText(string markdownText) { + if (string.IsNullOrEmpty(markdownText)) { + ASF.ArchiLogger.LogNullError(nameof(markdownText)); + return null; + } + + string plainText = Markdig.Markdown.ToPlainText(markdownText); + if (plainText == null) { + ASF.ArchiLogger.LogNullError(nameof(plainText)); + return null; + } + + return plainText; + } + internal static int RandomNext() { lock (Random) { return Random.Next();