|
| 1 | +using Common_glTF_Exporter.Utils; |
| 2 | +using System; |
| 3 | +using System.IO; |
| 4 | +using System.Net.Http; |
| 5 | +using System.Net.Http.Headers; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +public static class ClickUpFormSender |
| 9 | +{ |
| 10 | + public static async Task CreateClickUpTask(string email, string errorDescription, string exError) |
| 11 | + { |
| 12 | + string url = "ClickupEndPoint"; |
| 13 | + string description = $"{email}\n{errorDescription}\n{exError}"; |
| 14 | + |
| 15 | + using (var client = new HttpClient()) |
| 16 | + { |
| 17 | + // Leer el archivo de forma síncrona (compatible con .NET Framework) |
| 18 | + byte[] fileBytes = File.ReadAllBytes(ExportLog.logFilePath); |
| 19 | + |
| 20 | + var content = new ByteArrayContent(fileBytes); |
| 21 | + content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
| 22 | + |
| 23 | + // Crear el JSON dinámicamente, incluyendo la descripción |
| 24 | + string taskJson = $"{{\"name\":\"Bug Report\",\"description\":\"{EscapeJson(description)}\"}}"; |
| 25 | + |
| 26 | + // Agregar headers |
| 27 | + content.Headers.Add("x-file-name", ExportLog.FileLogName); |
| 28 | + content.Headers.Add("x-task-json", taskJson); |
| 29 | + |
| 30 | + try |
| 31 | + { |
| 32 | + Console.WriteLine("Uploading file..."); |
| 33 | + HttpResponseMessage response = await client.PostAsync(url, content); |
| 34 | + |
| 35 | + string responseText = await response.Content.ReadAsStringAsync(); |
| 36 | + Console.WriteLine("Response status: " + response.StatusCode); |
| 37 | + Console.WriteLine("Response body: " + responseText); |
| 38 | + } |
| 39 | + catch (Exception ex) |
| 40 | + { |
| 41 | + Console.WriteLine("Error: " + ex.Message); |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + // Escapa caracteres especiales para que no rompan el JSON |
| 47 | + private static string EscapeJson(string value) |
| 48 | + { |
| 49 | + return value |
| 50 | + .Replace("\\", "\\\\") |
| 51 | + .Replace("\"", "\\\"") |
| 52 | + .Replace("\n", "\\n") |
| 53 | + .Replace("\r", "\\r"); |
| 54 | + } |
| 55 | +} |
0 commit comments