mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
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
This commit is contained in:
committed by
Łukasz Domeradzki
parent
b247ba6167
commit
18cd620db8
@@ -40,6 +40,7 @@
|
||||
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="2.0.0" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.7" />
|
||||
<PackageReference Include="Humanizer" Version="2.4.2" />
|
||||
<PackageReference Include="Markdig.Signed" Version="0.15.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0-preview2-35157" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0-preview2-35157" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0-preview2-35157" />
|
||||
|
||||
@@ -57,6 +57,15 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
return Ok(new GenericResponse<HashSet<string>>(result));
|
||||
}
|
||||
|
||||
[HttpGet("MarkdownToText")]
|
||||
public ActionResult<GenericResponse<string>> MarkdownToTextGet([FromQuery] string text) {
|
||||
if (string.IsNullOrEmpty(text)) {
|
||||
return BadRequest(new GenericResponse<string>(false, string.Format(Strings.ErrorIsEmpty, nameof(text))));
|
||||
}
|
||||
|
||||
return Ok(new GenericResponse<string>(ArchiSteamFarm.Utilities.MarkdownToText(text)));
|
||||
}
|
||||
|
||||
[HttpPost("Send")]
|
||||
public async Task<ActionResult<GenericResponse<string>>> SendPost([FromBody] WWWSendRequest request) {
|
||||
if (request == null) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user