IndexController.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Azure.Storage.Blobs.Specialized;
  2. using HTEXScreen.Service;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Mvc;
  5. using PuppeteerSharp;
  6. using PuppeteerSharp.Media;
  7. using System.Configuration;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Text.Json;
  14. using System.Text.RegularExpressions;
  15. using System.Web;
  16. using TEAMModelOS.SDK;
  17. using TEAMModelOS.SDK.DI;
  18. namespace HTEXScreen.Controllers
  19. {
  20. [ApiController]
  21. [Route("api")]
  22. public class IndexController : ControllerBase
  23. {
  24. private readonly AzureStorageFactory _azureStorage;
  25. private readonly HttpClient _httpClient;
  26. private readonly IConfiguration _configuration;
  27. // private readonly HttpContext _httpContext;
  28. public IndexController(HttpClient httpClient, AzureStorageFactory azureStorage, IConfiguration configuration)
  29. {
  30. _httpClient = httpClient;
  31. _azureStorage = azureStorage;
  32. _configuration = configuration;
  33. // _httpContext=httpContext;
  34. }
  35. /// <summary>
  36. /// 上传到blob
  37. /// </summary>
  38. /// <param name="request"></param>
  39. /// <returns></returns>
  40. [HttpPost("http-log")]
  41. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  42. public async Task<IActionResult> HttpLog(JsonElement json)
  43. {
  44. try {
  45. string data = json.ToJsonString();
  46. var gmt8Time = DateTimeOffset.Now.GetGMTTime(8);
  47. var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
  48. if (!await appendBlob.ExistsAsync())
  49. {
  50. await appendBlob.CreateAsync();
  51. }
  52. using (var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{data},\n")))
  53. {
  54. await appendBlob.AppendBlockAsync(stream);
  55. }
  56. return Ok(new { code = 1 });
  57. }
  58. catch (Exception ex) {
  59. return Ok(new { code = 1 });
  60. }
  61. }
  62. }
  63. }