-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b4f02e
commit 3255837
Showing
10 changed files
with
82 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#nullable enable | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Modix.Services.Utilities; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Modix.Services; | ||
|
||
public class PasteService(IHttpClientFactory httpClientFactory, ILogger<PasteService> logger) | ||
{ | ||
private const string PASTE_URL = "https://paste.mod.gg/"; | ||
|
||
public async Task<string?> UploadPaste(string textToUpload) | ||
{ | ||
var content = FormatUtilities.BuildContent(textToUpload); | ||
|
||
var client = httpClientFactory.CreateClient(HttpClientNames.TimeoutFiveSeconds); | ||
|
||
var response = await client.PostAsync($"{PASTE_URL}documents", content); | ||
|
||
if (!response.IsSuccessStatusCode) | ||
{ | ||
var body = await response.Content.ReadAsStringAsync(); | ||
|
||
logger.LogError("Failed uploading paste to {Url}, failed with response {ResponseCode}, with body: {Body}", | ||
PASTE_URL, | ||
response.StatusCode, | ||
body); | ||
|
||
return null; | ||
} | ||
|
||
var urlResponse = await response.Content.ReadAsStringAsync(); | ||
var pasteKey = JObject.Parse(urlResponse)["key"]?.Value<string>(); | ||
|
||
return $"{PASTE_URL}{pasteKey}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters